Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/gpu-deepseek41/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ pub struct KBlockKernels {
}

impl KBlockKernels {
/// The device bytes the kernels hold beside their modules: the K-gemv's
/// expert ids.
pub fn device_bytes(&self) -> usize {
self.gemv.device_bytes()
}

/// Load the three into `gpu`'s context. Load-time only.
///
/// # Errors
Expand Down
63 changes: 33 additions & 30 deletions crates/gpu-gates/src/bin/gate_nemotron_serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ mod gate {
fn plan_only_names_its_default(
dir: &Path,
file: &Path,
ok: &mut bool,
) -> Result<Option<u64>, GateError> {
) -> Result<(Option<u64>, bool), GateError> {
let mut ok = true;
let limit = trained_ctx(file)?;
let (status, log, text) = plan(dir, "plan", file, &[])?;
let place = log.first(&record::PLACE_UNSET)?;
Expand Down Expand Up @@ -233,19 +233,16 @@ mod gate {
default_ok = line_ok && held && stands && above_short;
}
check(
ok,
&mut ok,
"plan_only_names_its_default",
exits && in_order && word_a && no_load && default_ok,
);
Ok(ctx_line(&text).and_then(|l| field(l, "ctx")))
Ok((ctx_line(&text).and_then(|l| field(l, "ctx")), ok))
}

/// `parallel_above_one_is_refused` (the module header).
fn parallel_above_one_is_refused(
dir: &Path,
file: &Path,
ok: &mut bool,
) -> Result<(), GateError> {
fn parallel_above_one_is_refused(dir: &Path, file: &Path) -> Result<bool, GateError> {
let mut ok = true;
let (status, log, text) = plan(dir, "refuse-parallel", file, &["--parallel", "2"])?;
let named = text.contains(ONE_SEQUENCE);
let no_plan = log.first(&record::PLAN)?.is_none();
Expand All @@ -258,11 +255,11 @@ mod gate {
println!("refuse-parallel stderr:\n{text}");
}
check(
ok,
&mut ok,
"parallel_above_one_is_refused",
!status.success() && named && no_plan,
);
Ok(())
Ok(ok)
}

/// The ids `NemotronHModel` gives stepped directly: for each prompt, from an empty cache, the
Expand Down Expand Up @@ -306,8 +303,8 @@ mod gate {
file: &Path,
default_ctx: Option<u64>,
layers: u64,
ok: &mut bool,
) -> Result<Option<Answers>, GateError> {
) -> Result<(Option<Answers>, bool), GateError> {
let mut ok = true;
let d = dir.join("serve");
std::fs::create_dir_all(&d)?;
let (cmd, mut all) = command(file)?;
Expand All @@ -319,8 +316,8 @@ mod gate {
Ok(addr) => addr,
Err(e) => {
println!("the server never listened: {e}");
check(ok, "load_and_listen", false);
return Ok(None);
check(&mut ok, "load_and_listen", false);
return Ok((None, ok));
}
};
let text = std::fs::read_to_string(&err_log).unwrap_or_default();
Expand All @@ -345,7 +342,7 @@ mod gate {
listen.line()
);
check(
ok,
&mut ok,
"load_and_listen",
same_ctx && loaded && ctx_is_plans && in_order,
);
Expand Down Expand Up @@ -373,15 +370,18 @@ mod gate {
println!("{name}: {e}");
false
});
check(ok, name, pass);
check(&mut ok, name, pass);
}
println!("server stopped: {}", s.stop()?);
Ok(Some(Answers {
prose,
turn,
prose_answer,
turn_answer,
}))
Ok((
Some(Answers {
prose,
turn,
prose_answer,
turn_answer,
}),
ok,
))
}

/// `edit_resend_is_a_fresh_run` (the module header): the slot holds the prose prompt and its
Expand Down Expand Up @@ -428,7 +428,8 @@ mod gate {
}

/// `completion_ids` (the module header), the server stopped and the session on the card.
fn completion_ids(file: &Path, a: &Answers, ok: &mut bool) -> Result<(), GateError> {
fn completion_ids(file: &Path, a: &Answers) -> Result<bool, GateError> {
let mut ok = true;
let ids = session_ids(file, &[a.prose.as_slice(), a.turn.as_slice()])?;
let prose = agree(&a.prose_answer.tokens, &a.prose_answer.stop, &ids[0]);
let turn = agree(&a.turn_answer.tokens, &a.turn_answer.stop, &ids[1]);
Expand All @@ -438,8 +439,8 @@ mod gate {
a.prose_answer.tokens.len(),
a.turn_answer.tokens.len()
);
check(ok, "completion_ids", prose && turn);
Ok(())
check(&mut ok, "completion_ids", prose && turn);
Ok(ok)
}

pub fn run() -> Result<(), GateError> {
Expand All @@ -454,11 +455,13 @@ mod gate {
)?;
drop(split);
let mut ok = true;
let default_ctx = plan_only_names_its_default(&dir, &file, &mut ok)?;
parallel_above_one_is_refused(&dir, &file, &mut ok)?;
let answers = served(&dir, &file, default_ctx, layers, &mut ok)?;
let (default_ctx, pass) = plan_only_names_its_default(&dir, &file)?;
ok &= pass;
ok &= parallel_above_one_is_refused(&dir, &file)?;
let (answers, pass) = served(&dir, &file, default_ctx, layers)?;
ok &= pass;
if let Some(a) = answers {
completion_ids(&file, &a, &mut ok)?;
ok &= completion_ids(&file, &a)?;
}
if !ok {
return Err(checks_failed());
Expand Down
1 change: 1 addition & 0 deletions crates/gpu-glm5next/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,7 @@ impl ChainBody for Body {
.nextn
.as_deref()
.map_or(0, |n| n.resident_bytes() + n.arena_bytes())
+ self.k.block.as_ref().map_or(0, KBlockKernels::device_bytes)
}

fn layers(&self) -> Range<usize> {
Expand Down
1 change: 1 addition & 0 deletions crates/gpu-mimo2/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ impl ChainBody for Body {
.taps
.as_ref()
.map_or(0, |t| t.iter().map(DeviceBuffer::num_bytes).sum())
+ self.k.block.as_ref().map_or(0, KBlockKernels::device_bytes)
}

fn layers(&self) -> Range<usize> {
Expand Down
9 changes: 5 additions & 4 deletions crates/gpu/src/arch/nemotron_h/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ impl GpuModel<Body> {
impl Body {
fn load(gpu: &Gpu, file: &Split, w: &mut Weights, ctx: usize) -> Result<Body, GpuError> {
let hp = Hparams::read(file).map_err(|e| GpuError::plan(WHAT, e))?;
if ctx == 0 {
return Err(GpuError::shape(WHAT, "a cache of 0 rows"));
}
let ssm = hp.ssm;
let mamba = mamba2::check(
WHAT,
Expand Down Expand Up @@ -359,7 +356,11 @@ impl ChainBody for Body {
Layer::Mlp(_) => 0,
})
.sum();
layers + self.s.bytes() + self.acts.bytes() + self.r.num_bytes()
layers
+ self.s.bytes()
+ self.acts.bytes()
+ self.r.num_bytes()
+ self.k.kgemv.device_bytes()
}

fn layers(&self) -> Range<usize> {
Expand Down
1 change: 1 addition & 0 deletions crates/gpu/src/arch/nemotron_h/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl Scratch {
+ self.words.num_bytes()
+ self.pos.num_bytes()
+ self.n_keys.num_bytes()
+ self.mamba.device_bytes()
}

/// The scratch for `sh`, the widest `ff` an MLP layer has and the
Expand Down
1 change: 1 addition & 0 deletions crates/gpu/src/arch/qwen3moe/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ impl ChainBody for Body {
+ self.ub.bytes()
+ self.taps.as_ref().map_or(0, |t| t.buf.num_bytes())
+ self.placed.as_ref().map_or(0, Placed::device_bytes)
+ self.k.q35.as_ref().map_or(0, |k| k.kgemv.device_bytes())
}

fn layers(&self) -> Range<usize> {
Expand Down
1 change: 1 addition & 0 deletions crates/gpu/src/arch/qwen3moe/body35.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3193,6 +3193,7 @@ impl ChainBody for Body35 {
.as_ref()
.map_or(0, |d| d.resident_bytes() + d.scratch_bytes())
+ self.placed.as_ref().map_or(0, Placed::device_bytes)
+ self.k.q35.as_ref().map_or(0, |k| k.kgemv.device_bytes())
}

fn layers(&self) -> Range<usize> {
Expand Down
5 changes: 5 additions & 0 deletions crates/gpu/src/mamba2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ pub struct Mamba2Scratch {
}

impl Mamba2Scratch {
/// The device bytes the scratch holds.
pub(crate) fn device_bytes(&self) -> usize {
self.part.num_bytes() + self.done.num_bytes()
}

/// A zeroed scratch for `shape`. Load-time only. `shape` is checked again
/// here, so a conv the host accepted and this kernel refuses never
/// allocates.
Expand Down
6 changes: 6 additions & 0 deletions crates/gpu/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ pub struct KGemvKernels {
}

impl KGemvKernels {
/// The device bytes the kernels hold beside their modules: the one
/// expert's ids.
pub fn device_bytes(&self) -> usize {
self.one.num_bytes()
}

/// Load the `_sel` family into `gpu`'s context, raising into its fault
/// word, and zero the ids. Load-time only.
pub fn load(gpu: &Gpu) -> Result<KGemvKernels, GpuError> {
Expand Down
Loading