maia: the weights move into the network (no copy), the file's bytes go once read
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:
parent
0fd40f01b4
commit
a94de00199
3 changed files with 20 additions and 11 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue