Skip to content

fix: Pass rtol and atol of Nx.all_close/3 to mx::allclose in their order - #162

Open
georgeguimaraes wants to merge 1 commit into
elixir-nx:mainfrom
georgeguimaraes:fix/allclose-rtol-atol
Open

georgeguimaraes wants to merge 1 commit into
elixir-nx:mainfrom
georgeguimaraes:fix/allclose-rtol-atol

Conversation

@georgeguimaraes

Copy link
Copy Markdown
Member

The eager Nx.Block.AllClose block of EMLX.Backend passed atol as rtol and rtol as atol to EMLX.allclose/5. So it tested |a - b| <= rtol + atol * |b|, and for large values Nx.all_close/3 said that close tensors were not close. For example, 1000.0 and 1000.005 are within the default rtol of 1.0e-5, but the block returned 0.

This change passes the two values in their order. The swap also hid a second problem: mx::allclose takes abs(b) in the type of b, which overflows at the smallest signed integer. The s8 doctest of Nx.all_close/3 fails after the swap fix because of this overflow. Two integer tensors now go to the default function, which widens them before abs, as Nx does.

The new test checks the eager and the compiled path. It fails without the fix.

The eager AllClose block passed atol as rtol and rtol as atol, so it tested |a - b| <= rtol + atol * |b|. For large values it said that close tensors were not close. It now passes rtol and atol in the order of EMLX.allclose/5.

mx::allclose takes abs(b) in the type of b, which overflows at the smallest signed integer. The swap hid this case in the doctest of Nx.all_close/3 with s8 values. Two integer tensors now go to the default function, which widens them first, as Nx does.
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.

1 participant