Skip to content

feat(models): add GPT-BigCode (gpt_bigcode) text model support #834

Closed

Description

@inureyes

Summary

GPT-BigCode is the architecture behind the BigCode StarCoder / SantaCoder code models. It is a GPT-2 derivative whose defining change is Multi-Query Attention, which makes it cheap to run at long context. mlx-lm supports it; mlxcel does not yet load the gpt_bigcode architecture. Porting it adds code-model coverage and is straightforward once the GPT-2 skeleton is in place, since MQA is just GQA with a single KV head, which mlxcel already supports everywhere.

Upstream reference

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

Public checkpoint

bigcode/gpt_bigcode-santacoder or a StarCoderBase checkpoint. Verify mlx-community checkpoint availability (confirm an existing MLX conversion) before validation.

Architecture notes

GPT-BigCode with these distinctive traits:

  • Multi-Query Attention: with multi_query=True, a single KV head is shared across all query heads.
  • Learned absolute position embeddings (added to token embeddings). No RoPE.
  • nn.LayerNorm (with bias), not RMSNorm.
  • Fused c_attn projection producing [dim + 2 * kv_dim] (query block plus a single shared key and value block). stored in the Conv1D layout like GPT-2 Correction (verified against bigcode/gpt_bigcode-santacoder): this is NOT the Conv1D layout. HuggingFace GPTBigCode uses nn.Linear, so c_attn.weight is [2304, 2048] = [out, in] already, and upstream gpt_bigcode.py has no sanitize method at all. Adding a transpose would silently corrupt every projection.

Implementation plan

Reuse the following mlxcel hooks:

  • Reuse the gpt2 skeleton (learned position embeddings + LayerNorm). No Conv1D transpose, per the correction above.
  • MQA maps directly onto mlxcel GQA with n_kv_heads = 1, which is already supported across the attention path; no new attention code should be needed.
  • Split the fused c_attn output into the query block and the single shared KV block, respecting the [dim + 2 * kv_dim] layout.

Dependency note: land this after or alongside the gpt2 port (#833), since it reuses the gpt2 learned position embeddings, LayerNorm wiring, and Conv1D transpose and shared validation helpers. Correction (verified against the merged src/models/gpt_bigcode.rs, PR #926, 4ed5e3b78): the Conv1D transpose is struck from this list because there is none to reuse, per the correction in the architecture notes above, where it was already established that GPT-BigCode is nn.Linear and not the Conv1D layout. What the merged port actually imports from src/models/gpt2.rs is position_ids and exceeds_position_table (the learned position-embedding helpers), layer_norm_from_weights (the biased LayerNorm loader), and dim_eq plus validate_embedding_table (the shared load-time validation helpers). Nothing layout-related crosses between the two modules.

Effort: LOW-MEDIUM.

Touchpoints & acceptance criteria

Delivered and closed. Implemented by PR #926, merged as 4ed5e3b78; mlxcel arch now reports the family. Test coverage: 20 unit tests in src/models/gpt_bigcode_tests.rs. Real-checkpoint validation: 60 greedy tokens from models/gpt_bigcode-santacoder reproduce the mlx-lm reference exactly, exercising the MQA path end to end. GPT-2 was re-verified byte-identical after this PR's shared-helper refactor. 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_bigcode config (including multi_query).
  • from_weights constructor.
  • Fused c_attn [dim + 2 * kv_dim] split at offsets [dim, dim + kv_dim]. No sanitize and no Conv1D transpose: the checkpoint is already [out, in], and a transposed weight is rejected by name instead.
  • Add the gpt_bigcode arch-string arm to src/models/detection.rs.
  • Register the model in src/model_metadata.rs (for_each_model_registration!), plus src/models/mod.rs (enum, ALL_MODEL_TYPES, metadata() table, all_variants!) and src/loaded_model.rs.
  • Add the TP/distributed inference arch-string if applicable (added to keep the dispatch table total; the planner rejects it, since the fused c_attn has no shard rules and a single KV head cannot be split).
  • _tests.rs unit tests beside the implementation (20 tests).
  • 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 28, 2026
    4ed5e3b
  4. self-assigned this
    on Aug 31, 2026
  5. added a commit that references this issue on Oct 27, 2026
    bdc7430
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