pub struct SafetensorsSource { /* private fields */ }Expand description
ModelSource over a HuggingFace-format directory.
Standard layout:
<dir>/config.json (required)
<dir>/generation_config.json (optional)
<dir>/tokenizer.json (required by the runtime)
<dir>/tokenizer_config.json (optional; chat special tokens)
<dir>/model.safetensors (single-file), or
<dir>/model.safetensors.index.json (sharded)For diffusion sub-dirs (unet/, vae/, text_encoder/) use
SafetensorsSource::load_weights_only, which tolerates
diffusion_pytorch_model.safetensors (or model.safetensors) and no
tokenizer/config.
Files are memory-mapped; ModelSource::open_tensor returns zero-copy
views into the mapping.
Implementations§
Source§impl SafetensorsSource
impl SafetensorsSource
Sourcepub fn load(dir: impl AsRef<Path>) -> Result<Self>
pub fn load(dir: impl AsRef<Path>) -> Result<Self>
Opens a model directory (see type docs for the expected layout).
Sourcepub fn load_weights_only(
dir: impl AsRef<Path>,
architecture: &str,
) -> Result<Self>
pub fn load_weights_only( dir: impl AsRef<Path>, architecture: &str, ) -> Result<Self>
Opens a directory purely for weight loading. No config.json or
tokenizer.json is required; metadata() returns a placeholder and
tokenizer() errors. Accepts diffusion-style
diffusion_pytorch_model.safetensors as well as model.safetensors.
Trait Implementations§
Source§impl ModelSource for SafetensorsSource
impl ModelSource for SafetensorsSource
Source§fn metadata(&self) -> &ModelMetadata
fn metadata(&self) -> &ModelMetadata
Architecture + hyperparameter metadata.
Source§fn tensor_names(&self) -> Vec<String>
fn tensor_names(&self) -> Vec<String>
Names of all tensors available in this source.
Source§fn open_tensor(&self, name: &str) -> Result<TensorReader<'_>>
fn open_tensor(&self, name: &str) -> Result<TensorReader<'_>>
Opens a tensor by name, returning a lazy reader over the raw bytes.
Source§fn tokenizer(&self) -> Result<TokenizerSpec>
fn tokenizer(&self) -> Result<TokenizerSpec>
Tokenizer specification (path to
tokenizer.json + added tokens).Source§fn sampler_defaults(&self) -> Option<SamplerConfig>
fn sampler_defaults(&self) -> Option<SamplerConfig>
Sampler defaults from
generation_config.json, if present.Source§fn open_tensor_quant(&self, _name: &str) -> Result<Option<QuantTensor<'_>>>
fn open_tensor_quant(&self, _name: &str) -> Result<Option<QuantTensor<'_>>>
Raw packed quantized bytes for a tensor, when this source stores it
in a quant format that has a device kernel (GGUF Q4_0/Q4_K/Q6_K).
None means “no packed representation” — the caller falls back to
ModelSource::open_tensor, which dequantizes to float. Sources
without packed formats keep this default.Auto Trait Implementations§
impl Freeze for SafetensorsSource
impl RefUnwindSafe for SafetensorsSource
impl Send for SafetensorsSource
impl Sync for SafetensorsSource
impl Unpin for SafetensorsSource
impl UnsafeUnpin for SafetensorsSource
impl UnwindSafe for SafetensorsSource
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