physicsnemo icon indicating copy to clipboard operation
physicsnemo copied to clipboard

🚀[FEA]: Clarify DDP dataset memory behavior and recommend lazy loading for large Zarr datasets

Open gncurtosi opened this issue 7 months ago • 4 comments

Is this a new feature, an improvement, or a change to existing functionality?

Improvement

How would you describe the priority of this feature request

Medium

Please provide a clear description of problem you would like to solve.

I want to report a DDP memory behavior that we validated and solved in practice.

Root cause:

  • In multi-GPU DDP, DistributedSampler correctly shards sample indices across ranks.
  • However, each rank/process still instantiates its own dataset object.
  • In the crash data path, eager loading materializes large Zarr arrays during dataset construction.
  • With 8 GPUs (8 ranks), this effectively multiplies host RAM usage by rank count and can lead to OOM/SIGKILL.

Key point:

  • The problem is not DistributedSampler itself.
  • The expensive part is eager dataset/reader initialization in CPU RAM.

Validated solution:

  • Switching to lazy loading (on-demand reads during iteration) reduced CPU RAM significantly.
  • After this change, distributed training became stable and scalable.

Request for PhysicsNeMo:

  1. Explicitly document in the crash/DDP example that DistributedSampler shards indices only, not dataset memory.
  2. Recommend lazy loading for large Zarr datasets in multi-GPU runs.
  3. Optionally add guidance for rank-aware early sharding of files/runs to reduce duplicate work across ranks.

Relevant paths in repo:

  • examples/structural_mechanics/crash/train.py
  • examples/structural_mechanics/crash/datapipe.py
  • examples/structural_mechanics/crash/zarr_reader.py

Describe any alternatives you have considered

  • Lowering nproc_per_node: reduces memory pressure but also reduces throughput.
  • Setting num_workers=0: helps worker overhead but does not remove rank-level dataset duplication.
  • Keeping eager loading: still causes high RAM in multi-GPU DDP.
  • Lazy loading: this is the solution that worked in our tests.

gncurtosi avatar Apr 03 '26 22:04 gncurtosi

@gncurtosi Thank you for the suggestion. It would be great if you wanted to contribute this enhancement. @coreyjadams can you guide @gncurtosi on this enhancement.

ram-cherukuri avatar Apr 07 '26 18:04 ram-cherukuri

I can take care of this. I understand all we need is add lazy Zarr loading (default lazy_load: true), on-demand sample materialization in the crash datapipe, and DDP memory documentation, then some tests.

Thabhelo avatar Jun 06 '26 03:06 Thabhelo

This issue is stale because it has been open for 60 days with no activity. Remove the stale label or comment to keep it open, otherwise this will be closed in 14 days.

github-actions[bot] avatar Aug 09 '26 02:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Aug 30 '26 01:08 github-actions[bot]