pub enum ShardedSafeTensors<'a> {
Sharded {
b: MmapedSafetensors,
make_dummy_regexes: Option<Arc<Vec<Regex>>>,
},
SimpleBackend(Box<dyn SimpleBackend + 'a>),
}
Variants§
Implementations§
Source§impl<'a> ShardedSafeTensors<'a>
impl<'a> ShardedSafeTensors<'a>
Sourcepub unsafe fn sharded<P: AsRef<Path>>(
paths: &[P],
dtype: DType,
dev: &Device,
make_dummy_regexes: Option<Arc<Vec<Regex>>>,
) -> Result<ShardedVarBuilder<'a>>
pub unsafe fn sharded<P: AsRef<Path>>( paths: &[P], dtype: DType, dev: &Device, make_dummy_regexes: Option<Arc<Vec<Regex>>>, ) -> Result<ShardedVarBuilder<'a>>
Initializes a VarBuilder
that retrieves tensors stored in a collection of safetensors
files and make them usable in a sharded way.
§Safety
The unsafe is inherited from [memmap2::MmapOptions
].
pub fn wrap( backend: Box<dyn SimpleBackend + 'a>, dtype: DType, dev: Device, ) -> ShardedVarBuilder<'a>
Trait Implementations§
Source§impl Backend for ShardedSafeTensors<'_>
impl Backend for ShardedSafeTensors<'_>
Get part of a tensor, typically used to do Tensor Parallelism sharding.
If the tensor is of size (1024, 1024).
dim
corresponds to the dimension to slice into
rank
is the rank of the current process
world_size
is the total number of ranks in the process group
get_sharded("tensor", 0, 0, 2)
means tensor.i((..512))
get_sharded("tensor", 0, 1, 2)
means tensor.i((512..))
get_sharded("tensor", 1, 0, 2)
means tensor.i((.., ..512))
type Hints = Shard
Source§fn get(
&self,
target_shape: Shape,
path: &str,
h: Self::Hints,
dtype: DType,
dev: &Device,
) -> Result<Tensor>
fn get( &self, target_shape: Shape, path: &str, h: Self::Hints, dtype: DType, dev: &Device, ) -> Result<Tensor>
Retrieve a tensor with some target shape.
Source§fn get_unchecked(
&self,
name: &str,
dtype: DType,
dev: &Device,
) -> Result<Tensor>
fn get_unchecked( &self, name: &str, dtype: DType, dev: &Device, ) -> Result<Tensor>
Retrieve a tensor based on the name.
fn contains_tensor(&self, name: &str) -> bool
Auto Trait Implementations§
impl<'a> Freeze for ShardedSafeTensors<'a>
impl<'a> !RefUnwindSafe for ShardedSafeTensors<'a>
impl<'a> Send for ShardedSafeTensors<'a>
impl<'a> Sync for ShardedSafeTensors<'a>
impl<'a> Unpin for ShardedSafeTensors<'a>
impl<'a> !UnwindSafe for ShardedSafeTensors<'a>
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
Converts
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>
Converts
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