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

Max_to cuda kernel bug with negative zero #379

Closed
ViliamVadocz opened this issue Jan 18, 2023 · 0 comments · Fixed by #380
Closed

Max_to cuda kernel bug with negative zero #379

ViliamVadocz opened this issue Jan 18, 2023 · 0 comments · Fixed by #380

Comments

@ViliamVadocz
Copy link
Contributor

ViliamVadocz commented Jan 18, 2023

Code added in #370 contains a bug to do with negative zero.

Test case:

#[test]
fn test_max_negative_zero() {
    let dev: TestDevice = Default::default();
    let t = dev.tensor([[-0.0, 0.0], [0.0, -0.0], [-0.0, -1.0], [0.0, -1.0]]);
    let r = t.trace().max::<_, Axis<1>>();
    assert_eq!(r.array(), [0.0, 0.0, -0.0, 0.0]);
    let g = r.sum().backward();
    assert_eq!(
        g.get(&t).array(),
        [[1.0, 1.0], [1.0, 1.0], [1.0, 0.0], [1.0, 0.0]]
    );
}

This test passes on cpu, but with the test-cuda feature it gives this failure:

---- tensor_ops::max_to::tests::test_max_negative_zero stdout ----
thread 'tensor_ops::max_to::tests::test_max_negative_zero' panicked at 'assertion failed: `(left == right)`
  left: `[0.0, 0.0, -1.0, 0.0]`,
 right: `[0.0, 0.0, -0.0, 0.0]`', src\tensor_ops\max_to\mod.rs:144:9

This bug was mentioned in the StackOverflow page from which the code for the kernel was taken, along with a suggested fix: https://stackoverflow.com/a/72461459/10514840

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 a pull request may close this issue.

1 participant