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

softshrink is expected to return nan when the input is nan on ARC #1152

Open
daisyden opened this issue Dec 9, 2024 · 0 comments
Open

softshrink is expected to return nan when the input is nan on ARC #1152

daisyden opened this issue Dec 9, 2024 · 0 comments
Assignees

Comments

@daisyden
Copy link
Contributor

daisyden commented Dec 9, 2024

🐛 Describe the bug

FAILED test_ops_xpu.py::TestCommonXPU::test_compare_cpu_nn_functional_softshrink_xpu_bfloat16 - AssertionError: Tensor-likes are not close!
FAILED test_ops_xpu.py::TestCommonXPU::test_compare_cpu_nn_functional_softshrink_xpu_float16 - AssertionError: Tensor-likes are not close!
FAILED test_ops_xpu.py::TestCommonXPU::test_compare_cpu_nn_functional_softshrink_xpu_float32 - AssertionError: Tensor-likes are not close!

When input is nan, PVC and CPU return nan while ARC returns 0. However I write a small case and it also returns nan on ARC, looks not a compiler issue. Need more investigations.

Traceback (most recent call last):
File "/root/actions-runner/_work/torch-xpu-ops/pytorch/third_party/torch-xpu-ops/test/xpu/extended/test_ops_xpu.py", line 97, in test_compare_cpu
test_common_test_fn(self.proxy, device, dtype, op)
File "/root/actions-runner/_work/torch-xpu-ops/pytorch/third_party/torch-xpu-ops/test/xpu/../../../../test/test_ops.py", line 414, in test_compare_cpu
self.assertEqual(cuda_results, cpu_results, atol=1e-3, rtol=1e-3)
File "/daisyenv/lib/python3.12/site-packages/torch/testing/_internal/common_utils.py", line 4007, in assertEqual
raise error_metas.pop()[0].to_error(
AssertionError: Tensor-likes are not close!

Mismatched elements: 3 / 9 (33.3%)
Greatest absolute difference: nan at index (6,) (up to 0.001 allowed)
Greatest relative difference: nan at index (6,) (up to 0.001 allowed)

#include "sycl/sycl.hpp"
#include <cmath>
#include <iostream>

void tanh_kernel(sycl::queue &q) {
  const size_t local_size = 1;
  const size_t global_size = 1;

  float* nan = (float*)sycl::malloc_shared(sizeof(float), q);
  float* output = (float*)sycl::malloc_shared(sizeof(float), q);
  //*nan = std::numeric_limits<float>::quiet_NaN();
  nan = std::numeric_limits<float>::signaling_NaN();
  output[0] = 555;

  auto e = q.submit([&](sycl::handler& h) {
  sycl::ext::oneapi::experimental::printf(
             "on host: result: %.16f\n",
             *nan);

  h.parallel_for(
      sycl::nd_range<1>{global_size, local_size},
      [=](sycl::nd_item<1> it) {
      output[0] = std::isnan(nan[0]) ? nan[0] : 3;
  });
      });
  e.wait();
  std::cout << "device output " << nan[0] <<  " " << output[0]  << "\n";
}

int main(int argc, char * argv[]) {
  auto devs = sycl::device::get_devices(sycl::info::device_type::gpu);
  auto first = devs[1];

  sycl::device dg1(first);
  sycl::queue q(dg1, sycl::property::queue::enable_profiling());

  tanh_kernel(q);

  return 0;
}

on host: result: nan
device output nan nan

Intel(R) oneAPI DPC++/C++ Compiler 2025.0.1 (2025.0.1.20241113)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/intel/oneapi/compiler/2025.0/bin/compiler
Configuration file: /opt/intel/oneapi/compiler/2025.0/bin/compiler/../icpx.cfg
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64

Versions

pip install --pre torch==2.6.0.dev20241202+xpu torchvision==0.20.0.dev20241202+xpu torchaudio==2.5.0.dev20241202+xpu --index-url https://download.pytorch.org/whl/nightly/xpu

@daisyden daisyden self-assigned this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant