Skip to content
Discussion options

You must be logged in to vote

Yes, you can close over the outer graphdef, and in practice the two are equivalent. Passing it as an argument costs nothing at runtime because GraphDef contains no arrays: it is registered with jax.tree_util.register_static. For jax.jit it is a pytree with zero leaves, so it ends up in the static part of the cache key (compared by ==/__hash__), like a static_argnums argument, and never becomes a tracer or a device buffer.

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 graphdef as an argument and one closing …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vladfi1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants