Repository navigation
Weight loading: conversion ops declare many-to-many support, and four small loader fixes - #49773
Conversation
d0cff10 to
011df9d
Compare
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
6765030 to
89032a4
Compare
|
[For maintainers] Suggested jobs to run (before merge) run-slow: minimax_m3_vl, muse_spark |
89032a4 to
b837014
Compare
vasqu
left a comment
There was a problem hiding this comment.
Mainly concerned about that 1 main block for conversions so rather let Arthur/Cyril check that out
| converted_key, source_pattern = rename_source_key(original_key, [], converters, reverse=True) | ||
| if source_pattern is not None: | ||
| new_converter = deepcopy(pattern_to_converter[source_pattern]) | ||
| # each target key gets its own converter instance | ||
| mapping = conversion_mapping.setdefault(renamed_key, new_converter) | ||
| # Rename after conversion, so the converter still sees the model's names. | ||
| # Each target key gets its own converter instance. | ||
| if converted_key not in conversion_mapping: | ||
| conversion_mapping[converted_key] = deepcopy(pattern_to_converter[source_pattern]) | ||
| mapping = conversion_mapping[converted_key] | ||
| mapping.add_tensor(converted_key, original_key, source_pattern, tensor) | ||
| else: | ||
| renamed_key, _ = rename_source_key(original_key, renamings, [], reverse=True) | ||
| mapping = conversion_mapping.setdefault(renamed_key, WeightRenaming(original_key, renamed_key)) | ||
| source_pattern = original_key | ||
|
|
||
| mapping.add_tensor(renamed_key, original_key, source_pattern, tensor) | ||
| mapping.add_tensor(renamed_key, original_key, original_key, tensor) | ||
|
|
||
| new_state_dict = {} | ||
| for first_param_name, reversed_converter in conversion_mapping.items(): | ||
| for layer_name, reversed_transform in conversion_mapping.items(): | ||
| # Apply the reverse converter | ||
| realized_value = reversed_converter.convert(first_param_name, model=model, config=model.config) | ||
| realized_value = reversed_transform.convert(layer_name, model=model, config=model.config) | ||
| for target_name, param in realized_value.items(): | ||
| param = param[0] if isinstance(param, list) else param | ||
| if isinstance(reversed_transform, WeightConverter): | ||
| target_name, _ = rename_source_key(target_name, renamings, [], reverse=True) |
There was a problem hiding this comment.
imo this is something more well suited for @ArthurZucker or @Cyrilvallez to check tbh
There was a problem hiding this comment.
yeah fair, cc @ArthurZucker @Cyrilvallez. during save, renamings were applied before converters, so a converter whose target gets renamed never matched and the key didn't round trip. now the converter works with model names and renamings go on its outputs, there's a round trip test for it
| for original_key, tensor in state_dict: | ||
| # Rename the key according to all renaming pattern and optional weight converter patterns | ||
| renamed_key, source_pattern = rename_source_key(original_key, renamings, converters, reverse=True) | ||
| converted_key, source_pattern = rename_source_key(original_key, [], converters, reverse=True) |
There was a problem hiding this comment.
it does look a bit weird skipping / passing empty lists around
There was a problem hiding this comment.
yeah it's ugly, will split it into two explicit steps
| if not self.operations: | ||
| raise ValueError("WeightConverter requires at least one operation.") | ||
|
|
||
| def copy(self, source_patterns, target_patterns, **kwargs) -> WeightConverter: |
There was a problem hiding this comment.
where did you encounter issues here?
There was a problem hiding this comment.
qwen4-exp, its ngram_embedding converter has force_cpu=True bcz the cat is ~95GiB. when the embedding is quantized the quantizer copies the converter for the scale, and copy was dropping force_cpu so the cat ran on gpu. reverse() goes through copy too
There was a problem hiding this comment.
True for copy, however reverse does not care about force_cpu anyway
There was a problem hiding this comment.
right ! updating the comment now, hope it doesn't interfere with your review 🙏
b837014 to
fcd32ed
Compare
805c40b to
bd1f71f
Compare
bd1f71f to
7f0af1d
Compare
7f0af1d to
9ba7111
Compare
3343e8e to
d8abfa4
Compare
Cyrilvallez
left a comment
There was a problem hiding this comment.
Nice! Overall agreed with those changes. However, I think the changes for reverse loading are non-trivial, so I opened #49928 instead (where I added you as co-author) instead, to be able to isolate the change and make it a bit simpler. If it's okay with you, we can proceed to merge that one PR, and then update this one to contain only the other smaller changes
|
Merged the linked PR @IlyasMoutawwakil, we can rebase this onto main |
b808eb8 to
5ecaeff
Compare
5ecaeff to
b2f8616
Compare
b2f8616 to
77f0dd4
Compare
|
This PR might need docs. This adds a new public opt-in flag, Pages that might need an update:
Posted automatically after approval. Docs live in |
|
Ok merging this one to unblock #50301 as well! |
|
it's good, the fsdp job failure is not from this PR. merge now |
What.
ConversionOps.supports_many_to_manyreplaces the hard-coded tuple of Ernie 4.5 VL ops inWeightConverter.Core no longer imports an op to allow it. The Ernie ops set the flag here. The first op outside core is
FineGrainedWeightGlobalsin NVFP4 on the fine-grained machinery #49779.SplitModulelistsqueezes only the split dim. A size-1 dim of the tensor itself stays. Any save that splitsstacked experts back loses that dim otherwise, e.g. an expert's block scales with a single column.
WeightConverter.copykeepsforce_cpu. Qwen4-Exp'sngram_embeddingconverter setsforce_cpu=Trueon main,because the concatenated embedding is about 95 GiB.
reverse_transformgoes throughcopy, so the save pathdropped it. The quantizer also copies converters for scale companions in Quantizer API: checkpoint renames, skip-lists in checkpoint names, dequantized saves #49774.
dtype first. Casting bf16 into int8 storage zeroes it, and casting into float8 rounds it twice. FP8 in FP8 on the fine-grained machinery (
Fp8Config) #49777rounded twice, and MXFP4's int8-packed weights in 🚨 MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan #49778 came out zero.
Pre-quantized loads are unchanged. Every tensor is still cast as before, including the on-disk scale containers,
and
get_new_dtypestill runs.Depends on. #49786.
How tested. New tests in
tests/utils/test_core_model_loading.py.test_qkv_chunk_rope_permute_with_fp8_quantizationalreadyfails on main; #49777 replaces it.
The comments and docstrings that say why each change exists are there for readability. Feel free to ask for any of them to go if it's self-evident.
🤖 Generated with Claude Code