Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
78762b2
add initial tests
guarin Nov 17, 2026
0bab3c2
init draft version
guarin Nov 17, 2026
01147ff
Merge branch 'main' into add-inkling2-loop
guarin Nov 17, 2026
a69e017
update tests
guarin Nov 18, 2026
02ee726
more todo
guarin Nov 18, 2026
39b88b8
update cache layer handling
guarin Nov 18, 2026
aa0cc26
cleanup
guarin Nov 18, 2026
ef5f4bb
split layers
guarin Nov 18, 2026
3f2a85f
cleanup message passing
guarin Nov 18, 2026
f848297
update gates
guarin Nov 18, 2026
aea1583
refactor message passing
guarin Nov 18, 2026
7434736
cleanup
guarin Nov 18, 2026
1c79cce
update
guarin Nov 19, 2026
9354250
cleanup
guarin Nov 19, 2026
abe7127
remove defensive checks
guarin Nov 19, 2026
e2abf0f
move to correct place
guarin Nov 19, 2026
29b216e
dequant step 1
guarin Nov 19, 2026
737f980
flatten loop config
guarin Nov 19, 2026
6fa0050
merge message queries
guarin Nov 19, 2026
6f3482c
fix
guarin Nov 19, 2026
1aa26ba
norm
guarin Nov 19, 2026
5a3dab4
update init weights
guarin Nov 19, 2026
a6a4af2
split layer loop
guarin Nov 19, 2026
2983e57
more splitting
guarin Nov 19, 2026
c1846e6
fix tests
guarin Nov 19, 2026
ff6dc64
rename
guarin Nov 19, 2026
d03e8d3
update inkling2 attentions
guarin Nov 19, 2026
9507570
remove unneeded layers
guarin Nov 19, 2026
06661c0
more cleanup
guarin Nov 19, 2026
ef20ef1
cleanup
guarin Nov 19, 2026
e23ef0f
refactor relative logits
guarin Nov 19, 2026
908b61b
merge k/v proj
guarin Nov 19, 2026
cb6894c
move things
guarin Nov 19, 2026
1a8cad7
fix packed sequences
guarin Nov 20, 2026
cc4f307
add Inkling2GatedOutputProjection
guarin Nov 20, 2026
d425f55
drop sdpa
guarin Nov 20, 2026
6427d4f
refactor scales
guarin Nov 20, 2026
6620ca6
refactor rel pos bias
guarin Nov 20, 2026
eb892bf
minor
guarin Nov 20, 2026
32049ef
fix repo
guarin Nov 20, 2026
ed58c54
handle unpadded_vocab_size
guarin Nov 20, 2026
3add884
merge kv proj
guarin Nov 20, 2026
6e657c3
fix repo
guarin Nov 20, 2026
9a94031
fix head loading
guarin Nov 20, 2026
3b75972
fix mxfp8 loading
guarin Nov 20, 2026
b01cd5f
use attn interface
guarin Nov 20, 2026
48141e7
text_hidden_size is now in the config
guarin Nov 20, 2026
1a15086
use dory caching
guarin Nov 20, 2026
c9ccbdb
move norm to proj
guarin Nov 20, 2026
9aed9db
move test
guarin Nov 20, 2026
e843e8f
update docs
guarin Nov 20, 2026
9ed3671
add todo
guarin Nov 20, 2026
18c8ac8
update tests
guarin Nov 20, 2026
3ed39b6
update docs
guarin Nov 20, 2026
46c36e5
add blog link
guarin Nov 20, 2026
6b1044a
tiny checkpoint
guarin Nov 20, 2026
9a1ff82
Merge branch 'main' into add-inkling2-loop
guarin Nov 20, 2026
eb4b4a3
cleanup
guarin Nov 20, 2026
6819273
make linter happy
guarin Nov 20, 2026
8d628c7
cleanup
guarin Nov 20, 2026
09c356e
add a10 expectations
guarin Nov 20, 2026
f0fd853
skip export tests
guarin Nov 20, 2026
e916f57
Merge branch 'main' into add-inkling2-mini
guarin Nov 20, 2026
c5b376c
update links
guarin Nov 20, 2026
e18dccc
update links
guarin Nov 20, 2026
e3a65e2
Merge branch 'add-inkling2-mini' of https://github.com/huggingface/tr…
guarin Nov 20, 2026
6173a2f
update tests
guarin Nov 20, 2026
bc3f715
fix fp32 loading
guarin Nov 21, 2026
a10ebc3
add kernels note
guarin Nov 21, 2026
430050f
consistency
Cyrilvallez Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dequant step 1
  • Loading branch information
guarin committed Nov 19, 2026
commit 29b216e20b2c04af4f9aee21c00f05aea7312a4a
33 changes: 32 additions & 1 deletion src/transformers/conversion_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ErnieFuseAndSplitTextVisionExperts,
GroupWeightRename,
Inkling2IndexOffsetWeightRename,
Inkling2LoopDequantizeExperts,
Interleave,
MergeModulelist,
PermuteForRope,
Expand Down Expand Up @@ -2577,6 +2578,35 @@ def _build_checkpoint_conversion_mapping():
]

