Expand description
One place to describe where a model’s weights live and how to load them.
Before this module every runner reimplemented the same download block:
split the repo id, build an [HFClientSync], download a file, then either
unsafe { VarBuilder::from_mmaped_safetensors(..) } or
PthTensors::new(..). Six near-identical copies drifted apart — only ESM3
attached any error context, and every one of them inherited the same
silently-wrong repo-id split (split_once('/').unwrap_or(("", repo_id)),
which turns a malformed id into an empty owner and a confusing 404 rather
than a clear error).
The pieces here are:
WeightSource— plainconstdata on each model enum: which repo, which revision, and which on-diskFormatthe weights use.LoadOptions— the device and dtype to load onto, so the six per-moduleconst *_DTYPEdefinitions collapse into one field.WeightSource::var_builder— the single place holding theunsafemmap.optional_prefix— the “is this checkpoint wrapped in an HF*ForMaskedLMclass?” probe, generalised from ESMC’sesmc.special case.
const WEIGHTS: WeightSource = WeightSource::safetensors("facebook/esm2_t6_8M_UR50D");
let opts = LoadOptions::new(Device::Cpu);
let vb = WEIGHTS.var_builder("model.safetensors", &opts)?;Structs§
- Load
Options - Device and dtype to load a model onto.
- Weight
Source - Where a model’s weights live on the HuggingFace hub, and how to read them.
Enums§
- Format
- How a checkpoint is stored on disk.
Functions§
- optional_
prefix - Descend into
prefixwhen the checkpoint nests the backbone under it. - var_
builder_ from_ path - Build a [
VarBuilder] over a local weight file of the givenFormat.