Repository navigation
Description
Summary
Add support for the Databricks DBRX MoE text model family to the mlxcel Rust inference runtime, porting the architecture from mlx-lm. DBRX is a large fine-grained mixture-of-experts transformer whose experts are stored as a small number of large stacked tensors rather than one tensor per expert, which is the main non-standard piece of this port.
Upstream reference
- mlx-lm implementation: https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/dbrx.py
Public checkpoint
mlx-community/dbrx-instruct-4bit
Note on size: this is a large checkpoint (roughly 70GB even at 4-bit). Real-checkpoint validation will need a machine with enough unified memory to load it. Call this out in any scheduling, since it is much heavier than the typical 4B to 8B smoke-test models.
Architecture notes
- MoE decoder with a
Router(top-k gating over the routed experts). - Experts are stored as large STACKED tensors:
experts.mlp.w1,experts.mlp.v1, andexperts.mlp.w2. These pack all experts into a single tensor per projection and must be split per-expert (or fed directly to a fused-expert path) duringsanitize. This is the defining quirk of the port. - Attention uses
clip_qkv: the fused QKV projection output is clipped to the range [-clip_qkv, +clip_qkv] before splitting into Q/K/V. - GQA via
attn_config.kv_n_heads(grouped-query attention with fewer KV heads than query heads). - "norm-attn-norm" block layout (normalization surrounding the attention block), which differs from the standard pre-norm transformer block ordering and should be mirrored faithfully.
- Standard RoPE position encoding.
Implementation plan
Reuse mlxcel's existing MoE infrastructure rather than writing a new expert path:
- Experts: reuse
src/models/switch_layers.rs(SwitchLinear/ fused experts). IfSwitchLinearcan consume the stackedw1/v1/w2layout directly, feed it the fused tensors; otherwise split the stacked tensors into per-expert slices insanitize. - Routing: a top-k
Router. The grouped top-k routing utilities on the DeepSeek-V2/V3 path (src/models/deepseek_v2.rs,src/models/deepseek_v3.rs) are the closest existing reference for router plumbing, even though DBRX routing is simpler (no expert groups or shared experts). - Attention: add the
clip_qkvclipping step to the fused QKV projection, then split into Q/K/V with GQA head counts fromattn_config.kv_n_heads. - Block layout: implement the norm-attn-norm ordering.
- New model file under
src/models/(for examplesrc/models/dbrx.rs), followingdocs/adding-models.md.
Touchpoints & acceptance criteria
- Config struct + serde parsing for the DBRX config, including
attn_config(withkv_n_heads,clip_qkv) andffn_config/ router fields. -
from_weightsconstructor wiring attention, MoE experts, and the norm-attn-norm blocks. -
sanitizehandling of the stacked expert tensors (experts.mlp.w1/.v1/.w2): split per-expert or map into the fusedSwitchLinearlayout. -
clip_qkvapplied to the fused QKV projection. - Arm added to
src/models/detection.rsfor the DBRX architecture /model_type. - Registration in
src/model_metadata.rsviafor_each_model_registration!. - TP / distributed arch-string entry if DBRX is to be usable under tensor/pipeline parallel.
- Unit tests in the model's
_tests.rs(config parse, sanitize expert split, forward shape). -
docs/supported-models.mdupdated to list DBRX. - Real-checkpoint validation:
mlxcel listreports the architecture, and./target/release/mlxcel generateproduces coherent output frommlx-community/dbrx-instruct-4bit.
Done only when the model loads and generates from the real checkpoint (per docs/adding-models.md).
Effort
MEDIUM-HIGH. The transformer and MoE routing are well within existing infrastructure, but the large model size (harder to validate) and the unusual stacked-expert weight layout add real work.
Activity
feat(models): add Databricks DBRX (dbrx) text model support (#1036)
docs(models): document the modelsize / modeltype / arch label taxonomy (
feat(models): add Databricks DBRX (dbrx) text model support (lablup#1036
docs(models): document the modelsize / modeltype / arch label taxonomy (