This commit is contained in:
timur 2026-09-25 20:32:50 +05:00
parent 5deac2a010
commit 0a7a877139
4 changed files with 20 additions and 4 deletions

View File

@ -86,6 +86,7 @@ class ModelManager:
device=self.settings.device,
compute_type=self.settings.whisper_compute_type,
download_root=str(self.settings.models_dir / "faster-whisper"),
local_files_only=True,
)
self._kind = "whisper"
transcribe_kwargs = {
@ -176,7 +177,10 @@ class ModelManager:
"audio-classification",
model=self.settings.emotion_model,
device=self.settings.device,
model_kwargs={"cache_dir": self.settings.models_dir / "huggingface"},
model_kwargs={
"cache_dir": self.settings.models_dir / "huggingface",
"local_files_only": True,
},
)
self._kind = "emotion"
@ -243,7 +247,9 @@ class ModelManager:
quantization = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16) if self.settings.qwen_load_in_4bit else None
self._tokenizer = AutoTokenizer.from_pretrained(
self.settings.qwen_model, cache_dir=self.settings.models_dir / "huggingface"
self.settings.qwen_model,
cache_dir=self.settings.models_dir / "huggingface",
local_files_only=True,
)
self._model = AutoModelForCausalLM.from_pretrained(
self.settings.qwen_model,
@ -251,6 +257,7 @@ class ModelManager:
device_map={"": self.settings.device},
quantization_config=quantization,
cache_dir=self.settings.models_dir / "huggingface",
local_files_only=True,
)
self._kind = "qwen"
prompt = self._tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)

View File

@ -14,6 +14,7 @@ services:
MODEL_SERVER_QWEN_MODEL: Qwen/Qwen2.5-3B-Instruct
MODEL_SERVER_QWEN_ENABLED: ${QWEN_ENABLED:-true}
HF_HUB_OFFLINE: "1"
TRANSFORMERS_OFFLINE: "1"
volumes:
# Bind mounts keep large model files and uploads outside Docker's
# writable layer. Override either location in .env when desired.

View File

@ -12,6 +12,8 @@ EnvironmentFile=/etc/llmserver/llmserver.env
Environment=PYTHONUNBUFFERED=1
Environment=HOME=/srv/llmserver
Environment=HF_HOME=/srv/llmserver/models/huggingface
Environment=HF_HUB_OFFLINE=1
Environment=TRANSFORMERS_OFFLINE=1
Environment=TORCH_HOME=/srv/llmserver/models/cache/torch
Environment=TRITON_CACHE_DIR=/srv/llmserver/models/cache/triton
Environment=XDG_CACHE_HOME=/srv/llmserver/models/cache

View File

@ -15,9 +15,11 @@ def test_transcription_retries_without_word_timestamps_on_alignment_error(monkey
audio.touch()
calls = []
model_kwargs = {}
class FakeWhisperModel:
def __init__(self, *args, **kwargs):
pass
model_kwargs.update(kwargs)
def transcribe(self, path, **kwargs):
calls.append((path, kwargs.copy()))
@ -48,6 +50,7 @@ def test_transcription_retries_without_word_timestamps_on_alignment_error(monkey
result = models.ModelManager(settings).transcribe(audio, language="ru")
assert model_kwargs["local_files_only"] is True
assert [call[1]["word_timestamps"] for call in calls] == [True, False]
assert result == {
"text": "hello",
@ -152,7 +155,10 @@ def test_emotion_recognition_uses_configured_pipeline(monkeypatch, tmp_path):
"audio-classification",
"test/emotion",
"cpu",
{"cache_dir": tmp_path / "models" / "huggingface"},
{
"cache_dir": tmp_path / "models" / "huggingface",
"local_files_only": True,
},
)
assert calls[1][1] is None
assert calls[1][0]["sampling_rate"] == 2