physicsnemo-shard-tensor

Integrate ShardTensor domain parallelism into PhysicsNeMo training and inference scripts.

3.2k|370|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/NVIDIA/skills --skill physicsnemo-shard-tensor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: physicsnemo-shard-tensor
Source: https://github.com/NVIDIA/skills/tree/main/skills/physicsnemo-shard-tensor
Command: npx skills add https://github.com/NVIDIA/skills --skill physicsnemo-shard-tensor

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Physics simulations with high-resolution inputs often exceed single-GPU memory, and standard PyTorch DDP/FSDP guidance does not cover splitting one sample's spatial or sequence dimension across GPUs. This Skill provides NVIDIA-authored guidance for PhysicsNeMo's ShardTensor domain parallelism so agents can convert scripts correctly without modifying model code.

Core Features & Use Cases

  • Script-level integration: Build 2D DeviceMesh topologies with named ddp and domain axes, scatter inputs with scatter_tensor, and choose the right wrapper (DDP or FSDP2 fully_shard) while leaving model code unchanged via auto-promotion.
  • Custom op enablement: Register shard patches from user code at import time using register_function_handler, register_dispatch_handler, or register_named_function_handler, modeled on existing patches in physicsnemo/domain_parallel/shard_utils/.
  • Multi-GPU correctness testing: Bootstrap distributed-vs-single-GPU numerical comparisons with numerical_shard_tensor_check and check_grads=True under torchrun with the multigpu_static marker.
  • Use Case: A ViT-style PhysicsNeMo training script OOMs on high-resolution inputs; the Skill guides converting it to an 8-GPU ddp x domain mesh with sharded spatial activations, batch size 1 per domain group, and verified gradient correctness.

Quick Start

Ask your agent to convert a single-GPU PhysicsNeMo training script to use ShardTensor domain parallelism across multiple GPUs with DDP or FSDP2.

Frequently Asked Questions about physicsnemo-shard-tensor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert a single-GPU PhysicsNeMo training script to multi-GPU domain parallelism?

Build a 2D DeviceMesh with named ddp and domain axes via DistributedManager.initialize_mesh, scatter inputs over the domain mesh with scatter_tensor using a Shard placement on a spatial dimension, keep the model code unchanged, and wrap with DistributedDataParallel on the explicit ddp process group. Per-domain-group batch size must be 1.

How do I add ShardTensor support for a custom layer that raises MissingShardPatch?

Register a patch from user code at import time using ShardTensor.register_function_handler, register_dispatch_handler, or register_named_function_handler, without forking physicsnemo. Model the implementation on existing patches in physicsnemo/domain_parallel/shard_utils/ such as pooling_patches.py, then validate with numerical_shard_tensor_check using check_grads=True.

Should I use DDP or FSDP2 with ShardTensor domain parallelism?

Use DistributedDataParallel when all parameters are plain tensors, since auto-promotion keeps them plain even with domain parallelism. Use FSDP2 fully_shard only when you need parameter sharding for memory or have DTensor spatial parameters; never use FSDP1, which conflicts with the auto-promotion design.

Why does ShardTensor addition fail with TypeError unsupported operand types?

The TypeError is misleading: binary dunders convert an internal NotImplementedError into NotImplemented, so CPython emits the generic message and hides the real traceback. Temporarily replace x + y with torch.add(x, y) to surface the true underlying exception.

When should I not use ShardTensor domain parallelism?

Do not use it for generic PyTorch DDP/FSDP setup without domain parallelism, LLM tensor or pipeline parallelism such as Megatron-style sharding, single-GPU training, or choosing PhysicsNeMo models and examples. ShardTensor targets spatial and sequence sharding of activations for physics workloads.

Does ShardTensor work with torch.compile?

Yes, with constraints: pass dynamic=False, and when domain_size is greater than 1, compile regionally while leaving sharded ring attention eager. Call torch._dynamo.reset() between input-size changes, and verify compiled versus eager numerics.