GB0156

Graph-Break Type

Short name describing what triggered the graph break

Unsupported method call

Context

Values or code snippet captured at the break point

call_method {self} {name} {args} {kwargs}

Explanation

Explanation of why the graph break was triggered

Dynamo does not know how to trace method {name} of class {self.python_type_name()}

Hints

Hints on how to resolve the graph break

No hints provided.

Additional Information

Example code that causes the graph break is:

def fn(it):
    return [x + 1 for x in it]
iterator = zip(range(5), range(10))
compiled_fn = torch.compile(fn, backend="eager", fullgraph=True)
compiled_fn(iterator)

A sample workaround around this is: By creating the zip iterator inside the function, torch.compile can trace its creation and usage from the start, avoiding the issue of handling an opaque iterator object passed across the compile boundary. This is often the most performant solution if you can refactor the code this way.

# Move the creation of the iterator INSIDE the function
def fn_fixed():
    iterator = zip(range(5), range(10))
    return [item[0] + item[1] for item in iterator]
compiled_fn = torch.compile(fn_fixed, backend="eager", fullgraph=True)
result = compiled_fn()

Another workaround around this is to convert the Iterator to a List beforehand as such:

def fn(it):
    return [item[0] + item[1] for item in it]
iterator = zip(range(5), range(10))

# Convert the iterator to a list before passing it to the compiled function
data_list = list(iterator)

compiled_fn = torch.compile(fn, backend="eager", fullgraph=True)
result = compiled_fn(data_list)

Click here to add Additional Info

Back to Registry