Repository navigation
Description
Summary
GPT-NeoX is the EleutherAI decoder architecture behind the Pythia model suite and other NeoX-derived checkpoints. It introduces partial RoPE and an optional parallel-residual block layout. mlx-lm supports it; mlxcel does not yet load the gpt_neox architecture. Porting it adds the Pythia family and gives mlxcel a well-documented set of small-to-mid checkpoints. Effort is contained because the distinctive pieces (partial RoPE, parallel residual, LayerNorm) already have precedents in the mlxcel tree.
Upstream reference
Public checkpoint
EleutherAI Pythia family (for example a pythia-* checkpoint). Verify mlx-community checkpoint availability (confirm an existing MLX conversion) before validation.
Architecture notes
GPT-NeoX with these distinctive traits:
- Partial RoPE: only
rotary_pctofhead_dimis rotated; the remaining channels pass through unrotated. - Optional parallel residual: with
use_parallel_residual=True, the attention sub-layer and the MLP sub-layer both read the same pre-norm input and their outputs are summed into the residual (rather than the MLP reading the attention output). nn.LayerNorm(with bias), not RMSNorm.- Separate
input_layernormandpost_attention_layernorm.
Implementation plan
Reuse the following mlxcel hooks:
- Reuse the existing partial-RoPE handling used by gemma4 (
partial_rotary_factor) insrc/models/gemma4.rsand by phi insrc/models/phi.rsto rotate only therotary_pctfraction ofhead_dim. - Reuse the parallel-residual block pattern for the
use_parallel_residual=Truepath fromsrc/models/gpt_oss.rssrc/models/stablelm.rs. Correction (verified against the tree at the merge parent of PR feat(models): add GPT-NeoX (gpt_neox) text model support #928,f7a877e76):src/models/gpt_oss.rshas no parallel-residual path at all, and never had one; its block is the ordinary chained form (h = x + attn(input_layernorm(x)), thenh + mlp(post_attention_layernorm(h))). The in-tree precedent issrc/models/stablelm.rs, which branches onuse_parallel_residualinTransformerBlock::forward. One difference from that precedent matters here: StableLM's parallel branch feeds both sub-layers from a singleinput_layernorm, whereas GPT-NeoX keeps two separate norms and computesx + attention(input_layernorm(x)) + mlp(post_attention_layernorm(x)), which is the form that shipped. - Reuse LayerNorm from the gpt2 work (feat(models): add GPT-2 (gpt2) text model support #833).
Effort: LOW-MEDIUM.
Touchpoints & acceptance criteria
Delivered and closed. Implemented by PR #928, merged as f7a877e76; mlxcel arch now reports the family. Test coverage: 32 unit tests in src/models/gpt_neox_tests.rs. Real-checkpoint validation: 40 greedy tokens from models/pythia-1b reproduce the mlx-lm reference exactly, which exercises the interleaved per-head QKV split, partial RoPE over 64 of 256 head channels, and the parallel-residual block together. A mutation run substituting the naive flat split failed exactly three tests and passed 26, confirming the tests catch that specific bug. The unticked boxes below are the original pre-implementation plan and were not maintained during the work; treat the merged PR and its review thread as the record of what shipped.
Follow the checklist in docs/adding-models.md. Integration is complete only when the model loads and generates from a real checkpoint, not when modules compile in isolation.
- Config struct + serde parse for the
gpt_neoxconfig (includingrotary_pct/use_parallel_residual). -
from_weightsconstructor. -
sanitizeweight remap. - Add the
gpt_neoxarch-string arm tosrc/models/detection.rs. - Register the model in
src/model_metadata.rs(for_each_model_registration!). - Add the TP/distributed inference arch-string if applicable.
-
_tests.rsunit tests beside the implementation, covering both the parallel-residual and the sequential paths. - Update
docs/supported-models.md. - Validate on a real checkpoint via
./target/release/mlxcel generateand confirmmlxcel archreports it.
Correction: the real-checkpoint validation step above originally read mlxcel list, which lists downloaded checkpoints in the local model store. The architecture registry is mlxcel arch, and that is what confirms the binary knows the family.
Effort
LOW-MEDIUM.
Activity
fix(gpt_neox): reject an odd rotary dimension count before it reaches…
fix(gpt_neox): clean up malformed error strings and finish the docs e…
feat(models): add GPT-NeoX (gpt_neox) text model support (#928)
feat(models): add GPT-NeoX (gpt_neox) text model support (lablup#928)