multimodalart HF Staff commited on
Commit
e6a77d8
·
verified ·
1 Parent(s): 7ccaec4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -73,6 +73,26 @@ def _distributed_addr(self):
73
 
74
  EngineConfig.distributed_addr = property(_distributed_addr)
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  LANGUAGES = {
77
  "English (US)": "en_us",
78
  "English (UK)": "en_gb",
@@ -146,6 +166,10 @@ def _embed_speaker(models, speaker_audio):
146
  wav = wav.astype(np.float32)
147
  if wav.ndim == 2:
148
  wav = wav.T # (samples, channels) -> (channels, samples)
 
 
 
 
149
  wav_t = torch.from_numpy(wav)
150
 
151
  embedder = models["embedder"]
 
73
 
74
  EngineConfig.distributed_addr = property(_distributed_addr)
75
 
76
+ import zonos2.engine.engine as zonos2_engine
77
+ from zonos2.models.weight import _normalize_zonos2_state_dict
78
+
79
+ # Deserialize the 15.3 GB checkpoint once in the main process (mmap keeps it
80
+ # page-cache backed); forked GPU workers inherit it copy-on-write, so cold
81
+ # engine init skips the ~17s torch.load and only pays the host->device copy.
82
+ _STATE_DICT = torch.load(
83
+ f"{MODEL_PATH}/model.pth", map_location="cpu", weights_only=False, mmap=True
84
+ )
85
+ if "model" in _STATE_DICT:
86
+ _STATE_DICT = _STATE_DICT["model"]
87
+ _STATE_DICT = _normalize_zonos2_state_dict(_STATE_DICT)
88
+
89
+
90
+ def _preloaded_checkpoint_weight(model_path, device):
91
+ return {k: v.to(device) for k, v in _STATE_DICT.items()}
92
+
93
+
94
+ zonos2_engine.load_checkpoint_weight = _preloaded_checkpoint_weight
95
+
96
  LANGUAGES = {
97
  "English (US)": "en_us",
98
  "English (UK)": "en_gb",
 
166
  wav = wav.astype(np.float32)
167
  if wav.ndim == 2:
168
  wav = wav.T # (samples, channels) -> (channels, samples)
169
+ else:
170
+ # The embedder's reflect-pad requires a 2D (channels, samples) input;
171
+ # mono uploads arrive 1D.
172
+ wav = wav[None, :]
173
  wav_t = torch.from_numpy(wav)
174
 
175
  embedder = models["embedder"]