Repository navigation
Conversation
QuantizerRole, QuantizerRequest, and DelayedScalingRequest are plain dataclasses, but they were defined in quantization.py, which forced the tensor package to import QuantizerRequest lazily from inside a method. Move them to a new leaf module, quantizer_types.py, that has no imports from the rest of transformer_engine.pytorch, and re-export them from quantization.py so the public API is unchanged. With the tensor package no longer depending on quantization.py at import time, the deferred quantizer imports in RecipeState.make_quantizers() can be hoisted to module level, resolving the TODO(ksivamani) notes. Signed-off-by: Muu <koimuu@163.com>
Contributor
[Low impact] The PR appears safe to merge; no actionable issues were found. SummaryMoves
No actionable issues found. Runtime tests were not run during this review. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
Q["quantization.py"] --> T["quantizer_types.py"]
Q --> P["tensor package"]
H["tensor/hybrid_tensor.py"] --> T
F["custom recipe factories"] --> T
A["Existing public type imports"] --> Q
Reviews (1) · Last reviewed commit: "[PyTorch] Break circular import between ..." · Reviewed by Greptile |
Contributor
Author
|
@ksivaman , Please review this PR and let me know if any adjustments are needed. Thanks for your time! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
QuantizerRole,QuantizerRequest, andDelayedScalingRequestare plain dataclasses, but they were defined inquantization.py. SinceHybridQuantizer.__init__needsQuantizerRequest, thetensorpackage had to import it lazily from inside a method, andquantization.pycompensated with five deferred quantizer imports inRecipeState.make_quantizers()(Float8Quantizer,Float8CurrentScalingQuantizer,MXFP8Quantizer,Float8BlockQuantizer,NVFP4Quantizer). Three of those carryTODO(ksivamani)notes asking for a better design. The lazy imports date back to TE 2.0, where thetensorpackage genuinely importedfp8; that back-edge is long gone, and this PR removes what it left behind.Fixes: no tracking issue — resolves the
TODO(ksivamani)notes intransformer_engine/pytorch/quantization.py.Type of change
Changes
transformer_engine/pytorch/quantizer_types.py, a leaf module containingQuantizerRole,QuantizerRequest, andDelayedScalingRequest(definitions unchanged). It imports nothing from the rest oftransformer_engine.pytorch.quantization.py: import and re-export the three dataclasses from the new module (still listed in__all__), hoist the five deferred quantizer imports to module level, and drop the now-unusedimport dataclasses.tensor/hybrid_tensor.py,custom_recipes/quantizer_factories.py,custom_recipes/quantizer_factory_zoo.py: import the dataclasses from the leaf module; no more local imports ofquantization.transformer_engine.pytorch.quantization.QuantizerRoleand friends still resolve, so user code, docs (autoapi), and old pickles are unaffected.quantization.pyare placed beforefrom .utils import ..., with a comment:.utilspulls inquantized_tensor(via the debug tooling), which imports a helper from insidetensor/, so thetensorpackage must be initializing for that import to succeed. This removes the reliance on the current import order within the package.No behavior change; pure import restructuring.
Testing
black(24.4.2, repo settings) andpylint(3.3.1, repopylintrc) on all touched files: no new warnings.transformer_engine.pytorch.tensorno longer reachesquantizationat module level, and no new cycles are introduced.python -c "import transformer_engine.pytorch"python -c "import transformer_engine.pytorch.quantization"pytest tests/pytorch/test_custom_recipe.pyChecklist: