GB0124

Graph-Break Type

Short name describing what triggered the graph break

Unsupported Tensor.item() call with capture_scalar_outputs=False

Context

Values or code snippet captured at the break point

call_method {self} item {args} {kwargs}

Explanation

Explanation of why the graph break was triggered

Dynamo does not support tracing Tensor.item() with config.capture_scalar_outputs=False.

Hints

Hints on how to resolve the graph break

Additional Information

Example code that causes the graph break is:

def fn(x):
    return x.item()

A sample workaround around this is:

def fn(x):
    return x.item()

input_tensor = torch.tensor([42.0])

# Workaround: Use a config patch to enable the required flag
with torch._dynamo.config.patch(capture_scalar_outputs=True):
    compiled_fn = torch.compile(fn, backend="eager", fullgraph=True)
    result = compiled_fn(input_tensor)

Click here to add Additional Info

Back to Registry