Repository navigation
feat(models): add IBM Granite dense (granite) - #254
Merged
Merged
Conversation
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.
7 tasks
3 of 4 tasks
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_multiplierscales the token embeddings,attention_multiplieris used as the SDPA scale (replacing1/sqrt(head_dim)),residual_multiplierscales every residual branch, andlogits_scalingdivides the final logits.Changes
src/models/granite.rs: dense Granite implementation (config, attention with theattention_multiplierscale, SwiGLU MLP, residual-scaled decoder block, tied/untied head withlogits_scaling). Reuses the sharedUnifiedLinear/RMSNorm/fast_ropehelpers; bias tensors are auto-loaded byUnifiedLinear, soattention_bias/mlp_biasneed no special handling.graniteend to end:detection.rs, theModelTypeenum +ALL_MODEL_TYPES+ metadata (newGranitefamily group), themodel_metadata.rsconfig-backed load policy, theloaded_model.rsenum + trait delegation, the tensor-parallel arch fallback map, and themain.rsFAMILY_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.mlx-community/granite-3.3-2b-instruct-4biton Apple Silicon (Metal):mlxcel archlistsGranite (dense);mlxcel generateproduces 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
granitevariant. Thegranitemoehybrid(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. Puregranitemoeis deferred: no public MLX checkpoint exists to validate it against.