Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion finetuning/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def _tokenize_texts(self, text) -> List[torch.Tensor]:

@torch.inference_mode()
def extract_mels(self, audio, sr):
assert sr == 24000, "Only support 24kHz audio"
if sr != 24000:
audio = librosa.resample(audio, orig_sr=sr, target_sr=24000)
sr = 24000
mels = mel_spectrogram(
torch.from_numpy(audio).unsqueeze(0),
n_fft=1024,
Expand Down
6 changes: 2 additions & 4 deletions finetuning/sft_12hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ def train():
unwrapped_model = accelerator.unwrap_model(model)
state_dict = {k: v.detach().to("cpu") for k, v in unwrapped_model.state_dict().items()}

drop_prefix = "speaker_encoder"
keys_to_drop = [k for k in state_dict.keys() if k.startswith(drop_prefix)]
for k in keys_to_drop:
del state_dict[k]
# NOTE: speaker_encoder weights are preserved in checkpoints to allow
# training resume. They can be stripped for inference-only exports.

weight = state_dict['talker.model.codec_embedding.weight']
state_dict['talker.model.codec_embedding.weight'][3000] = target_speaker_embedding[0].detach().to(weight.device).to(weight.dtype)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ def chunked_decode(self, codes, chunk_size=300, left_context_size=25):
context_size = left_context_size if start_index - left_context_size > 0 else start_index
codes_chunk = codes[..., start_index - context_size : end_index]
wav_chunk = self(codes_chunk)
wavs.append(wav_chunk[..., context_size * self.total_upsample :])
sample_count = min((end_index - start_index) * self.total_upsample, wav_chunk.shape[-1])
wavs.append(wav_chunk[..., -sample_count:])
start_index = end_index
return torch.cat(wavs, dim=-1)

Expand Down