Skip to content
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

enable linalg.vector_norm tests #8249

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion experimental/torch_xla2/test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"linalg.svdvals",
"linalg.tensorinv",
"linalg.tensorsolve",
"linalg.vector_norm",
"linspace",
"log_normal",
"logspace",
Expand Down
3 changes: 2 additions & 1 deletion experimental/torch_xla2/torch_xla2/ops/jaten.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,8 @@ def _aten_linalg_vector_norm(self, ord=2, dim=None, keepdim=False, dtype=None):
# Special cases (for efficiency and clarity)
if ord == 0:
if self.shape == ():
result = jnp.array(float(self != 0))
# float sets it to float64. set it back to input type
result = jnp.astype(jnp.array(float(self != 0)), self.dtype)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this the failure seen was:

FAILED test/test_ops.py::TestOpInfoCPU::test_reference_eager_linalg_vector_norm_cpu_float32 - AssertionError: The values for attribute 'dtype' do not match: torch.float64 != torch.float32.

else:
result = _with_reduction_scalar(jnp.sum, jnp.where(self != 0, 1, 0), dim, keepdim)

Expand Down
Loading