config qwen off

This commit is contained in:
timur 2026-08-29 14:25:18 +05:00
parent 9c2b6f6ea8
commit e435adc4ee
9 changed files with 68 additions and 6 deletions

View File

@ -1,15 +1,15 @@
HF_TOKEN=
API_KEY=
LOG_LEVEL=INFO
# Set to false to disable the chat endpoint and skip downloading Qwen.
QWEN_ENABLED=true
# Host paths mounted into the container. Model downloads survive rebuilds.
MODEL_STORAGE_PATH=/srv/llmserver/models
DATA_STORAGE_PATH=/srv/llmserver/data
# Override only when a different CUDA 13.3 image variant is required.
CUDA_IMAGE=nvidia/cuda:13.3.0-cudnn-runtime-ubuntu24.04
# MODEL_SERVER_QWEN_MODEL=Qwen/Qwen2.5-7B-Instruct
# MODEL_SERVER_WHISPER_MODEL=large-v3-turbo
# MODEL_SERVER_PYANNOTE_MODEL=pyannote/speaker-diarization-community-1
# MODEL_SERVER_EMOTION_MODEL=xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned
# MODEL_SERVER_QWEN_LOAD_IN_4BIT=true
# Unload the active GPU model after this many idle seconds. Set to 0 to disable.
# MODEL_SERVER_IDLE_UNLOAD_SECONDS=600

View File

@ -26,6 +26,10 @@ Set `LOG_LEVEL` in `.env` to `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`.
The default is `INFO`; container logs are available through
`docker compose logs -f api`.
Set `QWEN_ENABLED=false` in the Compose `.env` file (or
`MODEL_SERVER_QWEN_ENABLED=false` for a host installation) to disable the chat
endpoint and skip downloading Qwen during installation.
An API key is optional. Set `API_KEY` to enable it and send `Authorization: Bearer <key>`.
## API

View File

@ -29,6 +29,7 @@ class Settings(BaseSettings):
validation_alias=AliasChoices("MODEL_SERVER_HUGGINGFACE_TOKEN", "HF_TOKEN"),
)
qwen_model: str = "Qwen/Qwen2.5-7B-Instruct"
qwen_enabled: bool = True
qwen_load_in_4bit: bool = True
qwen_max_new_tokens: int = 1024
idle_unload_seconds: float = Field(default=600.0, ge=0)

View File

@ -23,11 +23,16 @@ def download_models(settings: Settings) -> None:
download_model(settings.whisper_model, cache_dir=str(faster_whisper_cache))
for name, model_id in (
models = [
("Pyannote", settings.pyannote_model),
("emotion", settings.emotion_model),
("Qwen", settings.qwen_model),
):
]
if settings.qwen_enabled:
models.append(("Qwen", settings.qwen_model))
else:
logger.info("Skipping disabled Qwen model")
for name, model_id in models:
logger.info("Downloading %s model=%s", name, model_id)
snapshot_download(
repo_id=model_id,

View File

@ -116,7 +116,13 @@ async def recognize_emotion(
@app.post("/v1/chat/completions", dependencies=[Depends(require_auth)])
async def chat(body: ChatRequest, queue: Annotated[JobQueue, Depends(queue_for)]):
async def chat(
body: ChatRequest,
queue: Annotated[JobQueue, Depends(queue_for)],
settings: Annotated[Settings, Depends(get_settings)],
):
if not settings.qwen_enabled:
raise HTTPException(status_code=503, detail="Qwen model is disabled")
job = await queue.submit(
TaskType.QWEN,
{"messages": [m.model_dump() for m in body.messages], "max_tokens": body.max_tokens, "temperature": body.temperature},

View File

@ -12,6 +12,7 @@ services:
MODEL_SERVER_LOG_LEVEL: ${LOG_LEVEL:-INFO}
MODEL_SERVER_WHISPER_MODEL: deepdml/faster-whisper-large-v3-turbo-ct2
MODEL_SERVER_QWEN_MODEL: Qwen/Qwen2.5-3B-Instruct
MODEL_SERVER_QWEN_ENABLED: ${QWEN_ENABLED:-true}
HF_HUB_OFFLINE: "1"
volumes:
# Bind mounts keep large model files and uploads outside Docker's

View File

@ -12,6 +12,8 @@ API_KEY=
# MODEL_SERVER_EMOTION_MODEL=xbgoose/hubert-large-speech-emotion-recognition-russian-dusha-finetuned
# MODEL_SERVER_EMOTION_CHUNK_SECONDS=15
# MODEL_SERVER_QWEN_MODEL=Qwen/Qwen2.5-7B-Instruct
# Set to false to disable the chat endpoint and skip downloading Qwen.
# MODEL_SERVER_QWEN_ENABLED=true
# MODEL_SERVER_QWEN_LOAD_IN_4BIT=true
# MODEL_SERVER_QWEN_MAX_NEW_TOKENS=1024
# Unload the active GPU model after this many idle seconds. Set to 0 to disable.

View File

@ -37,3 +37,12 @@ def test_logging_and_model_storage_defaults(tmp_path):
assert settings.log_level == "INFO"
assert settings.models_dir == Path("/models")
assert settings.idle_unload_seconds == 600
assert settings.qwen_enabled is True
def test_qwen_can_be_disabled_from_environment(monkeypatch, tmp_path):
monkeypatch.setenv("MODEL_SERVER_QWEN_ENABLED", "false")
settings = Settings(_env_file=None, data_dir=tmp_path)
assert settings.qwen_enabled is False

View File

@ -61,3 +61,37 @@ def test_downloads_all_configured_models(monkeypatch, tmp_path):
]
assert hf_cache.is_dir()
assert (tmp_path / "models" / "faster-whisper").is_dir()
def test_skips_qwen_download_when_disabled(monkeypatch, tmp_path):
snapshots = []
faster_whisper = ModuleType("faster_whisper")
faster_whisper.download_model = lambda *args, **kwargs: None
monkeypatch.setitem(sys.modules, "faster_whisper", faster_whisper)
class FakePipeline:
@classmethod
def from_pretrained(cls, *args, **kwargs):
return cls()
pyannote_audio = ModuleType("pyannote.audio")
pyannote_audio.Pipeline = FakePipeline
monkeypatch.setitem(sys.modules, "pyannote.audio", pyannote_audio)
monkeypatch.setattr(
"app.download_models.snapshot_download",
lambda **kwargs: snapshots.append(kwargs["repo_id"]),
)
settings = Settings(
_env_file=None,
models_dir=tmp_path / "models",
pyannote_model="test/pyannote",
emotion_model="test/emotion",
qwen_model="test/qwen",
qwen_enabled=False,
)
download_models(settings)
assert snapshots == ["test/pyannote", "test/emotion"]