nemo_rl.weight_sync.xferdtensor_python#
Standalone striped-receive Python DTensor resharding.
xferdtensor_python_impl implements exact Shard/Replicate resharding
without materializing a global tensor. For compatible replicated destinations:
Split every nonempty local destination shard into equal contiguous stripes.
Receive each stripe directly on a different member of the replica group.
Reconstruct every replica with one in-place NCCL all-gather.
The optimization is selected only when every active destination replica group can split dimension zero evenly, every exact receive can land directly in a contiguous destination view or be sent from a contiguous source view. This avoids striped plans that need both source packing and receive staging for one transfer. Other shapes and scalar tensors use the generic exact-transfer path contained in this module. This preserves arbitrary Shard/Replicate behavior without padding or a full-tensor temporary.
For contiguous local DTensors, the all-gather send stripe and receive buffer are views of the caller-owned destination shard. Explicit temporary storage is limited to noncontiguous source packing and destination receive staging. A noncontiguous local destination uses at most one additional contiguous local-shard buffer; a global-sized buffer is never allocated.
Module Contents#
Functions#
Return DTensor’s sequential sharding slices for one mesh coordinate. |
|
Group identical destination regions and select one DP0 representative. |
|
Return |
|
Collectively split once into all nonempty destination replica groups. |
|
Clear generic/striped plans and split communicators. |
|
Validate local buffers before entering communicator split or P2P. |
|
Reshard |
|
Return members in the rank order used by v1’s split communicator. |
|
Return |
|
Build exact source-to-stripe transfers with balanced source replicas. |
|
Return the largest distinct remote-peer count on any rank. |
|
Return whether |
|
Reject remote overlaps needing both send packing and receive staging. |
|
Return cached v1 geometry plus a striped plan, or |
|
Return a contiguous local-shard buffer and whether it needs copy-back. |
|
Stage exact transfers into the stripe owned by this destination rank. |
|
Reconstruct every local destination shard with an in-place all-gather. |
|
Reshard exactly, using striped receives for compatible replicas. |
Data#
API#
- nemo_rl.weight_sync.xferdtensor_python._mesh_rank_tensor(mesh)#
- nemo_rl.weight_sync.xferdtensor_python._mesh_ranks(mesh)#
- nemo_rl.weight_sync.xferdtensor_python._mesh_signature(mesh)#
- nemo_rl.weight_sync.xferdtensor_python._mesh_coordinates(mesh)#
- nemo_rl.weight_sync.xferdtensor_python._normalize_shard_dim(dim, tensor_ndim)#
- nemo_rl.weight_sync.xferdtensor_python._placement_signature(placements, tensor_ndim)#
- nemo_rl.weight_sync.xferdtensor_python._validate_layout(mesh, placements, global_shape, name)#
- nemo_rl.weight_sync.xferdtensor_python._compute_shard_slices(
- global_shape,
- mesh_shape,
- coordinates,
- placements,
Return DTensor’s sequential sharding slices for one mesh coordinate.
Sequential semantics matter when multiple mesh dimensions shard the same tensor dimension: each placement shards the local chunk produced by the preceding placement, including its uneven remainder.
- nemo_rl.weight_sync.xferdtensor_python._rank_regions(mesh, placements, global_shape)#
- nemo_rl.weight_sync.xferdtensor_python._intersect(left, right)#
- nemo_rl.weight_sync.xferdtensor_python._local_slices(overlap, owner_region)#
- nemo_rl.weight_sync.xferdtensor_python._region_numel(region)#
- nemo_rl.weight_sync.xferdtensor_python._local_tensor(tensor)#
- nemo_rl.weight_sync.xferdtensor_python._tensor_metadata(src_tensor, dst_tensor)#
- nemo_rl.weight_sync.xferdtensor_python._destination_groups(dst_mesh, dst_placements, dst_regions)#
Group identical destination regions and select one DP0 representative.
- nemo_rl.weight_sync.xferdtensor_python._build_exact_plan(src_regions, src_ranks, destination_groups)#
Return
(source, representative, overlap)transfers.Replicated source regions are deduplicated. If a destination representative also owns a valid source replica, use it for a local copy; otherwise use the first holder in source-mesh order.
- nemo_rl.weight_sync.xferdtensor_python._PLAN_CACHE#
‘OrderedDict(…)’
- nemo_rl.weight_sync.xferdtensor_python._PLAN_CACHE_MAX_SIZE#
1024
- nemo_rl.weight_sync.xferdtensor_python._plan_geometry(
- src_mesh,
- src_placements,
- dst_mesh,
- dst_placements,
- global_shape,
- nemo_rl.weight_sync.xferdtensor_python._SUBCOMM_CACHE#
None
- nemo_rl.weight_sync.xferdtensor_python._INACTIVE_SUBCOMM_CACHE#
None
- nemo_rl.weight_sync.xferdtensor_python._PROCESS_GROUP_COMM_IDS#
None
- nemo_rl.weight_sync.xferdtensor_python._PROCESS_GROUP_FINALIZERS#
None
- nemo_rl.weight_sync.xferdtensor_python._destroy_subcommunicator(communicator)#
- nemo_rl.weight_sync.xferdtensor_python._evict_communicators(comm_ids)#
- nemo_rl.weight_sync.xferdtensor_python._finalize_process_group(process_group_id)#
- nemo_rl.weight_sync.xferdtensor_python._parent_communicator_key(process_group)#
- nemo_rl.weight_sync.xferdtensor_python._active_replica_signature(destination_groups)#
- nemo_rl.weight_sync.xferdtensor_python._get_replica_subcommunicator(
- process_group,
- destination_groups,
- device,
Collectively split once into all nonempty destination replica groups.
The nccl4py version used by the target environment can hang if some peers use NCCL_SPLIT_NOCOLOR. Therefore ranks outside an active replica group join one unused leftover color. This preserves one collective split and does not add any data movement.
- nemo_rl.weight_sync.xferdtensor_python.clear_xferdtensor_python_caches(process_group=None)#
Clear generic/striped plans and split communicators.
This is part of the distributed call protocol: when a process group may be used again, every rank in that group must call cleanup in the same order after all GPU work has been synchronized. Asymmetric eviction can make one rank enter a future collective split while its peers reuse a cached split. Passing a process group removes only that group’s communicators; omitting it clears every local cache and is intended for coordinated teardown.
Call this explicitly before destroying or replacing a parent process group. The weak-reference finalizer is a best-effort fallback for Python cache bookkeeping, not a substitute for collective NCCL teardown ordering.
- nemo_rl.weight_sync.xferdtensor_python._validate_local_inputs(
- rank,
- src_tensor,
- dst_tensor,
- src_regions,
- dst_regions,
- device,
- dtype,
Validate local buffers before entering communicator split or P2P.
- nemo_rl.weight_sync.xferdtensor_python._stage_rank_operations(
- rank,
- src_tensor,
- dst_tensor,
- src_regions,
- dst_regions,
- transfers,
- device,
- dtype,
- stream=None,
- nemo_rl.weight_sync.xferdtensor_python._exchange_exact_overlaps(communicator, sends, receives, stream)#
- nemo_rl.weight_sync.xferdtensor_python._broadcast_destination(subcommunicator, dst_local, stream)#
- nemo_rl.weight_sync.xferdtensor_python._xferdtensor_python_impl_v1(
- src_tensor,
- src_mesh,
- src_placement,
- dst_tensor,
- dst_mesh,
- dst_placement,
- process_group,
- stream=None,
Reshard
src_tensorintodst_tensorwith exact data movement.This has the same seven-argument signature and in-place effect as
xferdtensor_golden. Every process-group rank must call it in the same order. The process group is expected to cover the union of source and destination meshes, as required by the reference implementation.
- nemo_rl.weight_sync.xferdtensor_python._STRIPED_PLAN_CACHE#
‘OrderedDict(…)’
- nemo_rl.weight_sync.xferdtensor_python._STRIPED_PLAN_CACHE_MAX_SIZE#
1024
- nemo_rl.weight_sync.xferdtensor_python._ordered_replica_members(representative, members)#
Return members in the rank order used by v1’s split communicator.
- nemo_rl.weight_sync.xferdtensor_python._build_striped_targets(destination_groups)#
Return
(destination_region, receiver)targets and rank stripes.NCCL all-gather has an equal-count contract. Splitting dimension zero of a contiguous row-major local shard produces equal, contiguous buffers and makes communicator-rank order match destination memory order exactly.
Nonemeans that the complete call must use the generic v1 path.
- nemo_rl.weight_sync.xferdtensor_python._build_striped_transfers(src_regions, src_ranks, targets)#
Build exact source-to-stripe transfers with balanced source replicas.
- nemo_rl.weight_sync.xferdtensor_python._max_p2p_peer_degree(transfers)#
Return the largest distinct remote-peer count on any rank.
- nemo_rl.weight_sync.xferdtensor_python._region_view_is_contiguous(region, parent_region)#
Return whether
regionis contiguous inside a row-major parent.
- nemo_rl.weight_sync.xferdtensor_python._remote_transfers_avoid_double_staging(
- transfers,
- src_regions,
- dst_regions,
Reject remote overlaps needing both send packing and receive staging.
- nemo_rl.weight_sync.xferdtensor_python._striped_geometry(
- src_mesh,
- src_placements,
- dst_mesh,
- dst_placements,
- global_shape,
Return cached v1 geometry plus a striped plan, or
Nonefallback.
- nemo_rl.weight_sync.xferdtensor_python._destination_buffer(dst_local, device, dtype, stream)#
Return a contiguous local-shard buffer and whether it needs copy-back.
- nemo_rl.weight_sync.xferdtensor_python._stage_striped_operations(
- rank,
- src_tensor,
- destination_buffer,
- src_regions,
- dst_regions,
- transfers,
- device,
- dtype,
- stream,
Stage exact transfers into the stripe owned by this destination rank.
- nemo_rl.weight_sync.xferdtensor_python._allgather_destination(
- subcommunicator,
- destination_buffer,
- destination_region,
- stripe_region,
- stream,
Reconstruct every local destination shard with an in-place all-gather.
- nemo_rl.weight_sync.xferdtensor_python.xferdtensor_python_impl(
- src_tensor,
- src_mesh,
- src_placement,
- dst_tensor,
- dst_mesh,
- dst_placement,
- process_group,
- stream=None,
Reshard exactly, using striped receives for compatible replicas.
stream(optionaltorch.cuda.Stream) pins every enqueued operation onto the caller’s stream so the reshard is ordered with the caller’s surrounding work (e.g. staging/copy-back of merged params);Noneuses the current stream.
- nemo_rl.weight_sync.xferdtensor_python.__all__#
[‘clear_xferdtensor_python_caches’, ‘xferdtensor_python_impl’]