Skip to content

A TTS that fits in your CPU (and pocket)

Python

Read POCKET_TTS_ERROR_WITHOUT_EOS, the variable the tests set (#436)

Tolga Unald28c519caa36
diff --git a/pocket_tts/models/tts_model.py b/pocket_tts/models/tts_model.py
index 7e188b6..c8bf72f 100644
--- a/pocket_tts/models/tts_model.py
+++ b/pocket_tts/models/tts_model.py
@@ -1001,7 +1001,7 @@ class TTSModel(nn.Module):
assert timer.elapsed_time_ms is not None
steps_times.append(timer.elapsed_time_ms)
else:
- if os.environ.get("KPOCKET_TTS_ERROR_WITHOUT_EOS", "0") == "1":
+ if os.environ.get("POCKET_TTS_ERROR_WITHOUT_EOS", "0") == "1":
raise RuntimeError("Generation reached maximum length without EOS!")
logger.warning(
"Maximum generation length reached without EOS, this very often indicates an error."
diff --git a/rust/src/model.rs b/rust/src/model.rs
index 995930b..2e7a313 100644
--- a/rust/src/model.rs
+++ b/rust/src/model.rs
@@ -496,7 +496,7 @@ impl<Q: CpuBackend> TtsModel<Q> {
step_times.push(start.elapsed().as_millis());
}
if reached_max_len {
- if std::env::var("KPOCKET_TTS_ERROR_WITHOUT_EOS").is_ok_and(|v| v == "1") {
+ if std::env::var("POCKET_TTS_ERROR_WITHOUT_EOS").is_ok_and(|v| v == "1") {
bail!("Generation reached maximum length without EOS!")
}
log::warn!(
diff --git a/tests/test_generation_regressions.py b/tests/test_generation_regressions.py
index 6f5972f..1e69ffe 100644
--- a/tests/test_generation_regressions.py
+++ b/tests/test_generation_regressions.py
@@ -95,6 +95,40 @@ def test_generate_reports_autoregressive_errors_before_decoder_done():
assert latents_queue.get(timeout=1) is None
+def test_generation_without_eos_fails_in_the_test_suite(
+ monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
+):
+ # tests/conftest.py sets POCKET_TTS_ERROR_WITHOUT_EOS so that a generation that never emits
+ # EOS fails the test instead of only logging a warning.
+ def run_without_eos(*args: object) -> None:
+ model = cast(
+ TTSModel,
+ SimpleNamespace(
+ _MIN_FRAMES_BEFORE_EOS=0,
+ _run_flow_lm_and_increment_step=lambda model_state, backbone_input_latents: (
+ torch.zeros(1, 1, 4),
+ torch.tensor(False),
+ ),
+ ),
+ )
+ TTSModel._autoregressive_generation(
+ model,
+ model_state={},
+ max_gen_len=3,
+ frames_after_eos=1,
+ latents_queue=queue.Queue(),
+ stop=threading.Event(),
+ first_input=torch.zeros(1, 1, 4),
+ )
+
+ with pytest.raises(RuntimeError, match="maximum length without EOS"):
+ run_without_eos()
+
+ monkeypatch.delenv("POCKET_TTS_ERROR_WITHOUT_EOS")
+ run_without_eos()
+ assert "Maximum generation length reached without EOS" in caplog.text
+
+
@pytest.mark.parametrize(
("source", "expected"),
[