Skip to content

Update GraniteSwitch dependencies - #133

Merged
yairallouche merged 17 commits into
mainfrom
feature/dehybridize-moeshared
Sep 30, 2026
Merged

yairallouche merged 17 commits into
mainfrom
feature/dehybridize-moeshared

Conversation

@antonpibm

Copy link
Copy Markdown
Collaborator

No description provided.

Remove the hybrid (mamba/SSM) dependency from GraniteSwitch. The switch
model is attention-only and never constructs a mamba layer, so it does not
need the GraniteMoeHybrid family — GraniteMoeShared provides every class it
actually uses (shared MLP, MoE, RMSNorm, RoPE, PreTrainedModel base) minus
the mamba machinery.

HF backend:
- GraniteSwitchConfig now extends GraniteMoeSharedConfig; modeling and
  core/lora imports repointed to the granitemoeshared twins.
- layer_types / position_embedding_type become switch-owned attributes
  (the shared parent does not declare them, but internal readers still
  depend on them).

shared_intermediate_size fix: the shared parent defaults it to 0, which is
also the "no shared MLP" sentinel for pure sparse-MoE bases. The config now
resolves it itself instead of inheriting a magic default — explicit values
(including 0) are honored verbatim; when unset, dense resolves to
intermediate_size and pure MoE keeps 0. This is a compose-time decision
frozen into config.json; it also closes a latent bug where a bare dense
config silently inherited the old 1024 default. Guarded by new unit tests.

composer: granite_moe_hybrid_arch/_sr_arch renamed to
granite_moe_shared_arch/_sr_arch. The "granitemoehybrid" registry key is
retained (mapped to the shared arch) because real Granite 4.x dense
checkpoints are still typed granitemoehybrid upstream; a "granitemoeshared"
key is added alongside.

vLLM backend:
- Removed the vestigial IsHybrid / HasInnerState marker mixins (no hybrid
  contract was implemented).
- The two borrowed upstream classes (GraniteMoeMoE, GraniteMoeSharedMLP)
  now load via a version-tolerant helper that prefers the non-hybrid
  granitemoe / granitemoeshared modules and falls back to granitemoehybrid,
  so a single codebase works across the pinned vLLM versions.

Local CPU tests pass (unit, config sis-trap, composer arch skinning, HF
granite4 equivalence, HF forward/lora/multi-switch). vLLM and GPU
generation tests to run on the cluster.

Signed-off-by: antonp <[email protected]>
eval/gen_smoke.py loads a composed Granite Switch checkpoint in vLLM and
generates the same question with the base path and with each adapter's
control token, printing the outputs so a reviewer can confirm the
de-hybridized (granitemoeshared) backend both loads and routes adapters.
Used by the Vela validation job (vela_yamls/dehybridize_vllm_gen.yaml).

Signed-off-by: antonp <[email protected]>
Signed-off-by: antonp <[email protected]>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@antonpibm

Copy link
Copy Markdown
Collaborator Author

/gpu-test-multi

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

❌ GPU tests failed — vllm19-multi

No pytest summary — the suite did not start. See the log below.

Commit: 14664b22155b830a13023037368a07b052dbe879
Full run & artifact log

Last 40 log lines
GPU test report — vllm19-multi
-------------------------------------------------------------------------
Commit:    14664b22155b830a13023037368a07b052dbe879
Suite:     tests/unit/ tests/hf/ tests/composer/ tests/vllm/ tests/integration/
Deps:      dev (vllm 0.19.x)
GPU:       NVIDIA A100-SXM4-80GB

