pub type VarBuilder<'a> = VarBuilderArgs<'a, Box<dyn SimpleBackend + 'a>>;
Expand description
A simple VarBuilder
, this is less generic than VarBuilderArgs
but should cover most common
use cases.
Aliased Type§
struct VarBuilder<'a> {
pub dtype: DType,
/* private fields */
}
Fields§
§dtype: DType
Implementations§
source§impl<'a> VarBuilder<'a>
impl<'a> VarBuilder<'a>
sourcepub fn from_backend(
backend: Box<dyn SimpleBackend + 'a>,
dtype: DType,
device: Device,
) -> Self
pub fn from_backend( backend: Box<dyn SimpleBackend + 'a>, dtype: DType, device: Device, ) -> Self
Initializes a VarBuilder
using a custom backend.
It is preferred to use one of the more specific constructors. This constructor is provided to allow downstream users to define their own backends.
sourcepub fn zeros(dtype: DType, dev: &Device) -> Self
pub fn zeros(dtype: DType, dev: &Device) -> Self
Initializes a VarBuilder
that uses zeros for any tensor.
sourcepub fn from_tensors(
ts: HashMap<String, Tensor>,
dtype: DType,
dev: &Device,
) -> Self
pub fn from_tensors( ts: HashMap<String, Tensor>, dtype: DType, dev: &Device, ) -> Self
Initializes a VarBuilder
that retrieves tensors stored in a hashtable. An error is
returned if no tensor is available under the requested path or on shape mismatches.
sourcepub unsafe fn from_mmaped_safetensors<P: AsRef<Path>>(
paths: &[P],
dtype: DType,
dev: &Device,
) -> Result<Self>
pub unsafe fn from_mmaped_safetensors<P: AsRef<Path>>( paths: &[P], dtype: DType, dev: &Device, ) -> Result<Self>
Initializes a VarBuilder
that retrieves tensors stored in a collection of safetensors
files.
§Safety
The unsafe is inherited from [memmap2::MmapOptions
].