Skip to content

Commit bcd2268

Browse files
justinchubyCopilot
andcommitted
Reconcile MTP closure with current main
Preserve fail-closed quantized ownership while allowing the reviewed Q4_1 dedicated MTP head to dequantize explicitly. Keep deterministic test tensor ordering and compatible multi-head diagnostics after the parent squash reconstruction. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 3c39aa6 commit bcd2268

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎src/mobius/integrations/gguf/_builder.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import re
2323
import struct
2424
from collections import Counter
25-
from collections.abc import Callable, Iterable, Mapping
25+
from collections.abc import Callable, Collection, Iterable, Mapping
2626
from pathlib import Path
2727
from typing import TYPE_CHECKING
2828
from urllib.parse import urlparse
@@ -3337,6 +3337,7 @@ def _load_quantized_state_dict(
33373337
name_mapper: Callable[[str, str], str | None] | None = None,
33383338
warn_unmapped: bool = True,
33393339
reuse_candidates: dict | None = None,
3340+
dequantize_float_linear_types: Mapping[str, Collection[str]] | None = None,
33403341
) -> dict:
33413342
"""Load tensors, preserving native blocks or normalizing to MatMulNBits.
33423343
@@ -3554,6 +3555,11 @@ def _load_quantized_state_dict(
35543555
}
35553556
and not should_repack
35563557
and not fused_projection_targets
3558+
and (
3559+
dequantize_float_linear_types is None
3560+
or module_stem not in dequantize_float_linear_types
3561+
or quant_spec.name not in dequantize_float_linear_types[module_stem]
3562+
)
35573563
):
35583564
raise ValueError(
35593565
f"Cannot keep {quant_spec.name} {tensor_role.value} {hf_name} "

‎src/mobius/integrations/gguf/_mtp.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ def validate_mtp_tensor_contract(gguf_model) -> None:
350350
)
351351
if count != 1:
352352
raise ValueError(
353-
f"{architecture} GGUF declares {count} MTP heads; ModelPackage can represent "
354-
"exactly one and will not silently truncate the remaining heads"
353+
f"{architecture} GGUF declares {count} MTP heads and has {count} MTP blocks, "
354+
"but only exactly one appended MTP block can be represented; refusing to "
355+
"silently truncate the remaining heads"
355356
)
356357
if legacy_tensors:
357358
raise ValueError(
@@ -620,6 +621,7 @@ def _mapper(gguf_name: str, _arch: str) -> str | None:
620621
mtp_config,
621622
name_mapper=_mapper,
622623
warn_unmapped=False,
624+
dequantize_float_linear_types={"lm_head": {"Q4_1"}},
623625
)
624626
# Mirror the backbone (build_from_gguf steps 7/7b): run process_tensors
625627
# over only the float tensors (native quant blocks were already

‎src/mobius/integrations/gguf/_mtp_test.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,17 @@ def _add_decoder_block(idx: int) -> None:
164164
matrix(f"{prefix}.nextn.embed_tokens.weight", (_VOCAB, _H))
165165
if dedicated_norm:
166166
f32(f"{prefix}.nextn.shared_head_norm.weight", (_H,))
167+
if unknown_nextn:
168+
f32(f"{prefix}.nextn.unknown.weight", (_H,))
169+
if extra_mtp_tensor is not None:
170+
f32(extra_mtp_tensor, (_H,))
171+
_add_decoder_block(index)
167172
if dedicated_head:
168173
matrix(
169174
f"{prefix}.nextn.shared_head_head.weight",
170175
(_VOCAB, _H),
171176
asymmetric=asymmetric_dedicated_head,
172177
)
173-
if unknown_nextn:
174-
f32(f"{prefix}.nextn.unknown.weight", (_H,))
175-
if extra_mtp_tensor is not None:
176-
f32(extra_mtp_tensor, (_H,))
177-
_add_decoder_block(index)
178178

179179
if quantized_backbone_embedding:
180180
matrix("token_embd.weight", (_VOCAB, _H))

0 commit comments

Comments
 (0)