maia: the weights move into the network (no copy), the file's bytes go once read
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run

Peak memory while loading: 79M 940 → 636 MB, 5M 72 → 52 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-26 00:09:21 +03:00
parent 0fd40f01b4
commit a94de00199
3 changed files with 20 additions and 11 deletions

View file

@ -44,11 +44,11 @@ impl Weights {
shape.get(axis).copied().ok_or(WeightsError::Format)
}
/// The tensor `name` of this shape.
pub fn get(&self, name: &str, shape: &[usize]) -> Result<Vec<f32>, WeightsError> {
/// The tensor `name` of this shape, taken out (each is used once: no copy).
pub fn get(&mut self, name: &str, shape: &[usize]) -> Result<Vec<f32>, WeightsError> {
let t = self
.tensors
.get(name)
.remove(name)
.ok_or_else(|| WeightsError::Missing(name.to_owned()))?;
if t.shape != shape {
return Err(WeightsError::Shape(
@ -57,6 +57,6 @@ impl Weights {
shape.to_vec(),
));
}
Ok(t.data.clone())
Ok(t.data)
}
}