mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Avoids calling builtin iter
if object is a generator (#162521)
The `iter(gen)` call will return the given `gen` object. So, we just avoid this call and shaves off a few ms of tracing time Pull Request resolved: https://github.com/pytorch/pytorch/pull/162521 Approved by: https://github.com/mlazos
This commit is contained in:
committed by
PyTorch MergeBot
parent
83cbba8759
commit
4e420415e8
@ -1831,6 +1831,8 @@ class BuiltinVariable(VariableTracker):
|
||||
ret = obj
|
||||
elif isinstance(obj, variables.RangeVariable):
|
||||
ret = obj.call_method(tx, "__iter__", [], {})
|
||||
elif isinstance(obj, variables.LocalGeneratorObjectVariable):
|
||||
ret = obj # type: ignore[assignment]
|
||||
else:
|
||||
# Handle the case where we are iterating over a tuple, list or iterator
|
||||
ret = self._call_iter_tuple_list(tx, obj, *args, **kwargs)
|
||||
|
Reference in New Issue
Block a user