Skip to content

Port T3 backbone to MLX with performance improvements and bug fixes - #532

Draft
PeteHaughie wants to merge 3 commits into
resemble-ai:masterfrom
PeteHaughie:feat/mlx-port
Draft

Port T3 backbone to MLX with performance improvements and bug fixes#532
PeteHaughie wants to merge 3 commits into
resemble-ai:masterfrom
PeteHaughie:feat/mlx-port

Conversation

@PeteHaughie

Copy link
Copy Markdown

This pull request introduces the initial proof-of-concept (PoC) for porting the T3 text-to-speech model's backbone to MLX, Apple's Metal-native ML framework. It establishes the technical boundary between PyTorch and MLX, provides scripts for weight conversion and benchmarking, and documents architectural decisions and success criteria. The changes focus on enabling fast, real-time inference on Apple Silicon, while keeping peripheral components in PyTorch for simplicity.

Key changes:

MLX Port Architecture and Documentation

  • Added a comprehensive domain context (CONTEXT.md) and five architectural decision records (ADRs) detailing the MLX port boundary, backbone construction, weight conversion, PoC scope, and success criteria. These documents clarify what is ported, the rationale, and how success is measured. [1] [2] [3] [4] [5] [6]

Weight Conversion and Loading

  • Introduced scripts/convert_weights_mlx.py, a script to convert T3 model weights from HuggingFace safetensors format to MLX-compatible .npz files, with explicit key mapping for all backbone and embedding layers.

MLX Inference and Benchmarking

  • Added scripts/poc_mlx.py for benchmarking the MLX T3 backbone, measuring forward pass and autoregressive generation speed, and verifying correct weight loading.
  • Added scripts/poc_end_to_end.py for an end-to-end PoC that runs PyTorch-based conditioning, MLX-based T3 generation, and PyTorch S3Gen audio decoding, demonstrating the cross-framework pipeline.

Dependency Management

  • Updated pyproject.toml to add MLX as an optional dependency, enabling easy installation for users with Apple Silicon.

References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

- T3MLX model: 30-layer LLaMA decoder with LLaMA-3 RoPE scaling,
  SwiGLU MLP, learned position embeddings, KV cache autoregressive loop
- Weight conversion: safetensors → .npz with key remapping
- Achieves 62 tok/s (2.5× real-time) — 60× faster than PyTorch MPS
- End-to-end pipeline: PyTorch conditioning → MLX generate → S3Gen decode
- Logit correlation >0.98 vs PyTorch reference
- 5 ADRs documenting architecture decisions
Bug fixes identified during pre-PR review:

- Add causal mask (tril) during prefill forward pass to prevent
  future-token leakage into earlier positions via KV cache
- Add position embeddings to autoregressive tokens via offset param
  in embed_speech_with_pos (BOS at pos 0, step i at pos i+1)
- Guard division by zero in _top_p_sample when softmax underflows
- Guard temperature near-zero in _sample_logits (clamp at 1e-6)
- Remove unused top_p parameter from _sample_logits

Housekeeping:
- .gitignore: assets/*.npz and venv* directories
- pyproject.toml: add mlx>=0.31.0 as optional dependency
Copilot AI review requested due to automatic review settings June 21, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@PeteHaughie
PeteHaughie marked this pull request as draft June 21, 2026 15:36
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