Dsv4 param mapping - #5000
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for DeepSeek-V4 checkpoint conversion, refactors attention masking logic, and introduces comprehensive reference tests. However, several critical issues were identified in the review: direct usage of hf_config instead of target_cfg breaks validation and updates for multimodal models; removing Gemma 4 attention dimension helpers breaks per_layer_config overrides; modifying DeepSeek-V2/V3 shape mappings breaks backward compatibility; incorrect dimension indexing and lack of unpadding in embedding and logit layers cause shape mismatch crashes during Hugging Face to MaxText conversion; and hardcoding compress ratios in the DeepSeek-V4 shape mapping limits custom configurations.
| for hf_attr, mt_attr in attributes_to_check: | ||
| # Skip checks if MaxText config doesn't have the attribute (shouldn't happen for valid configs) | ||
| if not hasattr(max_config, mt_attr): | ||
| # Skip checks if the HF config doesn't have this attribute (e.g. layer_norm_eps vs rms_norm_eps) | ||
| if not hasattr(hf_config, hf_attr): | ||
| continue | ||
|
|
||
| # Skip checks if the HF config doesn't have this attribute or raises AmbiguousGlobalPerLayerAttributeError | ||
| try: | ||
| hf_value = getattr(target_cfg, hf_attr) | ||
| except (AttributeError, ValueError, RuntimeError): | ||
| # Skip checks if MaxText config doesn't have the attribute (shouldn't happen for valid configs) | ||
| if not hasattr(max_config, mt_attr): | ||
| continue | ||
|
|
||
| hf_value = getattr(hf_config, hf_attr) | ||
| mt_value = getattr(max_config, mt_attr) |
There was a problem hiding this comment.
The removal of target_cfg and checking hf_config directly will break architecture validation for multimodal models (like Qwen2-VL) where text-specific attributes reside in hf_config.text_config. This causes hasattr(hf_config, hf_attr) to return False and silently skip all validation checks. We should restore target_cfg to ensure nested configurations are validated correctly.
| for hf_attr, mt_attr in attributes_to_check: | |
| # Skip checks if MaxText config doesn't have the attribute (shouldn't happen for valid configs) | |
| if not hasattr(max_config, mt_attr): | |
| # Skip checks if the HF config doesn't have this attribute (e.g. layer_norm_eps vs rms_norm_eps) | |
| if not hasattr(hf_config, hf_attr): | |
| continue | |
| # Skip checks if the HF config doesn't have this attribute or raises AmbiguousGlobalPerLayerAttributeError | |
| try: | |
| hf_value = getattr(target_cfg, hf_attr) | |
| except (AttributeError, ValueError, RuntimeError): | |
| # Skip checks if MaxText config doesn't have the attribute (shouldn't happen for valid configs) | |
| if not hasattr(max_config, mt_attr): | |
| continue | |
| hf_value = getattr(hf_config, hf_attr) | |
| mt_value = getattr(max_config, mt_attr) | |
| target_cfg = getattr(hf_config, "text_config", hf_config) or hf_config | |
| for hf_attr, mt_attr in attributes_to_check: | |
| # Skip checks if the HF config doesn't have this attribute (e.g. layer_norm_eps vs rms_norm_eps) | |
| if not hasattr(target_cfg, hf_attr): | |
| continue | |
| # Skip checks if MaxText config doesn't have the attribute (shouldn't happen for valid configs) | |
| if not hasattr(max_config, mt_attr): | |
| continue | |
| hf_value = getattr(target_cfg, hf_attr) | |
| mt_value = getattr(max_config, mt_attr) |
| if not is_match: | ||
| if override: | ||
| max_logging.log(f"⚠️ Overwriting HF Config '{hf_attr}': {hf_value} -> {mt_value} (from MaxText '{mt_attr}')") | ||
| setattr(target_cfg, hf_attr, mt_value) | ||
| setattr(hf_config, hf_attr, mt_value) |
Description
Start with a short description of what the PR does and how this is a change from
the past.
The rest of the description includes relevant details and context, examples:
If the change fixes a bug or a Github issue, please include a link, e.g.,:
FIXES: b/123456
FIXES: #123456
You can also provide a comma-separated list. If you don't want to close a bug but
simply to reference it, use BUGS, e.g.:
BUGS: b/123456
Notice 1: Once all tests pass, the "pull ready" label will automatically be assigned.
This label is used for administrative purposes. Please do not add it manually.
Notice 2: For external contributions, our settings currently require an approval from a MaxText maintainer to trigger CI tests.
Tests
Please describe how you tested this change, and include any instructions and/or
commands to reproduce.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.