The test suite never started — the run failed during setup.
Redacted tail of the run log:

  <nil>                  Normal   Scheduled        Successfully assigned security/<job> to dmf-nnnqh-gpu-worker-3-b6vfz
  2026-09-16T11:19:45Z   Normal   AddedInterface   Add eth0 [10.141.53.28/23] from ovn-kubernetes
  2026-09-16T11:19:45Z   Normal   Pulled           Container image "vllm/vllm-openai:latest" already present on machine
  2026-09-16T11:19:46Z   Normal   Created          Created container pytorch
  2026-09-16T11:19:46Z   Normal   Started          Started container pytorch
  <nil>                  Normal   Scheduled        Successfully assigned security/<job> to dmf-nnnqh-gpu-worker-3-c52pn
  2026-09-16T11:22:53Z   Normal   AddedInterface   Add eth0 [10.128.44.122/23] from ovn-kubernetes
  2026-09-16T11:22:53Z   Normal   Pulled           Container image "vllm/vllm-openai:latest" already present on machine
  2026-09-16T11:22:54Z   Normal   Created          Created container pytorch
  2026-09-16T11:22:54Z   Normal   Started          Started container pytorch
  2026-09-16T11:23:54Z   Normal   Killing          Stopping container pytorch
  <nil>                  Normal   Scheduled        Successfully assigned security/<job> to dmf-nnnqh-gpu-worker-3-59twx
  2026-09-16T12:02:27Z   Normal   AddedInterface   Add eth0 [10.143.28.26/23] from ovn-kubernetes
  2026-09-16T12:02:27Z   Normal   Pulling          Pulling image "vllm/vllm-openai:latest"
  2026-09-16T12:05:33Z   Normal   Pulled           Successfully pulled image "vllm/vllm-openai:latest" in 3m5.490740793s (3m5.490763994s including waiting)
  2026-09-16T12:05:33Z   Normal   Created          Created container pytorch
  2026-09-16T12:05:33Z   Normal   Started          Started container pytorch
  <nil>                  Normal   Scheduled        Successfully assigned security/<job> to dmf-nnnqh-gpu-worker-3-b6vfz
  2026-09-16T12:08:08Z   Normal   AddedInterface   Add eth0 [10.141.53.31/23] from ovn-kubernetes
  2026-09-16T12:08:08Z   Normal   Pulled           Container image "vllm/vllm-openai:latest" already present on machine
  2026-09-16T12:08:09Z   Normal   Created          Created container pytorch
  2026-09-16T12:08:09Z   Normal   Started          Started container pytorch
  [12:09:38] --- end post-mortem ---
  [12:09:38] cleanup: deleting <job> (exit=1)
  <job> "<job>" deleted

Verdict: FAILED before the test suite ran

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

❌ GPU tests failed — vllm20-multi

No pytest summary — the suite did not start. See the log below.

Commit: 14664b22155b830a13023037368a07b052dbe879
Full run & artifact log

Last 40 log lines
GPU test report — vllm20-multi
-------------------------------------------------------------------------
Commit:    14664b22155b830a13023037368a07b052dbe879
Suite:     tests/unit/ tests/hf/ tests/composer/ tests/vllm/ tests/integration/
Deps:      dev-vllm20 (vllm 0.20.x)
GPU:       NVIDIA A100-SXM4-80GB

The test suite never started — the run failed during setup.
Redacted tail of the run log:

  [12:03:06] <job> Failed
  [12:03:08] --- post-mortem: why the job ended (status and events only) ---
  [12:03:08] <job> status:
    QuotaReserved=True Resuming: Suspend is false
    ResourcesDeployed=True Resuming: Suspend is false
    PodsReady=True SufficientPodsReady: 1 pods running; 0 pods succeeded
    Unhealthy=False Resuming: Suspend is false
  [12:03:09] pod <job> phase and conditions:
    phase=Failed
    Initialized=True : 
    Ready=False PodFailed: 
    ContainersReady=False PodFailed: 
    PodScheduled=True : 
  [12:03:10] pod <job> container states:
    pytorch: ready=false restarts=0 state={"terminated":{"containerID":"cri-o://b7417c0c9e5611701a5f6e40ba16953e29bcb4aab7c8d12d0298c7c421b949bb","exitCode":1,"finishedAt":"2026-09-16T12:02:43Z","reason":"Error","startedAt":"2026-09-16T12:02:37Z"}}
  [12:03:10] kubelet events for <job>:
  TIME                   TYPE     REASON           MESSAGE
  <nil>                  Normal   Scheduled        Successfully assigned security/<job> to dmf-nnnqh-gpu-worker-3-8bdkk
  2026-09-16T12:02:34Z   Normal   AddedInterface   Add eth0 [10.131.37.35/23] from ovn-kubernetes
  2026-09-16T12:02:34Z   Normal   Pulled           Container image "vllm/vllm-openai:latest" already present on machine
  2026-09-16T12:02:37Z   Normal   Created          Created container pytorch
  2026-09-16T12:02:37Z   Normal   Started          Started container pytorch
  [12:03:11] --- end post-mortem ---
  [12:03:11] cleanup: deleting <job> (exit=1)
  <job> "<job>" deleted

Verdict: FAILED before the test suite ran

@antonpibm

Copy link
Copy Markdown
Collaborator Author

/gpu-test-multi

@antonpibm

Copy link
Copy Markdown
Collaborator Author

/gpu-test-multi

@antonpibm

Copy link
Copy Markdown
Collaborator Author

/gpu-test-multi

vLLM >=0.26 registers the fused expert bank via FusedMoEFactory at
block_sparse_moe.experts.routed_experts.w13_weight / .w2_weight. The HF->vLLM
stacked-MoE loader targeted experts.w13_weight (missing the routed_experts.
segment), so the packed tensors were never loaded: vLLM reported them
UNINITIALIZED and the fallthrough direct-load tripped
"RoutedExperts.weight_loader() missing 3 positional args". Point the loader's
w13/w2 targets at the routed_experts path and update the MoE weight-load test's
readback to the routed_experts submodule. Verified against the 0.26 and 0.27
lines.

