Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,10 +91,7 @@ torch.cuda.current_device = lambda: 0
|
|
| 91 |
torch.cuda.device_count = lambda: 0
|
| 92 |
torch.cuda.set_device = lambda *a, **kw: None
|
| 93 |
torch.cuda.init = lambda *a, **kw: None
|
| 94 |
-
# memory_stats возвращаем пустым — GPUMemoryManager посчитает фрагментацию = 0.
|
| 95 |
torch.cuda.memory_stats = lambda *a, **kw: {}
|
| 96 |
-
# mem_get_info возвращаем маленькими числами, чтобы defragment_memory не пытался
|
| 97 |
-
# выделить огромный тензор на "device 0" (это CPU) и не упал по OOM.
|
| 98 |
torch.cuda.mem_get_info = lambda *a, **kw: (100, 100)
|
| 99 |
torch.cuda.empty_cache = lambda *a, **kw: None
|
| 100 |
torch.cuda.synchronize = lambda *a, **kw: None
|
|
@@ -104,6 +101,42 @@ torch.cuda.manual_seed_all = lambda *a, **kw: None
|
|
| 104 |
torch.cuda.get_device_properties = lambda *a, **kw: _DummyDeviceProperties()
|
| 105 |
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
# =====================================================================
|
| 108 |
# Обычные импорты (все патчи уже применены).
|
| 109 |
# =====================================================================
|
|
@@ -123,9 +156,7 @@ _orig_load_preset = PlayDiffusion.load_preset
|
|
| 123 |
def _patched_load_preset(self, **kwargs):
|
| 124 |
preset = _orig_load_preset(self, **kwargs)
|
| 125 |
if str(self.device).startswith("cpu"):
|
| 126 |
-
# Речевой токенизатор (XLSR-1B) — в float32
|
| 127 |
preset["speech_tokenizer"]["dtype"] = torch.float32
|
| 128 |
-
# Вокодер BigVGAN — в float32
|
| 129 |
preset["vocoder"]["dtype"] = torch.float32
|
| 130 |
return preset
|
| 131 |
|
|
|
|
| 91 |
torch.cuda.device_count = lambda: 0
|
| 92 |
torch.cuda.set_device = lambda *a, **kw: None
|
| 93 |
torch.cuda.init = lambda *a, **kw: None
|
|
|
|
| 94 |
torch.cuda.memory_stats = lambda *a, **kw: {}
|
|
|
|
|
|
|
| 95 |
torch.cuda.mem_get_info = lambda *a, **kw: (100, 100)
|
| 96 |
torch.cuda.empty_cache = lambda *a, **kw: None
|
| 97 |
torch.cuda.synchronize = lambda *a, **kw: None
|
|
|
|
| 101 |
torch.cuda.get_device_properties = lambda *a, **kw: _DummyDeviceProperties()
|
| 102 |
|
| 103 |
|
| 104 |
+
# =====================================================================
|
| 105 |
+
# ПАТЧ 3.5. Принудительно грузим чекпоинты на CPU.
|
| 106 |
+
# Чекпоинты PlayDiffusion (last_250k_fixed.pkl, xlsr2_1b_v2_custom.pt и др.)
|
| 107 |
+
# сохранены с CUDA-тензорами. Без map_location="cpu" torch.load падает с
|
| 108 |
+
# "Attempting to deserialize object on a CUDA device but ... is False".
|
| 109 |
+
# Патчим torch.load так, чтобы он всегда использовал map_location="cpu".
|
| 110 |
+
# =====================================================================
|
| 111 |
+
_orig_torch_load = torch.load
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _remap_map_location(ml):
|
| 115 |
+
"""Любое CUDA-устройство (или None) превращаем в 'cpu'."""
|
| 116 |
+
if ml is None:
|
| 117 |
+
return "cpu"
|
| 118 |
+
if isinstance(ml, str) and ml.startswith("cuda"):
|
| 119 |
+
return "cpu"
|
| 120 |
+
if isinstance(ml, torch.device) and ml.type == "cuda":
|
| 121 |
+
return "cpu"
|
| 122 |
+
return ml
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _patched_torch_load(*args, **kwargs):
|
| 126 |
+
# torch.load(f, map_location=None, ...) — второй позиционный аргумент
|
| 127 |
+
# это map_location. Обрабатываем оба варианта: позиционный и ключевой.
|
| 128 |
+
if len(args) >= 2:
|
| 129 |
+
args = (args[0], _remap_map_location(args[1])) + args[2:]
|
| 130 |
+
else:
|
| 131 |
+
kwargs["map_location"] = _remap_map_location(
|
| 132 |
+
kwargs.get("map_location")
|
| 133 |
+
)
|
| 134 |
+
return _orig_torch_load(*args, **kwargs)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
torch.load = _patched_torch_load
|
| 138 |
+
|
| 139 |
+
|
| 140 |
# =====================================================================
|
| 141 |
# Обычные импорты (все патчи уже применены).
|
| 142 |
# =====================================================================
|
|
|
|
| 156 |
def _patched_load_preset(self, **kwargs):
|
| 157 |
preset = _orig_load_preset(self, **kwargs)
|
| 158 |
if str(self.device).startswith("cpu"):
|
|
|
|
| 159 |
preset["speech_tokenizer"]["dtype"] = torch.float32
|
|
|
|
| 160 |
preset["vocoder"]["dtype"] = torch.float32
|
| 161 |
return preset
|
| 162 |
|