Skip to content

Commit

Permalink
Fix long text generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnewman committed Oct 31, 2024
1 parent 77071da commit 78e6c08
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions f5_tts_mlx/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ def __call__(
text = list_str_to_tensor(text)
assert text.shape[0] == batch

if seq_len < text.shape[1]:
seq_len = text.shape[1]
inp = mx.pad(inp, [(0, 0), (0, seq_len - inp.shape[1]), (0, 0)])

# lens and mask
if not exists(lens):
lens = mx.full((batch,), seq_len)
Expand Down
6 changes: 1 addition & 5 deletions f5_tts_mlx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,14 @@ def maybe_masked_mean(t: mx.array, mask: mx.array | None = None) -> mx.array:
return einx.divide("b d, b -> b d", num, mx.maximum(den, 1))


def pad_to_length(t: mx.array, length: int, value=None):
def pad_to_length(t: mx.array, length: int, value=0):
ndim = t.ndim
seq_len = t.shape[-1]
if length > seq_len:
if ndim == 1:
t = mx.pad(t, [(0, length - seq_len)], constant_values=value)
elif ndim == 2:
t = mx.pad(t, [(0, 0), (0, length - seq_len)], constant_values=value)
elif ndim == 3:
t = mx.pad(
t, [(0, 0), (0, length - seq_len), (0, 0)], constant_values=value
)
else:
raise ValueError(f"Unsupported padding dims: {ndim}")
return t[..., :length]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "f5-tts-mlx"
version = "0.1.5"
version = "0.1.6"
authors = [{name = "Lucas Newman", email = "[email protected]"}]
license = {text = "MIT"}
description = "F5-TTS - MLX"
Expand Down

0 comments on commit 78e6c08

Please sign in to comment.