You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the current parallization strategy in the pipeline uses jax.pmap and has some limitations
Manual reshaping during pipeline -- requires reshape_data step to manually perepare data arrays with a leading dimension matching the number of devices.
Limited flexibility -- implementing more comples strategies in the future (like model parallelism) is less natural
potential optimizations -- jax.sharding integrates more deeply with the XLA compilor, with potential perfoarmce optimizations
Use PartitionSpec and NamedSharding to define how data should be distributed (sharded) or replicated across the mesh. Assuming particle data has shame (num_particles,...), we want to split data along the first axis which we named "data".
Here we need to define, which arrays are split across devices, and which arrays are copied. For example, we want to split e.g mass, metallicity, but keep e.g spatial_bin_edges, as a copy on all GPU devices.
Replace pmap calls with jax.jit and annotate the function inptuts and outputs with their respective NamedSharding specification5. Use jax.lax.psum within the jitted function for cross-device reduction (e.g summing partial datacubes)
@partial(jax.jit,#how inputs ARE sharded when the function is calledin_shardings=(particle_sharding, replicated_sharding),# Specify how the output SHOULD be shardedout_shardings=particle_sharding)defsome_function(data, param):
The Problem
the current parallization strategy in the pipeline uses
jax.pmapand has some limitationsreshape_datastep to manually perepare data arrays with a leading dimension matching the number of devices.jax.shardingintegrates more deeply with the XLA compilor, with potential perfoarmce optimizationsjit(pmap)causes issues -- pmap is called inside the pipeline, and then the final function is jitted. This causes known issues, seejit(pmap(f))causes inefficient behavior jax-ml/jax#2926Proposed Solution
Implement the parallelism using the
jax.shardingapi. For a general introduction, check the JAX documentation hereMeshrepresenting the GPU devices:We need a 1D mesh where we want to split the data across the particle axis
PartitionSpecandNamedShardingto define how data should be distributed (sharded) or replicated across the mesh. Assuming particle data has shame(num_particles,...), we want to split data along the first axis which we named "data".Here we need to define, which arrays are split across devices, and which arrays are copied. For example, we want to split e.g mass, metallicity, but keep e.g
spatial_bin_edges, as a copy on all GPU devices.this means split the data across the first dimension across the devices, but keep everything else intact. i.e f
For other components that we need to copy on all devices, this follows the following structure
We then need to define this for all the fields in the
RubixDatapytree, this could look like the following:pmapcalls withjax.jitand annotate the function inptuts and outputs with their respectiveNamedShardingspecification5. Usejax.lax.psumwithin the jitted function for cross-device reduction (e.g summing partial datacubes)reshape_datastep entirely