Skip to main content

provide_weights

Function provide_weights 

Source
pub fn provide_weights(
    file_name: &str,
    bytes: Vec<u8>,
) -> Result<(), ProvideWeightsError>
Expand description

Supply a weight file from memory, so every dispatcher that needs it uses these bytes before looking in $QSM_MODEL_DIR, the cache or the network.

file_name is the registry’s WeightFile::name (e.g. "xqsm.onnx"; for a multi-file model such as NeXtQSM, supply each of its ModelSpec::files). The bytes are checked against the registry’s SHA-256 and refused on a mismatch; a file whose model is WeightStatus::Pending has no hash yet and is taken as given, as $QSM_MODEL_DIR is.

This is how a host without a file system (a browser, wasm32-unknown-unknown) runs the deep-learning stages: fetch each file the run needs, call this, then call the pipeline functions as usual. The buffer is moved in, not copied, and stays until forget_weights (or until replaced by another call for the same file); runs borrow it without copying. Supplying the same file again replaces the earlier buffer.