Skip to content

Commit 6f73e06

Browse files
Guilherme Leobaspytorchmergebot
authored andcommitted
[iter] exhaust ListIterator when unpack_var_sequence is called (pytorch#156370)
Pull Request resolved: pytorch#156370 Approved by: https://github.com/zou3519 ghstack dependencies: pytorch#156369
1 parent acffd1a commit 6f73e06

6 files changed

+6
-1
lines changed

test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_dict

Whitespace-only changes.

test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_list

Whitespace-only changes.

test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_range

Whitespace-only changes.

test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_string

Whitespace-only changes.

test/dynamo_expected_failures/CPython313-test_iter-TestCase.test_sinkstate_tuple

Whitespace-only changes.

torch/_dynamo/variables/lists.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,13 @@ def as_python_constant(self):
12791279
raise NotImplementedError
12801280
return iter([x.as_python_constant() for x in self.items])
12811281

1282+
def has_unpack_var_sequence(self, tx):
1283+
return True
1284+
12821285
def unpack_var_sequence(self, tx):
1283-
return list(self.items[self.index :])
1286+
r = list(self.items[self.index :])
1287+
self.index = len(self.items)
1288+
return r
12841289

12851290
def force_unpack_var_sequence(self, tx) -> list[VariableTracker]:
12861291
return self.unpack_var_sequence(tx)

0 commit comments

Comments
 (0)