pub struct DTensor<T: Float> { /* private fields */ }Expand description
A logical tensor distributed across a DeviceMesh.
placements.len() must equal mesh.ndim() — there’s exactly one
placement per mesh dim. The physical storage is the per-rank
local_tensor; global_shape is the logical shape callers see.
Implementations§
Source§impl<T: Float> DTensor<T>
impl<T: Float> DTensor<T>
Sourcepub fn from_local(
local_tensor: Tensor<T>,
mesh: DeviceMesh,
placements: Vec<Placement>,
global_shape: Vec<usize>,
) -> FerrotorchResult<Self>
pub fn from_local( local_tensor: Tensor<T>, mesh: DeviceMesh, placements: Vec<Placement>, global_shape: Vec<usize>, ) -> FerrotorchResult<Self>
Wrap a per-rank local tensor with explicit placement annotations.
placements.len() must equal mesh.ndim(). global_shape is the
logical full-tensor shape (for Replicate it equals
local_tensor.shape(); for Shard it’s the local shape with the
sharded dim multiplied by the mesh size along that dim).
Sourcepub fn from_local_replicated(
local: Tensor<T>,
mesh: DeviceMesh,
) -> FerrotorchResult<Self>
pub fn from_local_replicated( local: Tensor<T>, mesh: DeviceMesh, ) -> FerrotorchResult<Self>
Build a fully-replicated DTensor: every rank holds the same tensor.
Equivalent to from_local with placements = [Replicate; mesh.ndim()]
and global_shape = local_tensor.shape().
Sourcepub fn placements(&self) -> &[Placement]
pub fn placements(&self) -> &[Placement]
Per-mesh-dim placement annotations.
Sourcepub fn mesh(&self) -> &DeviceMesh
pub fn mesh(&self) -> &DeviceMesh
The associated mesh.
Sourcepub fn redistribute(
&mut self,
target_placements: Vec<Placement>,
) -> FerrotorchResult<()>
pub fn redistribute( &mut self, target_placements: Vec<Placement>, ) -> FerrotorchResult<()>
Redistribute this DTensor to a new placement spec.
target_placements.len() must equal mesh.ndim(). The supported
transitions are:
Replicate → Replicate: no-op.Shard(d) → Shard(d)(same dim): no-op.Replicate → Shard(d): scatter (caller picks the rank’s shard).Shard(d) → Replicate: all_gather along the relevant mesh dim.Partial(op) → Replicate: all_reduce along the relevant mesh dim.Shard(d) → Shard(e)withd != e: all_to_all transpose.
The actual collective dispatch is delegated to the
crate::collective surface; this method records the intended
target and updates local_tensor to reflect the local shard after
the redistribute. Each transition is only validated for shape
compatibility here — the cross-rank communication is performed by
the lower-level crate::collective::* ops the caller invokes
before / after redistribute lands. (This separation keeps the
DTensor API testable without real multi-process launches.)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DTensor<T>
impl<T> !RefUnwindSafe for DTensor<T>
impl<T> Send for DTensor<T>
impl<T> Sync for DTensor<T>
impl<T> Unpin for DTensor<T>
impl<T> UnsafeUnpin for DTensor<T>
impl<T> !UnwindSafe for DTensor<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more