Skip to content

Conversation

@dxqb
Copy link

@dxqb dxqb commented Oct 29, 2025

torch.compile fails to trace

s = { ... }
if x in s:

it can trace lists

Who can review?

@Isotr0py

torch.compile fails to trace
```
s = { ... }
if x in s:
```

it can trace lists
UNQUANTIZED_TYPES = {gguf.GGMLQuantizationType.F32, gguf.GGMLQuantizationType.F16, gguf.GGMLQuantizationType.BF16}
STANDARD_QUANT_TYPES = {
UNQUANTIZED_TYPES = [gguf.GGMLQuantizationType.F32, gguf.GGMLQuantizationType.F16, gguf.GGMLQuantizationType.BF16]
STANDARD_QUANT_TYPES = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

we use set operations on them like here

DEQUANT_TYPES = STANDARD_QUANT_TYPES | KQUANT_TYPES | IMATRIX_QUANT_TYPES

would this work?

Copy link
Author

@dxqb dxqb Oct 30, 2025

Choose a reason for hiding this comment

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

you are right, this would not work and another solution is required

@yiyixuxu
Copy link
Collaborator

thanks for the PR! could you provide a testing script?

@dxqb
Copy link
Author

dxqb commented Oct 30, 2025

thanks for the PR! could you provide a testing script?

import torch
import gguf

UNQUANTIZED_TYPES = {gguf.GGMLQuantizationType.F32, gguf.GGMLQuantizationType.F16, gguf.GGMLQuantizationType.BF16}

def f(x):
    if x in UNQUANTIZED_TYPES:
        pass

f_compiled = torch.compile(f, fullgraph=True)
f_compiled(gguf.GGMLQuantizationType.F32)

torch._dynamo.exc.Unsupported: Unsupported method call
  Explanation: Dynamo does not know how to trace method `__contains__` of class `set`
  Hint: Avoid calling `set.__contains__` in your code.

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