Signed-off-by: itzikvaisman <[email protected]>
test_skinning_equivalence_vllm[granite-4.0-micro] and its _thorough variant
compare the skinned GraniteSwitch model against the original through vLLM and
gated the top-K logprobs at d > 0 -- literal bit-exactness. But the skinned
model runs its projections through the fused SWITCH Triton kernel while the
original uses vLLM's native linear, and the two have different float-reduction
orders even at zero adapter (CLAUDE.md Gotcha #9). Whether that sub-ULP noise
lands on zero is vLLM-version-dependent: both tests pass on 0.19.1 and 0.20 but
fail on 0.26 with max |diff| = 1.907349e-06 (== 2^-19, i.e. 1-2 ULP at these
logprob magnitudes). Every differing value across all 8 thorough requests was
one of 2^-19 / 2^-20 / 2^-21 -- the reduction-order fingerprint, not drift.

Gate at LOGPROB_ATOL = 1e-5 instead: ~5x above the observed noise floor, orders
of magnitude below any real logit/weight regression (which shifts logprobs by
>> 1e-3). This mirrors the philosophy already documented for the authoritative
test_generation_equivalence.py, which gates distribution equivalence rather than
token-exact match for exactly this reason.

max_diff now tracks the true max including tolerated noise so drift toward the
threshold stays visible even on a pass; the FAIL/OK prints and the module
docstring drop the now-inaccurate "bit-exact" wording.

Signed-off-by: antonp <[email protected]>
The zero-adapter / no-control-token vLLM equivalence tests asserted bitwise
identity (atol=0, rtol=0) between an inert GraniteSwitch and the upstream
GraniteMoeHybrid reference on identical transferred weights. That held only
while GraniteSwitch inherited GraniteMoeHybrid. After the de-hybridization
(GraniteMoeShared base), the inert forward runs an equivalent-but-different
reduction-order vLLM path, so the logprobs drift by ~1 bf16 ULP (measured
max_abs_diff 4.77e-7 == 2^-21, mean ~3e-8 across 4.0-mini {1b,350m,micro});
still far below model noise.

get_tolerances() now returns (1e-5, 1e-5) for the inert base-model path
instead of None (~20x the measured worst case, ~1000x tighter than the
adapter path, so a real logit regression still trips it), and the three
affected tests (TestGranite4FamilyEquivalence::test_logits_short/long,
TestZeroAdapterNoHiding::test_no_control_tokens) use it. Test-only change.

Signed-off-by: antonp <[email protected]>
… boundary

Add CLAUDE.md Gotcha #13 explaining that shared_intermediate_size == 0 means
skip the shared MLP (not build a zero-width one), and that the no-MLP-path
rejection lives in the decoders, not the config. Add config-level tests pinning
that boundary: pure-MoE excludes the shared_mlp LoRA targets, and a config with
neither experts nor a shared MLP is permitted at config level.

Signed-off-by: itzikvaisman <[email protected]>
The switch model is attention-only with unconditional RoPE, so both fields were
redundant for every targeted Granite base (4.0-micro/4.1/4.2/5.0 all resolve to
RoPE). layer_types was only ever consumed as a cache of a value transformers
derives itself: DynamicCache(config=...) builds an all-full_attention per-layer
layout from num_hidden_layers when layer_types is absent, so carrying it added a
32-default fallback that was wrong for every 40-layer target. position_embedding_type
had no transformers-side reader and only gated our own RoPE construction.

Remove both from GraniteSwitchConfig, the composer arch descriptors, and the
DynamicCache-length synthesis; collapse the four decoder RoPE gates to always-on;
replace the layer_types attention scan with the attention-only num_adapters>0
invariant. Tests now assert the config carries neither field and that DynamicCache
derives the correct per-layer layout from num_hidden_layers, including across a
from_dict round-trip (the load-from-config path).

Signed-off-by: antonp <[email protected]>
… shim

_upstream_layers.py was added in the de-hybridization reparent (7eb2138) as a
version-tolerant wrapper: each getter tried the non-hybrid module
(granitemoe / granitemoeshared) and fell back to granitemoehybrid on
ImportError. That fallback is dead code across the supported vLLM range --
granitemoe.GraniteMoeMoE and granitemoeshared.GraniteMoeSharedMLP export
directly on 0.19.1, 0.20.2, 0.26.0 and 0.27.1 (verified against the release
tags), and granitemoehybrid merely re-imports from those two modules rather
than owning the classes. So the try branch always wins and the wrapper reduced
to an indirection around a one-line import.

Inline the direct non-hybrid imports at the four call sites (has_experts /
has_shared_mlp in both the LoRA and SR decoders) and delete the module. Behavior
is identical; the switch keeps its non-hybrid sourcing (the point of
de-hybridization) without the extra layer.

Signed-off-by: antonp <[email protected]>
Re-establish the dependency on the transformers GraniteMoeHybrid class
family (config parent, HF modeling classes, and core/lora imports),
undoing the reparent to GraniteMoeShared while keeping the transformers
5.16 bump and its MoE-layer rename (experts()/top-k router API).

config: GraniteSwitchConfig extends GraniteMoeHybridConfig again. Because
the hybrid parent's __post_init__ defaults an unset layer_types to all
"linear_attention" (mamba), the config once more pins layer_types to
["full_attention"] * num_hidden_layers and passes position_embedding_type
through to super().__init__(); otherwise DynamicCache would size the wrong
per-layer cache and validate_layer_type would reject an inflated config.
The explicit shared_intermediate_size resolution is kept (dense ->
intermediate_size, pure-MoE -> 0, explicit honored) since the hybrid
parent's 1024 default is the wrong width for dense bases.

hf: modeling and core/lora repoint to the granitemoehybrid twins;
GraniteSwitchPreTrainedModel inherits GraniteMoeHybridPreTrainedModel. The
5.16 MoE API (router -> (top_k_index, top_k_weights, logits); experts(h,
idx, w)) and the dense MLP's input_linear/output_linear are identical
across the hybrid/shared twins, so the rename work is unaffected.

composer: granite_moe_shared_arch/_sr_arch renamed back to
granite_moe_hybrid_arch/_sr_arch (exports updated); the granitemoeshared
registry key is retained alongside granitemoehybrid.

tests: update layer_types assertions to the hybrid-parent reality
(all-attention, correct length), fix shared/hybrid references in
docstrings, and re-attribute the inert-path ULP tolerance to the fused
SWITCH kernel reduction order (Gotcha #9) rather than the base class.

Signed-off-by: antonp <[email protected]>
@antonpibm antonpibm changed the title Change GraniteSwitch inheritance to MoEShared Update GraniteSwitch dependencies Sep 22, 2026
@ItzikVa
ItzikVa force-pushed the feature/dehybridize-moeshared branch from 27cd856 to 55b5320 Compare September 28, 2026 07:56
…grade

This PR upgrades to transformers 5.16+ / vLLM 0.26+. It also carried the
remains of an experiment that reparented GraniteSwitchConfig from
GraniteMoeHybrid to GraniteMoeShared. That experiment was abandoned -- we
stay on GraniteMoeHybrid -- and the earlier revert reached only 13 of its
16 files. The leftovers were pure review noise, and two of them named
classes that do not exist.

Drop granitemoeshared as a supported model_type. Nothing consumed the two
registry keys except the assertions added alongside them, and no fixture
types a base that way, so removing them is a no-op. resolve_arch now
raises its normal "Unsupported architecture" error for such a base.

Fix two factually wrong comments. GraniteMoeSharedMoE exists in neither
vLLM nor transformers; the HF backend builds GraniteMoeHybridMoE.

Import GraniteMoeMoE and GraniteMoeSharedMLP from granitemoehybrid again.
vLLM's granitemoehybrid re-exports both, so either path resolves on 0.26 --
one path keeps the intent legible.

Restore the position_embedding_type gate around RoPE construction. The
reparent collapsed it because the Shared config has no such field;
GraniteSwitchConfig still does, so the escape hatch is still real.

Everything the dependency upgrade actually needs is untouched: the
experts.gate_up_proj / down_proj / router.weight tensor renames, the
(top_k_index, top_k_weights) router return, the routed_experts FusedMoE
param path, and the ["full_attention"] * num_hidden_layers pin.

Record why IsHybrid and HasInnerState must stay dropped. Declaring them
now makes vLLM size the KV cache for zero attention layers: transformers
5.16 remaps "attention" to "full_attention", ModelConfig.is_hybrid's
granite-4.0-micro escape hatch still compares against the literal
"attention", and get_num_layers_by_block_type counts that literal. This
only worked on vLLM 0.19 + transformers 5.9 because layer_types was
literally ["attention"] then.

Signed-off-by: itzikvaisman <[email protected]>
test_logits_match[4.0-micro] has flapped since 2026-09-24, going red about
one run in seven with a bit-reproducible 130708 elements over tolerance,
worst diff=2.9306e-03 at |expected|=11.279.

Measured on one A100-80GB node at this exact config, 2026-09-29/30:

  * The noise floor is EXACTLY ZERO.  Six engines per config as six separate
    processes, five pairs compared over 702464 elements, for all three
    full-size configs: upstream against ITSELF through two separate engines,
    switch against itself, and switch against upstream are all 0.0000e+00.
    15/15 bit-exact.  So there is no bf16 floor here to hide behind, the
    1e-5 in get_tolerances is not too tight, and the switch's math is right.
    The tolerance is deliberately NOT touched.

  * The red reproduces with this file run ALONE on a cleared compile cache,
    and stays green on 13 of 14 otherwise-identical runs.  No preceding
    test, no suite interaction, no GPU count, no cache warmth and no
    parameter ordering is involved -- each eliminated by its own leg.

  * The failure takes only two discrete, bit-reproducible values
    (2.9306e-03 and 2.9297e-03) out of an unpinned compiler.  That is the
    signature of kernel selection, which autotune makes by timing and then
    caches.  Corroborating: the failing logs show a Triton JIT of
    _topk_log_softmax_kernel, the very reduction producing the logprobs
    being compared.  2.9e-3 absolute at |expected|=11.28 is 2.6e-4
    relative, under one bf16 ulp (0.031) -- a reduction-order difference,
    not a logic error.

This was the only vLLM equivalence test that left torch.compile, CUDA-graph
capture and Triton autotune live.  _granite4_mini_tests.py already pins
enforce_eager for the one config that needed it, and those tests never flap
at the same 1e-5 gate, so pinning is the established idiom in this test
family.  An equivalence test must not measure the compiler as well as the
model.

enable_prefix_caching is set for symmetry, not as a fix: upstream declares
IsHybrid and the switch deliberately does not, so vLLM 0.26 resolved the
flag False for one engine and True for the other.  That asymmetry was
separately measured to be numerically inert, but a comparison should have
exactly one variable in it.

Evidence level: consistent with, not proven by A/B.  A 12-round balanced
A/B is in flight; at a 1-in-7 base rate it cannot reach significance, so
the argument above is mechanistic.  At the time of writing the control arm
has reproduced the red (1/8) and the treated arm has not (0/7).

Signed-off-by: itzikvaisman <[email protected]>
@yairallouche
yairallouche self-requested a review September 30, 2026 11:06
@yairallouche

Copy link
Copy Markdown
Collaborator

Update the vLLM version to 0.30.

1 similar comment
@yairallouche

Copy link
Copy Markdown
Collaborator

Update the vLLM version to 0.30.

@ItzikVa
ItzikVa marked this pull request as ready for review September 30, 2026 13:08
@yairallouche
yairallouche merged commit 1db3e1b into main Sep 30, 2026
8 checks passed
lastras pushed a commit to lastras/granite-switch that referenced this pull request Oct 5, 2026
Rebased onto main (generative-computing#130, generative-computing#133), which moves Granite Switch to transformers
5.16-5.17 and vLLM 0.26. Main makes "full_attention" the canonical layer
type, so the earlier remap back to "attention" (written for vLLM 0.19's
hybrid check) is dropped. The ASR device fix stays on top of main's CTC
pipeline: inside vLLM the pipeline still loads the model on the CPU.

The FA3 schedule patch now reports what it did (fa3_schedule.STATUS)
and warns when vLLM's internals differ instead of silently leaving the
wrong-shape schedule in place; a builder without the fields it sizes gets
no ahead-of-time schedule rather than a wrong one.

train_alora.py --serve-tokenizer stops training unless its prompt ids
are the ones the served checkpoint's tokenizer gives. Under transformers
5.6.2 the base model's tokenizer loaded as GPT2Tokenizer, without the
pre-tokenizer of its tokenizer.json: "your_weapon" and "{}}" split
differently from serving, about 4% more tokens on the narrator's prompts,
so an adapter trained there never saw the ids it is served.

Signed-off-by: Luis A Lastras <[email protected]>
vedem1192 pushed a commit to vedem1192/granite-switch that referenced this pull request Nov 20, 2026
* Reparent GraniteSwitch from GraniteMoeHybrid to GraniteMoeShared

Remove the hybrid (mamba/SSM) dependency from GraniteSwitch. The switch
model is attention-only and never constructs a mamba layer, so it does not
need the GraniteMoeHybrid family — GraniteMoeShared provides every class it
actually uses (shared MLP, MoE, RMSNorm, RoPE, PreTrainedModel base) minus
the mamba machinery.

HF backend:
- GraniteSwitchConfig now extends GraniteMoeSharedConfig; modeling and
  core/lora imports repointed to the granitemoeshared twins.
- layer_types / position_embedding_type become switch-owned attributes
  (the shared parent does not declare them, but internal readers still
  depend on them).

shared_intermediate_size fix: the shared parent defaults it to 0, which is
also the "no shared MLP" sentinel for pure sparse-MoE bases. The config now
resolves it itself instead of inheriting a magic default — explicit values
(including 0) are honored verbatim; when unset, dense resolves to
intermediate_size and pure MoE keeps 0. This is a compose-time decision
frozen into config.json; it also closes a latent bug where a bare dense
config silently inherited the old 1024 default. Guarded by new unit tests.

composer: granite_moe_hybrid_arch/_sr_arch renamed to
granite_moe_shared_arch/_sr_arch. The "granitemoehybrid" registry key is
retained (mapped to the shared arch) because real Granite 4.x dense
checkpoints are still typed granitemoehybrid upstream; a "granitemoeshared"
key is added alongside.

vLLM backend:
- Removed the vestigial IsHybrid / HasInnerState marker mixins (no hybrid
  contract was implemented).
- The two borrowed upstream classes (GraniteMoeMoE, GraniteMoeSharedMLP)
  now load via a version-tolerant helper that prefers the non-hybrid
  granitemoe / granitemoeshared modules and falls back to granitemoehybrid,
  so a single codebase works across the pinned vLLM versions.

Local CPU tests pass (unit, config sis-trap, composer arch skinning, HF
granite4 equivalence, HF forward/lora/multi-switch). vLLM and GPU
generation tests to run on the cluster.

Signed-off-by: antonp <[email protected]>

* Add adapter-generation smoke script for de-hybridization validation

eval/gen_smoke.py loads a composed Granite Switch checkpoint in vLLM and
generates the same question with the base path and with each adapter's
control token, printing the outputs so a reviewer can confirm the
de-hybridized (granitemoeshared) backend both loads and routes adapters.
Used by the Vela validation job (vela_yamls/dehybridize_vllm_gen.yaml).

Signed-off-by: antonp <[email protected]>

* remove unused file

Signed-off-by: antonp <[email protected]>

* Bumping transformers to 5.16

Signed-off-by: antonp <[email protected]>

* fix linting

Signed-off-by: antonp <[email protected]>

* Correct layer names

Signed-off-by: antonp <[email protected]>

* Rename MoE layers tp match 5.16

Signed-off-by: antonp <[email protected]>

* Change vllm test name

Signed-off-by: antonp <[email protected]>

* Fix vLLM FusedMoE expert-weight load path (routed_experts)

vLLM >=0.26 registers the fused expert bank via FusedMoEFactory at
block_sparse_moe.experts.routed_experts.w13_weight / .w2_weight. The HF->vLLM
stacked-MoE loader targeted experts.w13_weight (missing the routed_experts.
segment), so the packed tensors were never loaded: vLLM reported them
UNINITIALIZED and the fallthrough direct-load tripped
"RoutedExperts.weight_loader() missing 3 positional args". Point the loader's
w13/w2 targets at the routed_experts path and update the MoE weight-load test's
readback to the routed_experts submodule. Verified against the 0.26 and 0.27
lines.

Signed-off-by: itzikvaisman <[email protected]>

* Tolerate sub-ULP logprob noise in the vLLM skinning-equivalence check

test_skinning_equivalence_vllm[granite-4.0-micro] and its _thorough variant
compare the skinned GraniteSwitch model against the original through vLLM and
gated the top-K logprobs at d > 0 -- literal bit-exactness. But the skinned
model runs its projections through the fused SWITCH Triton kernel while the
original uses vLLM's native linear, and the two have different float-reduction
orders even at zero adapter (CLAUDE.md Gotcha generative-computing#9). Whether that sub-ULP noise
lands on zero is vLLM-version-dependent: both tests pass on 0.19.1 and 0.20 but
fail on 0.26 with max |diff| = 1.907349e-06 (== 2^-19, i.e. 1-2 ULP at these
logprob magnitudes). Every differing value across all 8 thorough requests was
one of 2^-19 / 2^-20 / 2^-21 -- the reduction-order fingerprint, not drift.

Gate at LOGPROB_ATOL = 1e-5 instead: ~5x above the observed noise floor, orders
of magnitude below any real logit/weight regression (which shifts logprobs by
>> 1e-3). This mirrors the philosophy already documented for the authoritative
test_generation_equivalence.py, which gates distribution equivalence rather than
token-exact match for exactly this reason.

max_diff now tracks the true max including tolerated noise so drift toward the
threshold stays visible even on a pass; the FAIL/OK prints and the module
docstring drop the now-inaccurate "bit-exact" wording.

Signed-off-by: antonp <[email protected]>

* Relax granite4-mini inert-path equivalence from bit-exact to ~1 ULP

The zero-adapter / no-control-token vLLM equivalence tests asserted bitwise
identity (atol=0, rtol=0) between an inert GraniteSwitch and the upstream
GraniteMoeHybrid reference on identical transferred weights. That held only
while GraniteSwitch inherited GraniteMoeHybrid. After the de-hybridization
(GraniteMoeShared base), the inert forward runs an equivalent-but-different
reduction-order vLLM path, so the logprobs drift by ~1 bf16 ULP (measured
max_abs_diff 4.77e-7 == 2^-21, mean ~3e-8 across 4.0-mini {1b,350m,micro});
still far below model noise.

get_tolerances() now returns (1e-5, 1e-5) for the inert base-model path
instead of None (~20x the measured worst case, ~1000x tighter than the
adapter path, so a real logit regression still trips it), and the three
affected tests (TestGranite4FamilyEquivalence::test_logits_short/long,
TestZeroAdapterNoHiding::test_no_control_tokens) use it. Test-only change.

Signed-off-by: antonp <[email protected]>

* Document shared_intermediate_size==0 skip-MLP contract and pin config boundary

Add CLAUDE.md Gotcha generative-computing#13 explaining that shared_intermediate_size == 0 means
skip the shared MLP (not build a zero-width one), and that the no-MLP-path
rejection lives in the decoders, not the config. Add config-level tests pinning
that boundary: pure-MoE excludes the shared_mlp LoRA targets, and a config with
neither experts nor a shared MLP is permitted at config level.

Signed-off-by: itzikvaisman <[email protected]>

* Drop layer_types and position_embedding_type from the switch config

The switch model is attention-only with unconditional RoPE, so both fields were
redundant for every targeted Granite base (4.0-micro/4.1/4.2/5.0 all resolve to
RoPE). layer_types was only ever consumed as a cache of a value transformers
derives itself: DynamicCache(config=...) builds an all-full_attention per-layer
layout from num_hidden_layers when layer_types is absent, so carrying it added a
32-default fallback that was wrong for every 40-layer target. position_embedding_type
had no transformers-side reader and only gated our own RoPE construction.

Remove both from GraniteSwitchConfig, the composer arch descriptors, and the
DynamicCache-length synthesis; collapse the four decoder RoPE gates to always-on;
replace the layer_types attention scan with the attention-only num_adapters>0
invariant. Tests now assert the config carries neither field and that DynamicCache
derives the correct per-layer layout from num_hidden_layers, including across a
from_dict round-trip (the load-from-config path).

Signed-off-by: antonp <[email protected]>

* Inline the upstream MoE/shared-MLP imports; drop the _upstream_layers shim

_upstream_layers.py was added in the de-hybridization reparent (8bed9dc) as a
version-tolerant wrapper: each getter tried the non-hybrid module
(granitemoe / granitemoeshared) and fell back to granitemoehybrid on
ImportError. That fallback is dead code across the supported vLLM range --
granitemoe.GraniteMoeMoE and granitemoeshared.GraniteMoeSharedMLP export
directly on 0.19.1, 0.20.2, 0.26.0 and 0.27.1 (verified against the release
tags), and granitemoehybrid merely re-imports from those two modules rather
than owning the classes. So the try branch always wins and the wrapper reduced
to an indirection around a one-line import.

Inline the direct non-hybrid imports at the four call sites (has_experts /
has_shared_mlp in both the LoRA and SR decoders) and delete the module. Behavior
is identical; the switch keeps its non-hybrid sourcing (the point of
de-hybridization) without the extra layer.

Signed-off-by: antonp <[email protected]>

* Revert GraniteSwitch reparent: restore GraniteMoeHybrid base

Re-establish the dependency on the transformers GraniteMoeHybrid class
family (config parent, HF modeling classes, and core/lora imports),
undoing the reparent to GraniteMoeShared while keeping the transformers
5.16 bump and its MoE-layer rename (experts()/top-k router API).

config: GraniteSwitchConfig extends GraniteMoeHybridConfig again. Because
the hybrid parent's __post_init__ defaults an unset layer_types to all
"linear_attention" (mamba), the config once more pins layer_types to
["full_attention"] * num_hidden_layers and passes position_embedding_type
through to super().__init__(); otherwise DynamicCache would size the wrong
per-layer cache and validate_layer_type would reject an inflated config.
The explicit shared_intermediate_size resolution is kept (dense ->
intermediate_size, pure-MoE -> 0, explicit honored) since the hybrid
parent's 1024 default is the wrong width for dense bases.

hf: modeling and core/lora repoint to the granitemoehybrid twins;
GraniteSwitchPreTrainedModel inherits GraniteMoeHybridPreTrainedModel. The
5.16 MoE API (router -> (top_k_index, top_k_weights, logits); experts(h,
idx, w)) and the dense MLP's input_linear/output_linear are identical
across the hybrid/shared twins, so the rename work is unaffected.

composer: granite_moe_shared_arch/_sr_arch renamed back to
granite_moe_hybrid_arch/_sr_arch (exports updated); the granitemoeshared
registry key is retained alongside granitemoehybrid.

tests: update layer_types assertions to the hybrid-parent reality
(all-attention, correct length), fix shared/hybrid references in
docstrings, and re-attribute the inert-path ULP tolerance to the fused
SWITCH kernel reduction order (Gotcha generative-computing#9) rather than the base class.

Signed-off-by: antonp <[email protected]>

* Back the abandoned GraniteMoeShared reparent out of the dependency upgrade

This PR upgrades to transformers 5.16+ / vLLM 0.26+. It also carried the
remains of an experiment that reparented GraniteSwitchConfig from
GraniteMoeHybrid to GraniteMoeShared. That experiment was abandoned -- we
stay on GraniteMoeHybrid -- and the earlier revert reached only 13 of its
16 files. The leftovers were pure review noise, and two of them named
classes that do not exist.

Drop granitemoeshared as a supported model_type. Nothing consumed the two
registry keys except the assertions added alongside them, and no fixture
types a base that way, so removing them is a no-op. resolve_arch now
raises its normal "Unsupported architecture" error for such a base.

Fix two factually wrong comments. GraniteMoeSharedMoE exists in neither
vLLM nor transformers; the HF backend builds GraniteMoeHybridMoE.

Import GraniteMoeMoE and GraniteMoeSharedMLP from granitemoehybrid again.
vLLM's granitemoehybrid re-exports both, so either path resolves on 0.26 --
one path keeps the intent legible.

Restore the position_embedding_type gate around RoPE construction. The
reparent collapsed it because the Shared config has no such field;
GraniteSwitchConfig still does, so the escape hatch is still real.

Everything the dependency upgrade actually needs is untouched: the
experts.gate_up_proj / down_proj / router.weight tensor renames, the
(top_k_index, top_k_weights) router return, the routed_experts FusedMoE
param path, and the ["full_attention"] * num_hidden_layers pin.

Record why IsHybrid and HasInnerState must stay dropped. Declaring them
now makes vLLM size the KV cache for zero attention layers: transformers
5.16 remaps "attention" to "full_attention", ModelConfig.is_hybrid's
granite-4.0-micro escape hatch still compares against the literal
"attention", and get_num_layers_by_block_type counts that literal. This
only worked on vLLM 0.19 + transformers 5.9 because layer_types was
literally ["attention"] then.

Signed-off-by: itzikvaisman <[email protected]>

* Pin the compiler in the full-size vLLM equivalence test

test_logits_match[4.0-micro] has flapped since 2026-09-24, going red about
one run in seven with a bit-reproducible 130708 elements over tolerance,
worst diff=2.9306e-03 at |expected|=11.279.

Measured on one A100-80GB node at this exact config, 2026-09-29/30:

  * The noise floor is EXACTLY ZERO.  Six engines per config as six separate
    processes, five pairs compared over 702464 elements, for all three
    full-size configs: upstream against ITSELF through two separate engines,
    switch against itself, and switch against upstream are all 0.0000e+00.
    15/15 bit-exact.  So there is no bf16 floor here to hide behind, the
    1e-5 in get_tolerances is not too tight, and the switch's math is right.
    The tolerance is deliberately NOT touched.

  * The red reproduces with this file run ALONE on a cleared compile cache,
    and stays green on 13 of 14 otherwise-identical runs.  No preceding
    test, no suite interaction, no GPU count, no cache warmth and no
    parameter ordering is involved -- each eliminated by its own leg.

  * The failure takes only two discrete, bit-reproducible values
    (2.9306e-03 and 2.9297e-03) out of an unpinned compiler.  That is the
    signature of kernel selection, which autotune makes by timing and then
    caches.  Corroborating: the failing logs show a Triton JIT of
    _topk_log_softmax_kernel, the very reduction producing the logprobs
    being compared.  2.9e-3 absolute at |expected|=11.28 is 2.6e-4
    relative, under one bf16 ulp (0.031) -- a reduction-order difference,
    not a logic error.

This was the only vLLM equivalence test that left torch.compile, CUDA-graph
capture and Triton autotune live.  _granite4_mini_tests.py already pins
enforce_eager for the one config that needed it, and those tests never flap
at the same 1e-5 gate, so pinning is the established idiom in this test
family.  An equivalence test must not measure the compiler as well as the
model.

enable_prefix_caching is set for symmetry, not as a fix: upstream declares
IsHybrid and the switch deliberately does not, so vLLM 0.26 resolved the
flag False for one engine and True for the other.  That asymmetry was
separately measured to be numerically inert, but a comparison should have
exactly one variable in it.

Evidence level: consistent with, not proven by A/B.  A 12-round balanced
A/B is in flight; at a 1-in-7 base rate it cannot reach significance, so
the argument above is mechanistic.  At the time of writing the control arm
has reproduced the red (1/8) and the treated arm has not (0/7).

Signed-off-by: itzikvaisman <[email protected]>

---------

Signed-off-by: antonp <[email protected]>
Signed-off-by: itzikvaisman <[email protected]>
Co-authored-by: itzikvaisman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants