Skip to content

Commit 5599c15

Browse files
shino16crcrpar
andauthored
Translate shape for fd.ops.full (#2763)
Co-authored-by: Masato Shinokawa <[email protected]> Co-authored-by: crcrpar <[email protected]>
1 parent 879f8bf commit 5599c15

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

thunder/executors/nvfuserex_impl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,13 @@ def full(
10431043
fd: FusionDefinition,
10441044
lc_to_nv_map: dict,
10451045
) -> Any:
1046+
nv_shape = getnv(shape, fd, lc_to_nv_map, inline_number=True)
10461047
nv_fill_value = getnv(fill_value, fd, lc_to_nv_map)
10471048
nvdtype = lcdtype_to_nvdtype(dtype)
10481049

10491050
_select_device(fd, device)
10501051

1051-
return fd.ops.full(shape, nv_fill_value, nvdtype)
1052+
return fd.ops.full(nv_shape, nv_fill_value, nvdtype)
10521053

10531054

10541055
register_supported(PrimIDs.FULL, full, _full_check)

thunder/tests/test_nvfuser.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,27 @@ def embedding_fn(inputs):
942942
torch.testing.assert_close(out, expected_out)
943943

944944

945+
@instantiate(
946+
executors=(nvFuserExecutor,),
947+
dtypes=NOTHING,
948+
)
949+
def test_full_symbolic_values(executor, device: str, dtype: dtypes.dtype):
950+
def foo(a):
951+
# TODO: 'device=device' doesn't work for "symbolic values" cache policy
952+
# See issue: https://github.com/Lightning-AI/lightning-thunder/issues/1710
953+
return torch.full(a.shape, 0, device="cuda", dtype=dtype)
954+
955+
jfoo = thunder.jit(foo, cache="symbolic values")
956+
957+
for shape in ((2, 3), (3, 2)):
958+
a = torch.randn(shape, device=device)
959+
actual = jfoo(a)
960+
expected = foo(a)
961+
torch.testing.assert_close(actual, expected)
962+
963+
assert thunder.cache_misses(jfoo) == 1
964+
965+
945966
@instantiate(
946967
executors=(nvFuserExecutor,),
947968
dtypes=NOTHING,

0 commit comments

Comments
 (0)