-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[callback] Allow external callbacks to return 64-bit values in 32-bit…
… mode Previously, prior to #20433, if the Python callback returned a Python literal (which is natively a 64-bit value), and the `result_shape_dtypes` specified a 32-bit expected returned value, we would just get garbage results. In #20433, I introduced an error in this situation. However, when trying to port the internal code that uses host_callback to `io_callback`, I am getting many instances of this error. The common scenario is a Python callback function that returns a Python scalar: ``` def f_host(): return 42. io_callback(f_host, jax.ShapeDtypeStruct((), np.float32)) ``` However, if the `f_host` were called directly JAX would canonicalize the value `42.` to a float32 (when `jax_enable_x64` is not set). I do not think that it makes sense for `io_callback` to have stricter behaviour that a direct call. In this PR we add a canonicalization step on the returned values of Python callbacks, which would cast the values to 32-bits. In some sense this is replacing the change in #20433 to add a canonicalization step instead of an error.
- Loading branch information
Showing
3 changed files
with
14 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters