Skip to content

Fix nnx.jit and nnx.jit_partial with device or backend. - #5648

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1021080631
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1021080631

Conversation

@copybara-service

Copy link
Copy Markdown

Fix nnx.jit and nnx.jit_partial with device or backend.

jax.jit raises ValueError: If backend or device is specified on jit, then out_shardings should not be specified. whenever out_shardings is not None.
nnx.jit and nnx.jit_partial always pass a tuple of internal output
shardings to jax.jit (e.g. (out_shardings, update_shardings)), so passing
device=... or backend=... failed at decoration time even when the user did
not specify any shardings.

As suggested on the issue, only forward the internal output shardings when the
user specified in_shardings or out_shardings; otherwise pass
out_shardings=None, which is equivalent because all internal shardings are
None in that case. Calls that pass shardings are unchanged (and jax.jit
still rejects them together with device/backend).

Fixes #4774

`jax.jit` raises `ValueError: If backend or device is specified on jit, then
out_shardings should not be specified.` whenever `out_shardings` is not `None`.
`nnx.jit` and `nnx.jit_partial` always pass a tuple of internal output
shardings to `jax.jit` (e.g. `(out_shardings, update_shardings)`), so passing
`device=...` or `backend=...` failed at decoration time even when the user did
not specify any shardings.

As suggested on the issue, only forward the internal output shardings when the
user specified `in_shardings` or `out_shardings`; otherwise pass
`out_shardings=None`, which is equivalent because all internal shardings are
`None` in that case. Calls that pass shardings are unchanged (and `jax.jit`
still rejects them together with `device`/`backend`).

Fixes #4774

PiperOrigin-RevId: 1021080631

This branch has not been deployed

No deployments
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.

nnx.jit() cannot specify backend or device due to out_shardings

1 participant