mapping["inkling2_loop"] = mapping["inkling2"].copy()
# Temporary: the original Inkling2Loop checkpoints store NVFP4 and MXFP8 experts. They are dequantized on load and
# replace the Inkling2 expert transforms, which keep MXFP8 experts quantized.
inkling2_loop_experts = [
WeightConverter(
source_patterns=[
r"mlp\.experts\.w13_weight",
r"mlp\.experts\.w13_weight_scale",
r"mlp\.experts\.w13_weight_amax",
r"mlp\.experts\.w13_weight_outer_scale_denominator",
],
target_patterns=r"mlp.experts.gate_up_proj",
operations=[Inkling2LoopDequantizeExperts(), Interleave(dim=1)],
),
WeightConverter(
source_patterns=[
r"mlp\.experts\.w2_weight",
r"mlp\.experts\.w2_weight_scale",
r"mlp\.experts\.w2_weight_amax",
r"mlp\.experts\.w2_weight_outer_scale_denominator",
],
target_patterns=r"mlp.experts.down_proj",
operations=[Inkling2LoopDequantizeExperts()],
),
]
inkling2_text = [
transform
for transform in mapping["inkling2_text"]
if not transform._original_source_patterns[0].startswith(r"mlp\.experts\.w")
]
mapping["inkling2_loop_text"] = [
WeightRenaming(source_patterns=r"controllers\.attn\.", target_patterns=r"q_message_gate."),
WeightRenaming(source_patterns=r"controllers\.k\.", target_patterns=r"k_message_gate."),
Expand All @@ -2600,7 +2630,8 @@ def _build_checkpoint_conversion_mapping():
target_patterns=r"message_input.query",
operations=[Concatenate(dim=1)],
),
] + mapping["inkling2_text"].copy()
*inkling2_loop_experts,
] + inkling2_text

for model_type, base_pattern in _MODEL_TO_CONVERSION_PATTERN.items():
if model_type in mapping:
Expand Down
51 changes: 51 additions & 0 deletions src/transformers/core_model_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,57 @@ def reverse_op(self) -> ConversionOps:
return ErnieFuseAndSplitTextVisionExperts(stack_dim=self.stack_dim, concat_dim=self.concat_dim)


class Inkling2LoopDequantizeExperts(ConversionOps):
r"""
Temporary op that dequantizes the NVFP4 and MXFP8 expert weights of the original Inkling2Loop checkpoints to the
dtype of the model param, until these formats can be loaded quantized.

- NVFP4 (`amax` present): two E2M1 codes per byte (even element in the low nibble), one float8 scale per 16 values
and a per-expert factor `amax / outer_scale_denominator`.
- MXFP8: float8 values with one power-of-two scale `2 ** (scale - 127)` per 32 values.
"""

E2M1_VALUES = (0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0)
EXPERTS_PER_CHUNK = 8

@torch.no_grad()
def convert(self, input_dict, source_patterns, target_patterns, model=None, full_layer_name=None, **kwargs):
tensors = {key: value[0] if isinstance(value, list) else value for key, value in input_dict.items()}
if len(tensors) == 1:
return {target_patterns[0]: next(iter(tensors.values()))}
weight, scale, amax, denominator = (tensors.get(pattern) for pattern in source_patterns)

# Without a quantizer, the loader casts all sources to the param dtype, but don't rely on it
try:
dtype = model.get_parameter(full_layer_name).dtype
except (AttributeError, TypeError):
dtype = torch.bfloat16
num_experts, rows = weight.shape[:2]
columns = weight.shape[2] * 2 if amax is not None else weight.shape[2]
output = torch.empty(num_experts, rows, columns, dtype=dtype, device=weight.device)
if amax is not None:
e2m1_values = torch.tensor(self.E2M1_VALUES, device=weight.device)
byte = torch.arange(256, device=weight.device)
byte_to_values = torch.stack((e2m1_values[byte & 0xF], e2m1_values[byte >> 4]), dim=-1)
expert_factor = amax.float() / denominator.float()
for start in range(0, num_experts, self.EXPERTS_PER_CHUNK):
experts = slice(start, start + self.EXPERTS_PER_CHUNK)
block_scale = scale[experts].float()
if amax is None:
values = weight[experts].float().view(*block_scale.shape, 32)
values = values * torch.exp2(block_scale - 127)[..., None]
else:
codes = weight[experts].to(torch.uint8).long()
values = byte_to_values[codes].view(*block_scale.shape, 16) * block_scale[..., None]
values = values * expert_factor[experts, None, None, None]
output[experts] = values.reshape(-1, rows, columns).to(dtype)
return {target_patterns[0]: output}

@property
def reverse_op(self) -> ConversionOps:
return self


def process_target_pattern(pattern: str) -> tuple[str, str | None]:
"""
Process a target pattern for reverse mapping (when targets become sources).
Expand Down