10000 removed zero dim cpu logic from fake_tensor.py by zero000064 · Pull Request #147501 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

removed zero dim cpu logic from fake_tensor.py #147501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 78 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7ca0551
modified device check logic and added tests
zero000064 Feb 20, 2025
b062a41
added tests and code generation
zero000064 Feb 20, 2025
1fc864d
Revert "added tests and code generation"
zero000064 Mar 19, 2025
c5a1e88
added tests and code generation
zero000064 Feb 20, 2025
15c6c3e
Revert "modified device check logic and added tests"
zero000064 Mar 19, 2025
11f4129
reverted the code generation change
zero000064 Mar 19, 2025
53130b7
removed zero dim cpu tensor logic from fake_tensor.py
zero000064 Mar 21, 2025
4359566
updated test_throw
zero000064 Mar 21, 2025
047729e
added test cases and deleted test cases
zero000064 Mar 23, 2025
b25e3eb
fixed linting issues.
zero000064 Mar 24, 2025
c33c556
Revert "removed zero dim cpu tensor logic from fake_tensor.py"
zero000064 Mar 28, 2025
07c98e2
modified device check logic and added tests
zero000064 Feb 20, 2025
6bd3f12
added tests and code generation
zero000064 Feb 20, 2025
ef97ddb
Revert "added tests and code generation"
zero000064 Mar 19, 2025
c6be930
added tests and code generation
zero000064 Feb 20, 2025
6605988
Revert "modified device check logic and added tests"
zero000064 Mar 19, 2025
6415599
reverted the code generation change
zero000064 Mar 19, 2025
be8bc51
removed zero dim cpu tensor logic from fake_tensor.py
zero000064 Mar 21, 2025
c69cdec
added test cases and deleted test cases
zero000064 Mar 23, 2025
ce1b160
fixed linting issues.
zero000064 Mar 24, 2025
97c4f9f
added test cases and deleted test cases
zero000064 Mar 23, 2025
c6805c0
fixed linting issues.
zero000064 Mar 24, 2025
4918050
Revert "removed zero dim cpu tensor logic from fake_tensor.py"
zero000064 Mar 28, 2025
166caa7
fixed the code after rebase
zero000064 Mar 28, 2025
ec6140f
fixed linting issues.
zero000064 Mar 30, 2025
8573f03
fixed setitem issue.
zero000064 Mar 30, 2025
2007459
fixed torch.where issues.
zero000064 Mar 30, 2025
a71ca19
fexed test_throw failure by using a more generic Exception for the re…
zero000064 Apr 6, 2025
14aeb52
fixed test failures
zero000064 Apr 6, 2025
5a5eca2
fixed bernoulli1 and bernoulli2 tests
zero000064 Apr 6, 2025
061cbc3
modified device check logic and added tests
zero000064 Feb 20, 2025
617e5bd
added tests and code generation
zero000064 Feb 20, 2025
af5ea2e
Revert "added tests and code generation"
zero000064 Mar 19, 2025
8b206a8
added tests and code generation
zero000064 Feb 20, 2025
bae5138
Revert "modified device check logic and added tests"
zero000064 Mar 19, 2025
1f842ed
reverted the code generation change
zero000064 Mar 19, 2025
5fe1c4b
removed zero dim cpu tensor logic from fake_tensor.py
zero000064 Mar 21, 2025
f4a84fc
updated test_throw
zero000064 Mar 21, 2025
6a819e1
added test cases and deleted test cases
zero000064 Mar 23, 2025
71fdbbf
fixed linting issues.
zero000064 Mar 24, 2025
d2a3076
Revert "removed zero dim cpu tensor logic from fake_tensor.py"
zero000064 Mar 28, 2025
a77ce55
modified device check logic and added tests
zero000064 Feb 20, 2025
7714f38
added tests and code generation
zero000064 Feb 20, 2025
45bd3b9
Revert "added tests and code generation"
zero000064 Mar 19, 2025
6961969
added tests and code generation
zero000064 Feb 20, 2025
813c54c
Revert "modified device check logic and added tests"
zero000064 Mar 19, 2025
4f7bbf6
reverted the code generation change
zero000064 Mar 19, 2025
575a4be
removed zero dim cpu tensor logic from fake_tensor.py
zero000064 Mar 21, 2025
86773f4
added test cases and deleted test cases
zero000064 Mar 23, 2025
6340b07
fixed linting issues.
zero000064 Mar 24, 2025
90de13c
added test cases and deleted test cases
zero000064 Mar 23, 2025
d24a4fd
fixed linting issues.
zero000064 Mar 24, 2025
cef6fe7
Revert "removed zero dim cpu tensor logic from fake_tensor.py"
8000 zero000064 Mar 28, 2025
58e97f2
fixed the code after rebase
zero000064 Mar 28, 2025
bbbeec9
fixed linting issues.
zero000064 Mar 30, 2025
8d3ffaa
fixed setitem issue.
zero000064 Mar 30, 2025
2eb3644
fixed torch.where issues.
zero000064 Mar 30, 2025
26dc436
fexed test_throw failure by using a more generic Exception for the re…
zero000064 Apr 6, 2025
b4065a8
fixed test failures
zero000064 Apr 6, 2025
97001e1
fixed bernoulli1 and bernoulli2 tests
zero000064 Apr 6, 2025
cda869e
Merge branch 'fake_tensor' of https://github.com/zero000064/pytorch i…
zero000064 Apr 15, 2025
2909945
fix add and sub failures
zero000064 Apr 15, 2025
a0b67ba
fixed failures
zero000064 Apr 15, 2025
73da9df
fixed fmin failures
zero000064 Apr 15, 2025
54feb2d
fixed test_throw_in_zero_dim_cpu_tensor failure
zero000064 Apr 16, 2025
34ea43d
fixed real tensor propagation error for test_throw_in_zero_dim_cpu_te…
zero000064 Apr 18, 2025
51eb79e
fixed failures from iteration version of arithmetic operations.
zero000064 Apr 19, 2025
fac7686
fixed test_out_multi_device failures
zero000064 Apr 25, 2025
b653170
Merge branch 'pytorch:main' into fake_tensor
zero000064 Apr 29, 2025
51a5e89
reverted code changes
zero000064 May 1, 2025
8f293b8
added the bypass logic for zero dim cpu tensor
zero000064 May 8, 2025
f799603
fixed lint issues
zero000064 May 8, 2025
28f7a88
Merge branch 'pytorch:main' into fake_tensor
zero000064 May 15, 2025
2b1915d
Merge branch 'pytorch:main' into fake_tensor
zero000064 May 23, 2025
3412a85
Merge branch 'pytorch:main' into fake_tensor
zero000064 Jul 2, 2025
0280dfd
Merge branch 'pytorch:main' into fake_tensor
zero000064 Jul 14, 2025
71a5249
fixed lint issue
zero000064 Jul 17, 2025
bc95749
Merge branch 'pytorch:main' into fake_tensor
zero000064 Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/test_fake_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ def test_zero_dim(self):
self.assertEqual(out.device, y.device)
self.assertTrue(isinstance(out, FakeTensor))

