Skip to content

Commit

Permalink
Drop dynamo-specific type hints on Tensor in favor of type-ignores (#…
Browse files Browse the repository at this point in the history
…113720)

Summary:
Per [this][1] discussion, plus some offline discussion. The summary:
albanD considers the core PyTorch types like Tensor to be extremely
brittle, and does not think the risk of adding these typed attributes to
be worth it.

eellison mentioned that we could use `WeakTensorKeyDictionary` instead.
However, based on the sparse usage of these bonus attributes, I think
that would be overkill. So I've opted to go with a few more type-ignore
comments instead.

[1]: pytorch/pytorch#113610 (comment)

X-link: pytorch/pytorch#113720
Approved by: https://github.com/ezyang, https://github.com/albanD, https://github.com/eellison
ghstack dependencies: #113534, #113610

Reviewed By: huydhn

Differential Revision: D51383035

Pulled By: int3

fbshipit-source-id: 31f2dc3e56986728c5a7cb69df59dceac6e6551b
  • Loading branch information
int3 authored and facebook-github-bot committed Nov 16, 2023
1 parent fa41cb2 commit 361a775
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def torch_clone(x):
if x.is_leaf and x.grad is not None:
y.grad = clone_input(x.grad, dtype=dtype)
if hasattr(x, "_dynamo_dynamic_indices"):
y._dynamo_dynamic_indices = x._dynamo_dynamic_indices.copy()
y._dynamo_dynamic_indices = x._dynamo_dynamic_indices.copy() # type: ignore[attr-defined]
return y

with torch.no_grad():
Expand Down Expand Up @@ -669,7 +669,7 @@ def torch_clone(x):
# performing the operation.
return torch_clone(x)
if hasattr(x, "_dynamo_dynamic_indices"):
result._dynamo_dynamic_indices = x._dynamo_dynamic_indices.copy()
result._dynamo_dynamic_indices = x._dynamo_dynamic_indices.copy() # type: ignore[attr-defined]
return result


Expand Down

0 comments on commit 361a775

Please sign in to comment.