Skip to main content

optional_prefix

Function optional_prefix 

Source
pub fn optional_prefix<'a>(
    vb: VarBuilder<'a>,
    prefix: &str,
    probe: &str,
) -> VarBuilder<'a>
Expand description

Descend into prefix when the checkpoint nests the backbone under it.

HuggingFace wrapper classes (EsmForMaskedLM, ESMCForMaskedLM, …) store the backbone under an attribute, so the same architecture ships both flat and prefixed. probe is a tensor that always exists in the backbone; if {prefix}.{probe} is present the prefixed root is returned, otherwise vb is returned unchanged.

// "esmc.embed.weight" present → root at "esmc", else flat.
let root = optional_prefix(vb, "esmc", "embed.weight");