Skip to content

[pyTorch] Replace the make_empty implementation to use C++ implementation#2666

Draft
ptrendx wants to merge 4 commits intoNVIDIA:mainfrom
ptrendx:pr_unify_make_empty
Draft

[pyTorch] Replace the make_empty implementation to use C++ implementation#2666
ptrendx wants to merge 4 commits intoNVIDIA:mainfrom
ptrendx:pr_unify_make_empty

Conversation

@ptrendx
Copy link
Member

@ptrendx ptrendx commented Feb 10, 2026

Description

This PR unifies the implementation of the QuantizedTensor creation by using the C++ implementation of the create_tensor.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Replaced the Python implementations of the make_empty with the calls to C++ create_tensor

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

known quantizers

Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
@ptrendx ptrendx requested a review from negvet February 10, 2026 00:17
@ptrendx
Copy link
Member Author

ptrendx commented Feb 10, 2026

/te-ci L1 pytorch

pre-commit-ci bot and others added 3 commits February 10, 2026 00:18
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
@ptrendx
Copy link
Member Author

ptrendx commented Feb 10, 2026

/te-ci L1 pytorch

"""Construct quantized tensor with uninitialized data"""
raise NotImplementedError(
f"{self.__class__.__name__} class does not implement make_empty function, "
"required for construction of unintialized quantized tensor"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clear NotImplementedError is beneficial for custom quantizers that do not override make_empty().
Now, if custom quantizer does not have make_empty(), then it will fail at the C++ convert_quantizer, because there is no registered C++ converter. C++ failure with NVTE_ERROR("Unexpected type for quantizer") is not as clear as NotImplementedError.

What about making C++ error more clear or even better add a check at base Quantizer.make_empty:

def make_empty(...):
    if getattr(self, "custom", False):
        raise NotImplementedError(
            f"{self.__class__.__name__} does not implement make_empty"
        )
    # ... existing C++ path ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants