Skip to content

Fix false data dependency error in nn.scan with effectful bodies - #5661

Open
vineethsaivs wants to merge 1 commit into
google:mainfrom
vineethsaivs:fix/scan-effects-false-dependency
Open

vineethsaivs wants to merge 1 commit into
google:mainfrom
vineethsaivs:fix/scan-effects-false-dependency

Conversation

@vineethsaivs

Copy link
Copy Markdown

What does this PR do?

nn.scan, nn.RNN and nn.remat_scan raise a false ValueError: broadcasted variable has a data dependency on the scan body. in flax 0.12.9 to 0.12.12 when the body has an effectful op that reads the carry or xs: jax.debug.print, jax.debug.callback, checkify.check, or an nn.remat body. It also fires with variable_axes={'params': 0}, and RNN and remat_scan have no check_constancy_invariants to switch off.

Since #5540 the init-mode check DCEs the traced body, and DCE always keeps effectful equations, so the carry looks used. This erases observer effects (debug, checkify, io_callback) before that DCE. Ref effects are kept, and a broadcast param that really reads the carry still raises.

Tests: 6 of the 8 new cases fail on main and all pass here. linen_transforms_test.py and core_scan_test.py pass (jax 0.11.2, CPU).

Fixes # (issue)

No issue filed.

Checklist

  • This PR fixes a minor issue (e.g.: typo or small bug) or improves the docs (you can dismiss the other checks if that's the case).
  • This change is discussed in a Github issue/discussion (please add a link).
  • The documentation and docstrings adhere to the documentation guidelines.
  • This change includes necessary high-coverage tests. (No quality testing = no merge!)

Since google#5540, the init-mode check in axes_scan DCEs the traced body to find
out whether the broadcast outputs read the carry or xs. JAX DCE keeps every
effectful equation, so jax.debug.print, jax.debug.callback, io_callback and
checkify.check on the carry (also inside nn.remat) raised
"broadcasted variable has a data dependency on the scan body", even with no
broadcast variables.

Erase observer effects before the DCE so that only real data dependencies
count. Ref effects are kept.

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.

1 participant