Short name describing what triggered the graph break
Unsupported Tensor.item() call with capture_scalar_outputs=False
Values or code snippet captured at the break point
call_method {self} item {args} {kwargs}
Explanation of why the graph break was triggered
Dynamo does not support tracing Tensor.item() with config.capture_scalar_outputs=False.
Hints on how to resolve the graph break
torch._dynamo.config.capture_scalar_outputs = Trueexport TORCHDYNAMO_CAPTURE_SCALAR_OUTPUTS=1Example 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)