From 03176266771131f80afaf60e0db759c951ccc883 Mon Sep 17 00:00:00 2001 From: James Pine Date: Thu, 16 Apr 2026 02:08:33 -0700 Subject: [PATCH] fix(qwen): unify HF cache dir to avoid split cache on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applies the cache_dir portion of #218. On Windows local setups, model assets can split between .hf-cache/hub and .hf-cache/transformers when Qwen3TTSModel.from_pretrained doesn't explicitly pin the cache root — speech_tokenizer and preprocessor_config.json then fail to resolve during load, causing 500s at generation time. Routes both HF Hub and Transformers through hf_constants.HF_HUB_CACHE. Skipped the torch_dtype= → dtype= rename from #218: transformers 4.36 (our minimum) doesn't accept the dtype alias, only 4.46+. Once we bump the minimum we can make that change. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/backends/pytorch_backend.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/backends/pytorch_backend.py b/backend/backends/pytorch_backend.py index c505d98d..b43a943e 100644 --- a/backend/backends/pytorch_backend.py +++ b/backend/backends/pytorch_backend.py @@ -99,16 +99,25 @@ class PyTorchTTSBackend: model_path = self._get_model_path(model_size) logger.info("Loading TTS model %s on %s...", model_size, self.device) + # Route both HF Hub and Transformers through a single cache root. + # On Windows local setups, model assets can otherwise split between + # .hf-cache/hub and .hf-cache/transformers, causing speech_tokenizer + # and preprocessor_config.json to fail to resolve during load. + from huggingface_hub import constants as hf_constants + tts_cache_dir = hf_constants.HF_HUB_CACHE + with force_offline_if_cached(is_cached, model_name): if self.device == "cpu": self.model = Qwen3TTSModel.from_pretrained( model_path, + cache_dir=tts_cache_dir, torch_dtype=torch.float32, low_cpu_mem_usage=False, ) else: self.model = Qwen3TTSModel.from_pretrained( model_path, + cache_dir=tts_cache_dir, device_map=self.device, torch_dtype=torch.bfloat16, )