Repository navigation
Description
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
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_attnprojection producing[dim + 2 * kv_dim](query block plus a single shared key and value block).stored in the Conv1D layout like GPT-2Correction (verified againstbigcode/gpt_bigcode-santacoder): this is NOT the Conv1D layout. HuggingFaceGPTBigCodeusesnn.Linear, soc_attn.weightis[2304, 2048]=[out, in]already, and upstreamgpt_bigcode.pyhas nosanitizemethod 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_attnoutput 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_bigcodeconfig (includingmulti_query). -
from_weightsconstructor. - Fused
c_attn[dim + 2 * kv_dim]split at offsets[dim, dim + kv_dim]. Nosanitizeand no Conv1D transpose: the checkpoint is already[out, in], and a transposed weight is rejected by name instead. - Add the
gpt_bigcodearch-string arm tosrc/models/detection.rs. - Register the model in
src/model_metadata.rs(for_each_model_registration!), plussrc/models/mod.rs(enum,ALL_MODEL_TYPES,metadata()table,all_variants!) andsrc/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_attnhas no shard rules and a single KV head cannot be split). -
_tests.rsunit tests beside the implementation (20 tests). - 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(models): check a quantized GPT-BigCode projection's output width
docs: correct gelu_approx and TP-refusal comments for gpt_bigcode
feat(models): add GPT-BigCode (gpt_bigcode) text model support (lablu…
feat(models): add GPT-BigCode (gpt_bigcode) text model support (lablu…