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

NaN related ops are not correct for burn-wgpu fusion backend #2089

Open
antimora opened this issue Aug 1, 2024 · 1 comment
Open

NaN related ops are not correct for burn-wgpu fusion backend #2089

antimora opened this issue Aug 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@antimora
Copy link
Collaborator

antimora commented Aug 1, 2024

I am adding two new tensor methods related to NaN (is_nan and contains_nan). My unit tests are failing for burn-wgpu backend. See #2088 PR

Describe the bug
These two methods do not work as expected:

    /// Returns a new tensor with boolean elements indicating whether each element of the input is NaN.
    ///
    /// # Returns
    ///
    /// A boolean tensor where `true` indicates NaN and `false` indicates a non-NaN value.
    pub fn is_nan(&self) -> Tensor<B, D, Bool> {
        // Check if the input tensor is NaN by comparing it to itself
        // NaN is the only value that is not equal to itself
        K::not_equal(self.primitive.clone(), self.primitive.clone())
    }

    /// Checks if the tensor contains any NaN values.
    ///
    /// # Returns
    ///
    /// A boolean tensor with a single element indicating whether the tensor contains any NaN values.
    pub fn contains_nan(&self) -> Tensor<B, 1, Bool> {
        // Summing the tensor will result in NaN if the tensor contains any NaN values
        // This is faster than checking each element individually
        // because it rolls up the NaN values into a single value
        let sum = K::sum(self.primitive.clone());

        // Check if the sum is NaN by comparing it to itself
        K::not_equal(sum.clone(), sum)
    }

To Reproduce

  1. check out this PR branch: Add is_nan and contains_nan tensor ops #2088 PR
  2. cd burn-wgpu
  3. cargo test nan

Expected behavior
The tests should pass.

Screenshots
image

NOTE: The unit test should be enabled currently ignored for all backends.

@antimora antimora added the bug Something isn't working label Aug 3, 2024
@antimora antimora changed the title NaN related ops are not correct for burn-wgpu backend NaN related ops are not correct for burn-wgpu fusion backend Aug 3, 2024
@antimora
Copy link
Collaborator Author

antimora commented Aug 3, 2024

@nathanielsimard @louisfd, this is only for fusion backend. Any particular difference?

antimora added a commit to antimora/burn that referenced this issue Aug 5, 2024
antimora added a commit that referenced this issue Aug 6, 2024
* Add is_nan and contains_nan tensor ops

* Enable nan test for burn-candle

* Disabling tests due to #2089
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant