Repository navigation
Read config.dtype instead of the deprecated config.torch_dtype alias - #3049
Conversation
config.torch_dtype is an alias of config.dtype that returns None when unset instead of being absent, so getattr defaults on it never apply. Read config.dtype directly in the DFlash export, _resolve_export_dtype and the HF trainer. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Keval Morabia <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Use config.dtype for dtype selection modelopt/torch/export/plugins/hf_spec_export.py, modelopt/torch/export/unified_export_hf.py, modelopt/torch/opt/plugins/transformers.py, tests/unit/torch/export/test_hf_spec_rope_export.py, tests/unit/torch/export/test_unified_export_hf.py |
Export and trainer code read configured dtype from config.dtype. DFlash export falls back to torch.bfloat16 when the base config dtype is None. Tests check the fallback and use dtype in configured dtype fixtures. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: chenhanyu
Merge Risk: 
Minimal · up to e029c
-
The PR is mergeable; no confirmed correctness, availability, or dependency-collection risk remains.
Pre-merge checks: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed-
Full details: Security Anti-Patterns
-
Explanation
The authoritative PR diff changes only dtype access and tests. It adds no
torch.load(..., weights_only=False),numpy.load(..., allow_pickle=True), hardcodedtrust_remote_code=True, external-inputeval()/exec(), or# nosec. It changes nopyproject.tomlor requirements file. Therefore, it introduces none of the listed security anti-patterns.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
meenchen
left a comment
There was a problem hiding this comment.
Bot review (gpt-6.1-sol) — DM the bot to share feedback.
Changes requested: the new unconditional Transformers import breaks collection of otherwise dependency-light export tests when the optional HF extra is absent.
Needs action:
- Guard the
LlamaConfigdependency intest_hf_spec_rope_export.pyso only the real-config regression skips without Transformers; preserve collection and execution of the other tests.
No action needed:
- The dtype readers match the supported Transformers >=5.5 API, and the DFlash fallback handles an unset dtype correctly.
- Existing fixture edits are justified by the field migration; assertions remain intact. Tests were inspected, not executed.
transformers is an optional dependency, so import it inside the one test that needs it instead of at module level, which broke collection of the other export tests without the hf extra. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Keval Morabia <[email protected]>
meenchen
left a comment
There was a problem hiding this comment.
Bot review (gpt-6.1-sol) — DM the bot to share feedback.
LGTM: the prior optional-dependency collection issue is resolved; human sign-off remains required for the justified existing-test edits.
Needs action:
- Confirm the existing export-test fixture migrations from
torch_dtypetodtype; they match the supported API change and preserve all assertions.
No action needed:
- ✔️ Resolved the critical collection issue:
LlamaConfigis accessed through test-localpytest.importorskip("transformers"), leaving other tests collectable without the HF extra. - The DFlash regression covers explicit float16 and unset-dtype bfloat16 fallback. Tests were inspected, not executed.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3049 +/- ##
==========================================
- Coverage 79.97% 79.43% -0.54%
==========================================
Files 661 661
Lines 75419 75419
==========================================
- Hits 60315 59911 -404
- Misses 15104 15508 +404
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What does this PR do?
Type of change: Bug fix
config.torch_dtypeis a deprecated alias ofconfig.dtype(transformers>=5.5) that returnsNonewhen unset instead of raising, so agetattr(config, "torch_dtype", default)never reaches its default. This readsconfig.dtypedirectly in:modelopt/torch/export/plugins/hf_spec_export.py: the DFlash export wrote the string"None"astorch_dtypefor a base config without a dtype; it now falls back tobfloat16.modelopt/torch/export/unified_export_hf.py:_resolve_export_dtypenow readsconfig.dtype(behavior unchanged, no deprecation warning).modelopt/torch/opt/plugins/transformers.py: dropped the redundanttorch_dtypefallback.Left unchanged: the
"torch_dtype"keys written to exportedconfig.jsonfiles and the eagle/spec-dec default configs (on-disk format), and the legacytorch_dtype=kwarg accepted byinit_quantized_weights(public API; handled in #2161).Related: #2161 (same defect in
init_quantized_weights).Usage
N/A, no API change.
Testing
tests/unit/torch/export/test_hf_spec_rope_export.pyandtest_unified_export_hf.py: 69 passed (CPU). The newtest_dflash_torch_dtype_inherits_base_or_defaultsuses a realLlamaConfigand fails without the fix for the unset-dtype case.tests/unit/torch/opttransformers tests fail at collection with and without this change in my environment (TypeErroronNone), so the trainer change is covered only by inspection.Before your PR is "Ready for review"
🤖 Generated with Claude Code
Summary by CodeRabbit
None.