Skip to content

pocket_tts: support flow_lm.z_proj when z_dim differs from transformer d_model - #1239

Merged
0xShug0 merged 4 commits into
0xShug0:mainfrom
AfriSpeech:pocket-tts-z-proj
Nov 13, 2026
Merged

0xShug0 merged 4 commits into
0xShug0:mainfrom
AfriSpeech:pocket-tts-z-proj

Conversation

@michsethowusu

Copy link
Copy Markdown
Contributor

Summary

When running compact PocketTTS models where flow_lm.transformer.d_model is smaller than flow_lm.z_dim (e.g. d_model=512 with z_dim=1024 for full-rank flow matching), PyTorch pocket-tts inserts a projection layer flow_lm.z_proj (Linear(d_model, z_dim)).

This PR adds support for:

  1. Parsing flow_lm.z_dim into flow_condition_dim in PocketTTSDescriptor / PocketTTSModelConfig (defaulting to flow_dim if omitted).
  2. Loading flow_lm.z_proj.weight and optional flow_lm.z_proj.bias in load_backend_flow_weights.
  3. Applying z_projection on condition_ before passing to out_eos and flow_net in FlowLM::build().

When flow_lm.z_proj is not present (e.g. in standard 110M models), behavior remains identical.

@0xShug0

0xShug0 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

@michsethowusu One regression: flow_lm.z_dim: null is valid upstream, but the new parser passes it to std::stoi. Same config with flow_lm.z_dim: null, main generates successfully; PR fails with stoi. Please treat null like an omitted value.

@michsethowusu

Copy link
Copy Markdown
Contributor Author

Good catch, thank you! Pushed a fix to treat null and None as omitted values (std::nullopt) in optional_int and optional_float. Confirmed that configs with flow_lm.z_dim: null now parse safely and fall back to d_model without invoking std::stoi.

@0xShug0

0xShug0 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

@michsethowusu Adding optional_nullable_int is a good approach. Please keep optional_int and optional_float unchanged. This update changes their behavior globally, silently treating invalid values such as empty strings as omitted for every model.

Instead, implement nullable handling in optional_nullable_int and use it specifically for flow_lm.z_dim in pockettts. Please also handle Null and NULL, which are valid YAML null spellings but still throw stoi.

@0xShug0

0xShug0 commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@michsethowusu I don't have permission to push changes to your branch. I was planning to create a new PR to preserve your authorship, or would you prefer to make the changes yourself?

@michsethowusu

Copy link
Copy Markdown
Contributor Author

@0xShug0 I have invited you with write/push permissions to our AfriSpeech/audio.cpp fork so you can push directly to this branch. Alternatively, please feel free to create a new PR or make any changes directly as you prefer. Thanks for your work on this!

@michsethowusu

michsethowusu commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

You can accept the invite here: https://github.com/AfriSpeech/audio.cpp/invitations

@0xShug0
0xShug0 merged commit eb8281c into 0xShug0:main Nov 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants