Uh oh!
There was an error while loading. Please reload this page.
[PyTorch] Refactor C++ quantizer infrastructure - #1952
Conversation
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
baaef38 to
bd5e1ddComparefor more information, see https://pre-commit.ci
timmoon10
commented
Jul 16, 2025
/te-ci pytorch |
Signed-off-by: Tim Moon <tmoon@nvidia.com>
for more information, see https://pre-commit.ci
timmoon10
commented
Jul 17, 2025
/te-ci pytorch |
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Quantizer::create_tensor functionfor more information, see https://pre-commit.ci
timmoon10
commented
Jul 17, 2025
/te-ci pytorch |
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
timmoon10
commented
Jul 18, 2025
/te-ci pytorch |
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
for more information, see https://pre-commit.ci
timmoon10
commented
Jul 19, 2025
/te-ci pytorch L1 |
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
timmoon10
commented
Jul 21, 2025
/te-ci pytorch L1 |
Avoid problems with in-place ops after quantizer usages are changed externally. Signed-off-by: Tim Moon <tmoon@nvidia.com>
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Tim Moon <tmoon@nvidia.com>
| template <typename... ArgTs> | ||
| void launch(int device_id, const dim3 grid_dim, const dim3 block_dim, | ||
| unsigned int shared_mem_bytes, cudaStream_t stream, ArgTs &&...args) { | ||
| cuda_driver::ensure_context_exists(); |
There was a problem hiding this comment.
This PR exposed a bug in our NVRTC infrastructure. Three facts:
- The CUDA driver maintains a thread-local stack of CUDA contexts.
- PyTorch will initialize the CUDA context if needed for jitting.
- PyTorch performs autograd on a separate thread.
By removing unnecessary at::reciprocals from create_tensor, I experienced some cases where the backward pass launched an NVRTC kernel before launching any PyTorch ops (namely in the FP8 linear op with UB). Since the autograd thread's context stack was empty, this resulted in "invalid device context" errors.
There was a problem hiding this comment.
This is interesting, thanks!
Signed-off-by: Tim Moon <tmoon@nvidia.com>
timmoon10
commented
Jul 24, 2025
/te-ci core |
zhongbozhu
left a comment
There was a problem hiding this comment.
LGTM.
Will save us a lot of work for NVFP4 if we rebase on this PR.
ksivaman
commented
Jul 29, 2025
/te-ci pytorch L0 L1 |
Uh oh!
There was an error while loading. Please reload this page.
…A#1952 instead of manual quantization Signed-off-by: Jan Bielak <jbielak@nvidia.com>
Description
This PR makes three changes to the quantizer infrastructure in the
transformer_engine_torchextensions:Quantizer::quantizefunction. Previously this was duplicated in functions for quantization, activations, normalization, etc.Quantizer::convert_and_update_tensorfunction, similar to Make quantize_ respect the usages of the quantizer #1836.Quantizer::create_tensorto always return an uninitialized tensor, removing the need for an unnecessary scale reciprocal. For backward compatibility, some quantizer subclasses provide functions for creating initialized tensors.Arguments for removing the `rowwise_data` arg from `Quantize::create_tensor`
rowwise_dataprovides an option to provide an already-initialized data buffer. This was implemented to support some use-cases with attention involving QKV fusing and with the Userbuffers buffer (no longer needed after #1711). However, this design has numerous problems:dynamic_castthe quantizer to specific concrete class, so there is not much benefit in a generic API.This PR removes the
rowwise_dataarg entirely from the base class, so callingcreate_tensorwill create a tensor with pure uninitialized buffers.NoneQuantizerandFloat8Quantizerstill expose variants ofcreate_tensorfor providing pre-initialized buffers, with better recipe-specific logic.#1950 is an alternative attempt to avoid the problems of the
rowwise_dataAPI in the FP8 current-scaling quantizer. #1836 adds an optionaloutarg toQuantizer::create_tensorand will force any provided tensor to match the quantizer's usages.Closes#1836. Closes#1950.
Type of change
Changes
Quantizer::create_tensorconstruct uninitialized tensors, with some sub-class variants for constructing initialized tensorstex.quantizeforces quantized tensors to match the quantizer's usagesQuantizer::quantizeChecklist: