Commit e0553aa
committed
fix: address CodeRabbit review findings — MPS cache cleanup, MLX unload thread-safety
Two follow-ups from the automated review on this PR:
1. backend/backends/base.py: empty_device_cache() only handled "cuda"
and "xpu", never "mps" — so once the previous commit enabled MPS for
the PyTorch Qwen3-TTS/CustomVoice engines, switching model sizes on
Apple Silicon would leak MPS-cached memory (torch.mps.empty_cache()
never got called). Added the missing branch.
2. backend/backends/qwen_custom_voice_backend.py: unload_model() had
its own inline `if torch.cuda.is_available(): torch.cuda.empty_cache()`
instead of using the shared empty_device_cache() helper — meant it
never freed MPS memory either, same bug as #1 but duplicated instead
of shared. Switched to the shared helper (matches pytorch_backend.py's
existing pattern).
3. backend/backends/mlx_backend.py: load_model_async()'s unload-on-
model-size-change call went straight to self.unload_model() instead
of routing through _run_on_mlx_thread like every other MLX call in
this file (the whole point of the earlier commit in this PR). Fixed
for consistency with the thread-pinning fix.
Verified on M4: 0.6B -> generate still works post-changes (regression
check), torch.mps.empty_cache() confirmed callable without error in
this environment.1 parent 7cfa6b8 commit e0553aa
3 files changed
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | | - | |
177 | | - | |
| 176 | + | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | | - | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
0 commit comments