@unittest.skipIf(not RUN_CUDA, "requires cuda")
def test_op_with_zero_dim_bypassed(self):
if torch._functorch.config.fake_tensor_propagate_real_tensors:
return
shape_env = ShapeEnv()
mode = FakeTensorMode(shape_env=shape_env)
x = torch.tensor(1.0, device="cuda")
y = torch.tensor(2.0)
fake_x = mode.from_tensor(x)
fake_y = mode.from_tensor(y)

with self.assertRaisesRegex(
RuntimeError, "Unhandled FakeTensor Device Propagation for.*"
) as exc:
torch.nextafter(fake_x, fake_y)

def test_nan_to_num(self):
with FakeTensorMode():
for dtype in [torch.float16, torch.float32]:
Expand Down
13 changes: 11 additions & 2 deletions torch/_subclasses/fake_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ def _find_common_device(
aten._foreach_copy.default,
)

# list of ops not using zero dim cpu tensor logic to align with the eager mode.
bypass_zero_dim_cpu_tensor_check_ops = ordered_set(
aten.nextafter.default,
)

def check_cpu_device(device: torch.device) -> bool:
return device.type == "cpu"

Expand All @@ -912,13 +917,17 @@ def merge_devices(t: object) -> None:
is_cpu_zero_dim = t_is_cpu_zero_dim
return

is_bypass_zero_dim_cpu_tensor_check_op = (
func in bypass_zero_dim_cpu_tensor_check_ops
)

# mismatching devices !
# if current tensor is cpu 0 dim, defer to existing device
if t_is_cpu_zero_dim:
if t_is_cpu_zero_dim and not is_bypass_zero_dim_cpu_tensor_check_op:
return

# current device is from cpu 0 dim tensor, overwrite
if is_cpu_zero_dim:
if is_cpu_zero_dim and not is_bypass_zero_dim_cpu_tensor_check_op:
common_device = t.device
is_cpu_zero_dim = t_is_cpu_zero_dim
return
Expand Down
Loading
0