[Bug] Using `QuantizedTensor` on CPU causes a `RecursionError`
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 68/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Calme
- Domaine
- machine-learning
Piste de recherche
Commencez par exécuter la reproduction fournie de NVFP4Quantizer, puis suivez les chemins de dispatch et de déquantification dans pytorch/quantized_tensor.py, pytorch/tensor/nvfp4_tensor.py et pytorch/tensor/storage/nvfp4_tensor_storage.py. Le travail est terminé lorsque l’application de xq_cpu + 0 après le déplacement du tenseur quantifié vers le CPU ne lève plus de RecursionError.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
Trying to use an QuantizedTensor with certain Pytorch ops, after having moved it to cpu causes a RecursionError.
Steps/Code to reproduce bug
import torch
from transformer_engine.pytorch import NVFP4Quantizer
x = torch.randn(128, 128, device="cuda")
q = NVFP4Quantizer()
xq = q(x)
xq_cpu = xq.cpu()
xq_cpu + 0
will cause:
Traceback (most recent call last):
File "/workspace/repro.py", line 9, in <module>
xq_cpu + 0
~~~~~~~^~~
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 806, in __torch_dispatch__
return super().__torch_dispatch__(func, types, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 804, in __torch_dispatch__
args = tree_map(maybe_unwrap, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1578, in tree_map
return treespec.unflatten(map(func, *flat_args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1313, in unflatten
leaves = list(leaves)
^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 772, in maybe_unwrap
return arg.dequantize()
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 444, in dequantize
return _FromNVFP4Func.apply(self, dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/autograd/function.py", line 625, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/storage/nvfp4_tensor_storage.py", line 58, in forward
cuda_tensor = tensor.to(device=torch.device("cuda"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 806, in __torch_dispatch__
return super().__torch_dispatch__(func, types, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 804, in __torch_dispatch__
args = tree_map(maybe_unwrap, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1578, in tree_map
return treespec.unflatten(map(func, *flat_args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1313, in unflatten
leaves = list(leaves)
^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 772, in maybe_unwrap
return arg.dequantize()
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 445, in dequantize
return _FromNVFP4Func.forward(None, self, dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/storage/nvfp4_tensor_storage.py", line 58, in forward
cuda_tensor = tensor.to(device=torch.device("cuda"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 806, in __torch_dispatch__
return super().__torch_dispatch__(func, types, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 804, in __torch_dispatch__
args = tree_map(maybe_unwrap, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1578, in tree_map
return treespec.unflatten(map(func, *flat_args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1313, in unflatten
leaves = list(leaves)
^^^^^^^^^^^^
[...]
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 772, in maybe_unwrap
return arg.dequantize()
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 445, in dequantize
return _FromNVFP4Func.forward(None, self, dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/storage/nvfp4_tensor_storage.py", line 58, in forward
cuda_tensor = tensor.to(device=torch.device("cuda"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 806, in __torch_dispatch__
return super().__torch_dispatch__(func, types, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 804, in __torch_dispatch__
args = tree_map(maybe_unwrap, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1578, in tree_map
return treespec.unflatten(map(func, *flat_args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1313, in unflatten
leaves = list(leaves)
^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 772, in maybe_unwrap
return arg.dequantize()
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 445, in dequantize
return _FromNVFP4Func.forward(None, self, dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/storage/nvfp4_tensor_storage.py", line 58, in forward
cuda_tensor = tensor.to(device=torch.device("cuda"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/tensor/nvfp4_tensor.py", line 806, in __torch_dispatch__
return super().__torch_dispatch__(func, types, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/quantized_tensor.py", line 804, in __torch_dispatch__
args = tree_map(maybe_unwrap, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1576, in tree_map
leaves, treespec = tree_flatten(tree, is_leaf=is_leaf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/torch/utils/_pytree.py", line 1485, in tree_flatten
treespec = helper(tree, leaves)
^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded
I noticed this when trying to use torch.testing.assert_close on a tensor quantized with NVFP4Quantizer and a custom implementation of NVFP4 quantization.
Expected behavior
xq_cpu + 0 should not cause RecursionError.
Environment overview (please complete the following information)
- Environment location: [Docker]
- Method of Transformer Engine install: [build from source].
Environment details
Should be irrelevant.
Device details
Should be irrelevant.
Additional context
n/a.
- Langage dominant
- Python
- Étoiles
- 3.6k
- Forks
- 862
- Merge moyen
- 4 j 21 h
- PR mergées (30 j)
- 62
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de NVIDIA/TransformerEngine
-
[Bug] group_quantize_fp8_blockwise: mbarrier invalidated before other threads finish waiting on itOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
NVIDIA/TransformerEngine#3647 ·
Les mainteneurs répondent en général sous 2 jours
-
[PyTorch] fp8_cs_quantize fake implementation returns a vector inverse scale instead of a scalarPeut-être à nouveau libre @sanjana658 l’a pris il y a 8 jours, et aucune pull request n’est ouverte. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
NVIDIA/TransformerEngine#3636 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
[Bug] Backend selection picks FA3 for training with head_dim_qk=192 / v_head_dim=128, but FA3 backward cannot run itPeut-être à nouveau libre @modelpath-dev l’a pris il y a 42 jours, et aucune pull request n’est ouverte. Ouverteattention
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
NVIDIA/TransformerEngine#3481 · 4 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Increase MAX_TENSOR_NUMOuvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
NVIDIA/TransformerEngine#2189 · 7 commentaires · 5 réactions ·
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
NVIDIA/TransformerEngine#3689 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de NVIDIA/TransformerEngine
Issues similaires
-
bot-triaged module: LrScheduler module: optimizer triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
documentation glm5 llm-model
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
vllm-project/vllm-ascend#19062 ·
Les mainteneurs répondent en général sous 1 jour
-
Author Page: shuai-zhao-llmOuverteauthor-page correction
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
acl-org/acl-anthology#10496 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Issue Type: Bug Report
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
celery/celery#10875 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
SasanLabs/VulnerableApp#836 ·
Les mainteneurs répondent en général sous 1 jour