Repository navigation
How do we perform gradient sync in nnx for data parallel training? #5314
Replies: 1 comment
|
NNX is just a wrapper around jax that takes care of "mutable" state -- it doesn't add any gradient synchronization beyond what jax already does. Whether you need to insert an explicit pmean will depend on how you wrote your code, e.g. are you using |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Context
I'm trying to perform data parallel training where model is replicated on each device and data is sharded along the batch axis. Typically in PyTorch / Tensorflow, we have the gradient synced across the devices during the backward pass (Pytorch) or right before optimizer update (Tensorflow) via an
all_reduceop.Question
I've been looking at some examples from for both NNX and Linen, and for Linen examples, we see explicit
jax.lax.pmeancalls to sync the gradients (example).. However, for NNX, I cannot find any resource or example that explains to me where exactly gradient synchronization happens. All examples simply callvalue_and_gradand passes the gradients to the optimizer. Where and how does gradient sync exactly happen with NNX?All reactions