Skip to content

feat(models): add IBM Granite dense (granite) - #254

Merged
inureyes merged 2 commits into
mainfrom
feat/issue-245-granite
Jun 13, 2026
Merged

inureyes merged 2 commits into
mainfrom
feat/issue-245-granite

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Port the dense IBM Granite decoder (granite) from mlx-lm. Granite is a Llama-style transformer distinguished by four scalar multipliers, applied verbatim from the reference: embedding_multiplier scales the token embeddings, attention_multiplier is used as the SDPA scale (replacing 1/sqrt(head_dim)), residual_multiplier scales every residual branch, and logits_scaling divides the final logits.

Changes

  • src/models/granite.rs: dense Granite implementation (config, attention with the attention_multiplier scale, SwiGLU MLP, residual-scaled decoder block, tied/untied head with logits_scaling). Reuses the shared UnifiedLinear / RMSNorm / fast_rope helpers; bias tensors are auto-loaded by UnifiedLinear, so attention_bias / mlp_bias need no special handling.
  • Registered granite end to end: detection.rs, the ModelType enum + ALL_MODEL_TYPES + metadata (new Granite family group), the model_metadata.rs config-backed load policy, the loaded_model.rs enum + trait delegation, the tensor-parallel arch fallback map, and the main.rs FAMILY_ORDER.
  • src/models/granite_tests.rs: config-parse and derived-default unit tests (head_dim, quantization, tied embeddings).
  • docs/supported-models.md: Granite dense listed.

Validation

  • cargo clippy --release --features metal,accelerate --lib --bins --tests -- -D warnings: clean.
  • 5 Granite unit tests pass.
  • Real checkpoint mlx-community/granite-3.3-2b-instruct-4bit on Apple Silicon (Metal): mlxcel arch lists Granite (dense); mlxcel generate produces coherent output ("The capital of France is Paris." then EOS; a clean three-tip enumeration sustained over 80 tokens at ~160 tok/s).

Scope

Part of #245. This PR lands the dense granite variant. The granitemoehybrid (Granite 4.x, a Mamba2 + attention hybrid) follows together with #247 (Falcon-H1) and #251 (PLaMo 2) on shared hybrid-cache infrastructure, and that follow-up will close #245. Pure granitemoe is deferred: no public MLX checkpoint exists to validate it against.

Port the dense Granite decoder from mlx-lm. Granite is a Llama-style transformer with four scalar multipliers applied verbatim from the reference: embedding_multiplier on the token embeddings, attention_multiplier as the SDPA scale (replacing 1/sqrt(head_dim)), residual_multiplier on every residual branch, and logits_scaling dividing the final logits.

Register the granite model_type end to end: detection, the ModelType enum and ALL_MODEL_TYPES, metadata under a new Granite family group, the config-backed load policy, the LoadedModel enum and trait delegation, the tensor-parallel arch fallback map, and the arch FAMILY_ORDER.

Add granite_tests.rs covering config parsing and the derived head_dim, quantization, and tied-embedding defaults.

Validated against mlx-community/granite-3.3-2b-instruct-4bit: mlxcel arch lists it and mlxcel generate produces coherent output.

Part of #245. GraniteMoE and the Granite 4.x granitemoehybrid variant follow on shared MoE and Mamba2 hybrid infrastructure.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:high High priority area:models Model architectures, weights, loading, metadata status:review Under review labels Jun 13, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Jun 13, 2026
@inureyes
inureyes merged commit 42b4349 into main Jun 13, 2026
4 checks passed
@inureyes
inureyes deleted the feat/issue-245-granite branch June 13, 2026 04:42
inureyes added a commit that referenced this pull request Jun 13, 2026
Implement IBM Granite 4.x (`granitemoehybrid`), an interleaved Mamba2 (SSM) + GQA attention hybrid with the four Granite scalar multipliers (embedding, attention, residual, logits). Each layer is either a Mamba2 mixer or an attention mixer, selected by `layer_types`. Both the dense-MLP mode and the MoE mode (`block_sparse_moe` + `shared_mlp`) live in one file, selected by `num_local_experts`, completing the hybrid scope of the Granite port (the dense `granite` variant landed in #254).

The Mamba2 mixer reuses the Falcon-H1 SSD scan and the fused-kernel decode path. Two Granite differences: the post-scan gate is always the gated RMSNorm (gate before a plain full-weight rms_norm, no n_groups grouping), and attention defaults to NoPE (position_embedding_type == "nope") with attention_multiplier as the SDPA scale. The model owns a per-layer Mamba or Attention enum cache and reports supports_batching == false, like Falcon-H1 / PLaMo 2.

Registered as a Nonstandard + Special model across detection, model metadata, the loaded-model enum, both loaders, and the distributed name map. Adds checkpoint-free config-geometry tests and documents the family in docs/supported-models.md. The MoE-hybrid path is implemented to mirror the upstream reference but currently has no public MLX checkpoint to validate; the dense-MLP hybrid is validated against mlx-community/granite-4.0-h-350m-4bit.
@inureyes inureyes added this to the 0.3 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
* feat(models): add IBM Granite dense (granite)

Port the dense Granite decoder from mlx-lm. Granite is a Llama-style transformer with four scalar multipliers applied verbatim from the reference: embedding_multiplier on the token embeddings, attention_multiplier as the SDPA scale (replacing 1/sqrt(head_dim)), residual_multiplier on every residual branch, and logits_scaling dividing the final logits.

Register the granite model_type end to end: detection, the ModelType enum and ALL_MODEL_TYPES, metadata under a new Granite family group, the config-backed load policy, the LoadedModel enum and trait delegation, the tensor-parallel arch fallback map, and the arch FAMILY_ORDER.

Add granite_tests.rs covering config parsing and the derived head_dim, quantization, and tied-embedding defaults.

Validated against mlx-community/granite-3.3-2b-instruct-4bit: mlxcel arch lists it and mlxcel generate produces coherent output.

Part of lablup#245. GraniteMoE and the Granite 4.x granitemoehybrid variant follow on shared MoE and Mamba2 hybrid infrastructure.

* style(models): apply rustfmt to granite_tests
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…p#259)

Implement IBM Granite 4.x (`granitemoehybrid`), an interleaved Mamba2 (SSM) + GQA attention hybrid with the four Granite scalar multipliers (embedding, attention, residual, logits). Each layer is either a Mamba2 mixer or an attention mixer, selected by `layer_types`. Both the dense-MLP mode and the MoE mode (`block_sparse_moe` + `shared_mlp`) live in one file, selected by `num_local_experts`, completing the hybrid scope of the Granite port (the dense `granite` variant landed in lablup#254).

The Mamba2 mixer reuses the Falcon-H1 SSD scan and the fused-kernel decode path. Two Granite differences: the post-scan gate is always the gated RMSNorm (gate before a plain full-weight rms_norm, no n_groups grouping), and attention defaults to NoPE (position_embedding_type == "nope") with attention_multiplier as the SDPA scale. The model owns a per-layer Mamba or Attention enum cache and reports supports_batching == false, like Falcon-H1 / PLaMo 2.

Registered as a Nonstandard + Special model across detection, model metadata, the loaded-model enum, both loaders, and the distributed name map. Adds checkpoint-free config-geometry tests and documents the family in docs/supported-models.md. The MoE-hybrid path is implemented to mirror the upstream reference but currently has no public MLX checkpoint to validate; the dense-MLP hybrid is validated against mlx-community/granite-4.0-h-350m-4bit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:models Model architectures, weights, loading, metadata priority:high High priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): add IBM Granite family (granite, granitemoe, granitemoehybrid)

1 participant