Skip to content

Commit

Permalink
[export] avoid debug name crash for dim hints (pytorch#139104)
Browse files Browse the repository at this point in the history
Fixes #ISSUE_NUMBER

Pull Request resolved: pytorch#139104
Approved by: https://github.com/ezyang
  • Loading branch information
pianpwk authored and pytorchmergebot committed Oct 30, 2024
1 parent 7765d1e commit 180d283
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/export/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3128,6 +3128,21 @@ def forward(self, image, crop_height, crop_width):
args = (torch.rand(3, 700, 700), 150, 150)
self.assertEqual(ecrop.module()(*args), ecrop(*args))

def test_dim_dynamic_divisibility(self):
class M(torch.nn.Module):
def forward(self, x):
if x.size(0) % 2 == 0:
return x.clone() * 2
else:
return x.clone() * 0

input1 = (torch.randn(4),)
model = M()
dynamic_shapes = {
"x": {0: torch.export.Dim.DYNAMIC},
}
export(model, input1, dynamic_shapes=dynamic_shapes)

def test_export_func_with_kwargs(self):
class Module(torch.nn.Module):
def forward(self, arg1, arg2, kw1, kw2):
Expand Down
7 changes: 6 additions & 1 deletion torch/fx/experimental/symbolic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,12 @@ def solve(self) -> None:
):
if self._is_supported_congruence(congruence):
base, divisor = congruence.args
tmp_name = f"_{self._dcp.source_name_to_debug_name[self._dcp.symbol_to_source[s][0].name()]}"
tmp_name = "_" + str(
self._dcp.source_name_to_debug_name.get(
self._dcp.symbol_to_source[s][0].name(),
self._dcp.symbol_to_source[s][0].name(),
)
)
tmp = sympy.Symbol(tmp_name, integer=True)
from torch._dynamo.source import ConstantSource

Expand Down

0 comments on commit 180d283

Please sign in to comment.