Skip to content

feat(models): add GPT-NeoX (gpt_neox) text model support #836

Closed

Description

@inureyes

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

https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/gpt_neox.py

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_pct of head_dim is 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_layernorm and post_attention_layernorm.

Implementation plan

Reuse the following mlxcel hooks:

  • Reuse the existing partial-RoPE handling used by gemma4 (partial_rotary_factor) in src/models/gemma4.rs and by phi in src/models/phi.rs to rotate only the rotary_pct fraction of head_dim.
  • Reuse the parallel-residual block pattern for the use_parallel_residual=True path from src/models/gpt_oss.rs src/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.rs has no parallel-residual path at all, and never had one; its block is the ordinary chained form (h = x + attn(input_layernorm(x)), then h + mlp(post_attention_layernorm(h))). The in-tree precedent is src/models/stablelm.rs, which branches on use_parallel_residual in TransformerBlock::forward. One difference from that precedent matters here: StableLM's parallel branch feeds both sub-layers from a single input_layernorm, whereas GPT-NeoX keeps two separate norms and computes x + 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_neox config (including rotary_pct / use_parallel_residual).
  • from_weights constructor.
  • sanitize weight remap.
  • Add the gpt_neox arch-string arm to src/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.rs unit 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 generate and confirm mlxcel arch reports 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

  1. added
    type:enhancement
    priority:low
    area:models
    status:ready
    status:in-progress
    status:review
    and removed
    status:ready
    status:in-progress
    on Jul 21, 2026
  2. added
    status:done
    and removed
    status:review
    on Jul 26, 2026
  3. added a commit that references this issue on Jul 26, 2026
    f7a877e
  4. self-assigned this
    on Aug 31, 2026
  5. added a commit that references this issue on Oct 27, 2026
    d14d659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:modelspriority:lowstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions