From 32777f426bc01aee9d31b1e672aaa983ea29b793 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Wed, 19 Nov 2025 16:09:29 +0100 Subject: [PATCH 1/3] Add Tensor.is_cpu --- thunder/tests/opinfos.py | 14 ++++++++++++++ thunder/torch/__init__.py | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/thunder/tests/opinfos.py b/thunder/tests/opinfos.py index 8f603a1883..7f06d7eab8 100644 --- a/thunder/tests/opinfos.py +++ b/thunder/tests/opinfos.py @@ -555,6 +555,20 @@ def _is_cuda_torch(x: torch.Tensor) -> bool: tensor_properties.append(is_cuda_opinfo) +def _is_cpu_torch(x: torch.Tensor) -> bool: + return x.is_cpu + + +is_cpu_opinfo = OpInfo( + ltorch.is_cpu, + sample_input_generator=elementwise_unary_generator, + torch_reference=_is_cpu_torch, + dtypes=(datatypes.all_dtypes), +) + +tensor_properties.append(is_cpu_opinfo) + + def _is_nested_torch(x: torch.Tensor) -> bool: return x.is_nested diff --git a/thunder/torch/__init__.py b/thunder/torch/__init__.py index 7c828e664c..f295a2990b 100644 --- a/thunder/torch/__init__.py +++ b/thunder/torch/__init__.py @@ -333,6 +333,11 @@ def is_cuda(a: TensorLike, /) -> bool: return a.device.devicetype is devices.DeviceType.CUDA +@torchsymbol(torch.Tensor.is_cpu, is_property=True, id="torch.is_cpu") +def is_cpu(a: TensorLike, /) -> bool: + return a.device.devicetype is devices.DeviceType.CPU + + @torchsymbol(torch.polar, id="torch.polar") def polar(abs_: TensorLike, angle: TensorLike): # Decompose polar into real/imag using Thunder ops and construct complex via mapped torch.complex From 743d803409a913a8596d7db81215adcc57024e31 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:13:44 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- thunder/tests/distributed/test_fsdp.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/thunder/tests/distributed/test_fsdp.py b/thunder/tests/distributed/test_fsdp.py index 920f912210..92832d17cf 100644 --- a/thunder/tests/distributed/test_fsdp.py +++ b/thunder/tests/distributed/test_fsdp.py @@ -46,6 +46,7 @@ from transformer_engine.common.recipe import MXFP8BlockScaling import transformer_engine from thunder.tests.test_transformer_engine_executor import te_assert_close + is_fp8_supported, fp8_support_reason = check_fp8_support() from thunder.tests.distributed.helper import ( @@ -1159,8 +1160,12 @@ def forward(self, x): shard_size = int(dim / world_size) fsdp_te_params = tuple(te_model.parameters()) try: - te_assert_close(jit_model.get_parameter("fc1.weight"), fsdp_te_params[0].view(shard_size, dim), te_recipe=fp8_recipe) - te_assert_close(jit_model.get_parameter("fc2.weight"), fsdp_te_params[1].view(shard_size, dim), te_recipe=fp8_recipe) + te_assert_close( + jit_model.get_parameter("fc1.weight"), fsdp_te_params[0].view(shard_size, dim), te_recipe=fp8_recipe + ) + te_assert_close( + jit_model.get_parameter("fc2.weight"), fsdp_te_params[1].view(shard_size, dim), te_recipe=fp8_recipe + ) except Exception as e: # Return exceptions only for rank==0 if rank == 0: From dc081c6a12f6d460cf62e3e77d9124dab9025860 Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Thu, 20 Nov 2025 16:22:17 +0100 Subject: [PATCH 3/3] fix review comment --- thunder/torch/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thunder/torch/__init__.py b/thunder/torch/__init__.py index f295a2990b..090f46643e 100644 --- a/thunder/torch/__init__.py +++ b/thunder/torch/__init__.py @@ -333,11 +333,14 @@ def is_cuda(a: TensorLike, /) -> bool: return a.device.devicetype is devices.DeviceType.CUDA -@torchsymbol(torch.Tensor.is_cpu, is_property=True, id="torch.is_cpu") +@torchsymbol(torch.Tensor.is_cpu, is_property=True, id="torch.Tensor.is_cpu") def is_cpu(a: TensorLike, /) -> bool: return a.device.devicetype is devices.DeviceType.CPU +register_method("is_cpu", is_cpu) + + @torchsymbol(torch.polar, id="torch.polar") def polar(abs_: TensorLike, angle: TensorLike): # Decompose polar into real/imag using Thunder ops and construct complex via mapped torch.complex