Repository navigation
Question about functional training loop documentation #5369
|
In https://flax.readthedocs.io/en/stable/guides/performance.html#functional-training-loop I see that the graphdef itself is passed through the jitted |
Replies: 1 comment
|
Yes, you can close over the outer Quick check on flax 0.12.8 / jax 0.10.2 (CPU): graphdef, state = nnx.split((model, optimizer))
jax.tree_util.tree_leaves(graphdef) # []
nnx.split((model, optimizer))[0] == graphdef # True (same hash)A jitted step taking The reason to pass it explicitly is mostly style and safety:
If your model structure never changes, closing over it is fine. |
Yes, you can close over the outer
graphdef, and in practice the two are equivalent. Passing it as an argument costs nothing at runtime becauseGraphDefcontains no arrays: it is registered withjax.tree_util.register_static. Forjax.jitit is a pytree with zero leaves, so it ends up in the static part of the cache key (compared by==/__hash__), like astatic_argnumsargument, and never becomes a tracer or a device buffer.Quick check on flax 0.12.8 / jax 0.10.2 (CPU):
A jitted step taking
graphdefas an argument and one closing …