Support quantized tensor subclasses across Python and C++ - #3393
Open
dingqingy-nv wants to merge 4 commits into
Open
Support quantized tensor subclasses across Python and C++#3393dingqingy-nv wants to merge 4 commits into
dingqingy-nv wants to merge 4 commits into
Conversation
Signed-off-by: Dingqing Yang <dingqingy@nvidia.com>
Signed-off-by: Dingqing Yang <dingqingy@nvidia.com>
Signed-off-by: Dingqing Yang <dingqingy@nvidia.com>
dingqingy-nv
marked this pull request as ready for review
August 18, 2026 04:18
Contributor
Greptile SummaryThe PR extends quantized-tensor subclass support across Python detach operations and C++ type detection.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Tensor as QuantizedTensor subclass
participant Dispatch as PyTorch dispatch
participant Binding as C++ binding
Caller->>Dispatch: detach(tensor)
Dispatch->>Tensor: tensor.detach()
Tensor->>Tensor: type(self).make_like(self)
Tensor-->>Caller: detached runtime subclass
Caller->>Binding: update_quantized(src, subclass)
Binding->>Binding: PyObject_TypeCheck
Binding-->>Caller: update accepted in place
Reviews (2): Last reviewed commit: "Centralize quantized tensor detach" | Re-trigger Greptile |
ptrendx
reviewed
Aug 18, 2026
ptrendx
reviewed
Aug 18, 2026
ptrendx
reviewed
Aug 18, 2026
Signed-off-by: Dingqing Yang <dingqingy@nvidia.com>
ptrendx
approved these changes
Aug 18, 2026
Member
|
/te-ci pytorch |
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
Transformer Engine quantized tensors can be subclassed, but two boundaries assumed an exact concrete wrapper class:
detach()implementations reconstructed the base TE class, dropping the tensor's runtime subclass. PyTorch then rejected the result when rewrapping it as atorch.nn.Parameter, becauseParameterrequiresdetach()to preserve the exact runtime type.Py_TYPEcomparisons for quantized tensor outputs. As a result, operations such asMXFP8Quantizer.update_quantized(src, dst)rejected a validMXFP8Tensorsubclass even though Pythonisinstance(dst, MXFP8Tensor)was true.Megatron Core GTP exposes both cases because it represents native quantized parameters with dynamic subclasses such as
GTP_MXFP8Tensor. The newer module application path in #3153 made the latent detach mismatch visible. The downstream integration is NVIDIA/Megatron-LM#6546.Type of change
Changes
QuantizedTensor.detach()contract.Float8Tensor,Float8BlockwiseQTensor,MXFP8Tensor,NVFP4Tensor,IdentityTensor, andHybridQuantizedTensor.torch.nn.Parameterconstruction, andupdate_quantizedinto dynamic subclasses.Validation
Built and tested on GB300 from TE commit
bf64b4e8b2985ce7ff394b7f3cb240e764b24a3a:update_quantizedacross Float8, blockwise Float8, MXFP8, NVFP4, Identity, and Hybrid wrappers._applyattribute-preservation tests passed.NVTE_CUTEDSL_FUSED_GROUPED_MLP=1after installing the official final cuDNN-frontend 1.27.0 package:The cuDNN-frontend package replacement addresses a separate pre-release package mismatch around optional
prob_tensor; it is not part of this PR.Checklist