Skip to content

feat(models): add Databricks DBRX (dbrx) text model support #835

Closed

Description

@inureyes

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

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, and experts.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) during sanitize. 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). If SwitchLinear can consume the stacked w1 / v1 / w2 layout directly, feed it the fused tensors; otherwise split the stacked tensors into per-expert slices in sanitize.
  • 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_qkv clipping step to the fused QKV projection, then split into Q/K/V with GQA head counts from attn_config.kv_n_heads.
  • Block layout: implement the norm-attn-norm ordering.
  • New model file under src/models/ (for example src/models/dbrx.rs), following docs/adding-models.md.

Touchpoints & acceptance criteria

  • Config struct + serde parsing for the DBRX config, including attn_config (with kv_n_heads, clip_qkv) and ffn_config / router fields.
  • from_weights constructor wiring attention, MoE experts, and the norm-attn-norm blocks.
  • sanitize handling of the stacked expert tensors (experts.mlp.w1 / .v1 / .w2): split per-expert or map into the fused SwitchLinear layout.
  • clip_qkv applied to the fused QKV projection.
  • Arm added to src/models/detection.rs for the DBRX architecture / model_type.
  • Registration in src/model_metadata.rs via for_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.md updated to list DBRX.
  • Real-checkpoint validation: mlxcel list reports the architecture, and ./target/release/mlxcel generate produces coherent output from mlx-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

  1. added
    type:enhancement
    priority:medium
    status:ready
    area:models
    on Jul 21, 2026
  2. added
    status:in-progress
    status:done
    and removed
    status:ready
    status:in-progress
    on Aug 5, 2026
  3. added a commit that references this issue on Aug 5, 2026
    1094dd7
  4. added
    modelsize:large
    modeltype:text
    arch:moe
    on Aug 5, 2026
  5. self-assigned this
    on Aug 31, 2026
  6. added 2 commits that reference this issue on Oct 27, 2026
    e4f7a79
    b034e49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch:moearea:modelsmodelsize:largemodeltype:textpriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions