Skip to content

Commit

Permalink
fix set item in tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
superDong1998 committed Mar 13, 2024
1 parent 79def73 commit 9362a1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion frontend/guard_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ def get_common_device(arg: Any) -> None:

def as_fx_node(arg: Any) -> NodeArgs:
if isinstance(arg, (tuple, list)):
return fx_immutable.immutable_list([as_fx_node(x) for x in arg])
if isinstance(arg, list):
return fx_immutable.immutable_list(
[as_fx_node(x) for x in arg])
else:
return tuple(
fx_immutable.immutable_list(
[as_fx_node(x) for x in arg]))
if isinstance(arg, slice):
return slice(as_fx_node(arg.start), as_fx_node(arg.stop),
as_fx_node(arg.step))
Expand Down Expand Up @@ -1735,6 +1741,12 @@ def set_if_inplace_return() -> None:
"__name__") and func.__name__ in ("flatten_parameters",
"numel", "children"):
return
if hasattr(func, "__module__"
) and func.__module__ == 'torch.autograd.profiler':
return
elif hasattr(func, "__self__") and isinstance(
func.__self__, torch.autograd.profiler.record_function):
return
print("record function in graph", func)
self.state.record_function(
func,
Expand Down
17 changes: 17 additions & 0 deletions test/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,20 @@ def test_no_grad(caplog):
compiled = compile(run_no_grad)
run_and_check(compiled, [MISS], 1, caplog, expect, inp)
run_and_check(compiled, [HIT], 1, caplog, expect, inp)


def tensor_set_item(x):
length = x.shape[0]
for i in range(length):
x[i, i, i] = 1.0
return x


def test_tensor_set_item(caplog):
reset()
with torch.no_grad():
input = torch.rand([4, 4, 4, 4])
expect = tensor_set_item(input)
compiled = compile(tensor_set_item)
run_and_check(compiled, [MISS], 1, caplog, expect, input)
run_and_check(compiled, [HIT], 1, caplog, expect, input)

0 comments on commit 9362a1f

Please sign in to comment.