Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The internal torchao tensor subclasses cause errors with torch.compile #1463

Open
JohnnyRacer opened this issue Dec 28, 2024 · 5 comments
Open
Labels
bug Something isn't working

Comments

@JohnnyRacer
Copy link

When I use torch.compile with certain models that cause the following error:

BackendCompilerFailed: backend='inductor' raised:
AssertionError: torch.compile is currently being used with tensor subclass inputs:
<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torchao.quantization.linear_activation_quantized_tensor.LinearActivationQuantizedTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torchao.quantization.linear_activation_quantized_tensor.LinearActivationQuantizedTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>,<class 'torch._subclasses.fake_tensor.FakeTensor'>. We are attempting to a compile a graph with two graph outputs
that alias one another, which is currently unsupported in the subclass use case. If you run into this,
please file a github issue

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information

LinearActivationQuantizedTensor and FakeTensor which are tensor subclasses are not supported by torch.compile which raises the errors.

The model compiles correct if the errors are suppressed with the following:

import torch._dynamo
torch._dynamo.config.suppress_errors = True
@supriyar
Copy link
Contributor

cc @jerryzh168 @drisspg

@drisspg
Copy link
Contributor

drisspg commented Dec 30, 2024

Do you have a repro?
I added some code a while a go to make sure that the compile specific subclasses work with FP8 tensor that probably needs to be reproduced:

def allowed_subclasses(type):

I have often found this is indicative a graph break though somewhere un expected.

@supriyar supriyar added the bug Something isn't working label Jan 6, 2025
@jerryzh168
Copy link
Contributor

please provide a repro, also what is the version of pytorch you are using? can you run pip show torch and paste the result

@JohnnyRacer
Copy link
Author

I can't share my repro directly as the codebase for the model that this happens with is large and complicated (no clue on where it is having problems with torchao). I can't seem to reproduce it with small toy models, as it seems to occur only before Triton begins to compile the kernels in the back. The tensor classes seem to have something to do with testing the quantization optimizations being performed on the model with Triton. I will try to narrow down the modules that are problematic and give a repro if possible.
torchao version : 0.7.0
torch version: 2.5.0a0+b465a5843b.nv24.9 # From Docker NGC PyTorch 24.9 image

@jerryzh168
Copy link
Contributor

jerryzh168 commented Jan 9, 2025

no problem, could you try upgrade pytorch to most recent version to see if it is fixed? since there could be tensor subclass + compile issues that's fixed recently:

pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants