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

@ -65,7 +65,7 @@ struct Linear {
impl Linear {
fn load(
w: &Weights,
w: &mut Weights,
name: &str,
out: usize,
inp: usize,
@ -152,7 +152,7 @@ struct LayerNorm {
}
impl LayerNorm {
fn load(w: &Weights, name: &str, n: usize) -> Result<LayerNorm, WeightsError> {
fn load(w: &mut Weights, name: &str, n: usize) -> Result<LayerNorm, WeightsError> {
Ok(LayerNorm {
w: w.get(&format!("{name}.weight"), &[n])?,
b: w.get(&format!("{name}.bias"), &[n])?,
@ -246,7 +246,7 @@ pub struct Prediction {
}
impl Net {
pub fn new(w: &Weights) -> Result<Net, WeightsError> {
pub fn new(w: &mut Weights) -> Result<Net, WeightsError> {
let dims = Dims::read(w)?;
let Dims {
d,