Skip to content

Conversation

@Silv3S
Copy link
Contributor

@Silv3S Silv3S commented Sep 17, 2025

Fixes #1943

@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 10:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the nonzero_static operation for the XPU backend, adding support for a static-sized version of the nonzero operation that fills output to a specified size. This addresses issue #1943 in the torch-xpu-ops repository.

  • Adds dispatch entries for nonzero_static and nonzero_static.out operations in the native functions YAML
  • Implements the XPU backend functions with proper input validation and size handling
  • Refactors common validation logic into a shared helper function

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
yaml/native/native_functions.yaml Adds dispatch entries for nonzero_static operations to XPU backend
src/ATen/native/xpu/Nonzero.cpp Implements nonzero_static functions and refactors common validation logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@EikanWang EikanWang left a comment

Choose a reason for hiding this comment

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

The logic looks good to me. Pls. help add test cases or list the existing test cases here as evidence that validates the logic.

@Silv3S
Copy link
Contributor Author

Silv3S commented Sep 22, 2025

There are two parametrized tests from upstream, aligned to work with XPU

  • test_unary_ufuncs_xpu.py::TestUnaryUfuncsXPU::test_nonzero_static_large_xpu
  • test_unary_ufuncs_xpu.py::TestUnaryUfuncsXPU::test_nonzero_static_xpu

Copy link
Contributor

@CuiYifeng CuiYifeng left a comment

Choose a reason for hiding this comment

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

LGTM.

@CuiYifeng CuiYifeng added this pull request to the merge queue Sep 23, 2025
Merged via the queue into intel:main with commit 0df6a62 Sep 23, 2025
25 checks passed
@Silv3S Silv3S deleted the nonzero_static_op branch September 23, 2025 09:58
mengfei25 pushed a commit that referenced this pull request Sep 24, 2025
mengfei25 added a commit that referenced this pull request Sep 24, 2025
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

Successfully merging this pull request may close these issues.

Implement aten::nonzero_static on XPU backend

3 participants