Add Granite 4.1 20B support (GraniteSWA adapter) - #283
Open
lipikaworkemail-ctrl wants to merge 3 commits into
Open
Add Granite 4.1 20B support (GraniteSWA adapter)#283lipikaworkemail-ctrl wants to merge 3 commits into
lipikaworkemail-ctrl wants to merge 3 commits into
Conversation
lipikaworkemail-ctrl
requested review from
BenjSz,
anubhavjana,
arielge,
kiszk and
kmehant
as code owners
August 4, 2026 19:06
Author
|
Hi @arielge, could you please review this PR? cc: @saurabh-srivastava4 @goutham-binnadi-gopala @Mohini-Shrivastava |
Signed-off-by: Lipika Sreedharan <lipikaworkemail@gmail.com>
lipikaworkemail-ctrl
force-pushed
the
enable-granite-4-1-20b-hf-adapters
branch
4 times, most recently
from
August 4, 2026 19:49
f5bd456 to
876a6e2
Compare
Signed-off-by: Lipika Sreedharan <lipikaworkemail@gmail.com>
lipikaworkemail-ctrl
force-pushed
the
enable-granite-4-1-20b-hf-adapters
branch
from
August 4, 2026 19:52
876a6e2 to
8ebb3c8
Compare
arielge
requested changes
Aug 5, 2026
arielge
left a comment
Contributor
There was a problem hiding this comment.
Thanks @lipikaworkemail-ctrl, I think that to merge this we would need to wait for a transformers release that includes the new GraniteSWAConfig class, and upgrade the dependencies accordingly
| "granite41_20b": { | ||
| "name": "Granite 4.1 20B", | ||
| "path": "ibm-research/granite-4.1-20b", | ||
| "adapter": "hf_granite_swa.py", |
Contributor
There was a problem hiding this comment.
Suggested change
| "adapter": "hf_granite_swa.py", | |
| "adapter": "hf_granite_swa.py", | |
| "is_gated": True, |
until it is public, let's consider it gated
| return torch.compile(block_forward, dynamic=False) | ||
|
|
||
|
|
||
| def _run_backbone_forward( |
Contributor
There was a problem hiding this comment.
Maybe better to do more reuse of the existing adapter, like in #281
| Granite4VisionConfig, | ||
| GraniteConfig, | ||
| GraniteMoeHybridConfig, | ||
| GraniteSWAConfig, |
Contributor
There was a problem hiding this comment.
The import currently fails, so to merge this change we would need to wait for a transformers release that includes this config
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
Adds support for Granite 4.1 20B (ibm-research/granite-4.1-20b) via a new
hf_granite_swa.pyadapter for theGraniteSWAConfigmodel family.Granite 4.1 introduces a Sliding Window Attention (SWA) architecture where decoder layers alternate between full attention and sliding-window attention (
layer_typeon eachGraniteSWADecoderLayer). Sliding-window layers restrict attention to a local band ofsliding_windowtokens; full-attention layers use the standard causal mask. This requires a dedicated adapter rather than reusinghf_granite.py.Changes
New file
hf_adapters/hf_granite_swa.py— Spyre adapter forGraniteSWAForCausalLM:_make_compiled_block: per-layer compiled forward; builds a band mask for sliding-window layers, passes the normal causal mask for full-attention layers._run_forward: embedding × multiplier → blocks → RMSNorm → LM head withlogits_scaling.prepare_for_spyre: patches RMSNorm, pads LM head, compiles all blocks.Modified files
hf_adapters/auto_spyre_model.pyGraniteSWAConfigandhf_granite_swa.GraniteSWAConfig → hf_granite_swainCONFIG_TO_ADAPTER_MODULE_MAPPING."ibm-research/granite-4.1-20b": torch.bfloat16inMODEL_PATH_TO_TORCH_DTYPE.tests/model_registry.pygranite41_20b(ibm-research/granite-4.1-20b,hf_granite_swa.py, 20b) — verified.ARCHITECTURE.md— verified checkpoint row, adapter table row, coverage counts, model-specific features column for Granite 4.1 SWA.hf_adapters.md— adapter summary row ..github/cache_config/hf_models_and_datasets.yaml— addibm-research/granite-4.1-20b.Verified checkpoint
ibm-research/granite-4.1-20bParis.Tested on Spyre with
max_new_tokens=8.Notes
ibm-research/granite-4.1-20blives under theibm-researchorg (notibm-granite). All other Granite 4.1/4.0/3.x models remain underibm-granite.aten.embeddingCPU fallback warning on Spyre is expected and does not affect correctness.Checklist
prepare_for_spyre/_run_forward/_make_compiled_blockpatternGraniteSWAConfigregistered inCONFIG_TO_ADAPTER_MODULE_MAPPINGMODEL_PATH_TO_TORCH_DTYPEupdated with correct org and dtype for 20BARCHITECTURE.mdandhf_adapters.mdARCHITECTURE.mdibm-research/granite-4.1-20bResults: