Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cosmos_rl/policy/model/dino_cradio_v3/cosmos_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ model_name_or_path = "nvidia/C-RADIOv3-g"
tp_size = 1
cp_size = 1
ep_size = 1
dp_shard_size = -1 # FSDP-only, autodetect shard size based on WORLD_SIZE
dp_shard_size = 1
pp_size = 1
dp_replicate_size = 1
dp_replicate_size = 8

[train]
resume = false
Expand Down
19 changes: 17 additions & 2 deletions cosmos_rl/policy/model/dino_cradio_v3/parallelize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Optional, Callable

import torch.nn as nn
from torch.distributed.device_mesh import DeviceMesh
from torch.distributed._composable.replicate import replicate

from cosmos_rl.utils.logging import logger
from cosmos_rl.utils.parallelism import ParallelDims
from cosmos_rl.policy.config import Config as CosmosConfig

Expand All @@ -11,7 +15,18 @@ def parallelize_model(
config: CosmosConfig,
pp_loss_fn: Optional[Callable],
) -> nn.Module:
if parallel_dims.world_size > 1:
raise NotImplementedError("Only single GPU runs supported!")
if parallel_dims.world_size == 1:
return None, None

world_mesh = parallel_dims.mesh
# DDP
if parallel_dims.dp_replicate_enabled:
assert world_mesh.ndim == 1, "DDP does not support > 1D parallelism"
_apply_ddp(model, world_mesh)

return None, None


def _apply_ddp(model: nn.Module, dp_mesh: DeviceMesh):
replicate(model, device_mesh=dp_mesh)
logger.info("Applied DDP to the model")
Loading