STRA-338 size-fn: gptoss-npu experts and prefill_part trimmed

This commit is contained in:
Pavlo Ratushnyi
2026-11-06 18:04:50 +01:00
parent 3691a466ce
commit 0414e6d9f7
3 changed files with 31 additions and 10 deletions
+22 -6
View File
@@ -103,23 +103,39 @@ impl NpuPrefill {
let specs = gate_up_specs(&layout, layer, &plan.chunks, (&at.gate, &at.up), (e, ff));
self.timings.part(5, t0.elapsed());
let shifts = self.timed_products(&specs)?;
let t2 = Instant::now();
let act = self.activation(dispatch, view, &plan, (&at.gate, &at.up), &shifts, ff)?;
let halves = halves_of(dispatch, &act, self.quantize_activations);
self.client.put_at(layout.expert[3].offset, &halves).map_err(fail)?;
self.put_activations(dispatch, &act)?;
let down_specs = down_specs(&layout, layer, &plan.chunks, &at.down, (e, ff));
self.timings.part(6, t2.elapsed());
let down_shifts = self.timed_products(&down_specs)?;
let t4 = Instant::now();
let down_refs: Vec<_> = down_shifts.iter().collect();
let down = self.read_results(&plan.chunks, &at.down, e, &down_refs)?;
let down = self.read_down(&plan.chunks, &at.down, &down_shifts, e)?;
let moe = combine_down(&plan, view, &down, m, e);
self.timings.part(7, t4.elapsed());
Ok(moe)
}
/// The activations as half precision rows for the down products, into the shared region.
fn put_activations(&mut self, dispatch: &Dispatch, act: &[f32]) -> Result<(), ModelError> {
let halves = halves_of(dispatch, act, self.quantize_activations);
self.client
.put_at(self.client.layout.expert[3].offset, &halves)
.map_err(fail)
}
/// The down products' results, with their scale shifts divided out.
fn read_down(
&self,
chunks: &[Chunk],
offsets: &[usize],
shifts: &[Option<Vec<u8>>],
e: usize,
) -> Result<Vec<f32>, ModelError> {
let refs: Vec<_> = shifts.iter().collect();
self.read_results(chunks, offsets, e, &refs)
}
/// Gather the half precision rows of every entry's token into the shared region.
fn put_gathered(&mut self, plan: &ExpertPlan, h2f: &[u16], e: usize) -> Result<(), ModelError> {
let mut gathered = vec![0u16; plan.entry_token.len() * e];
+8
View File
@@ -42,6 +42,14 @@ pub struct Timings {
}
impl Timings {
/// Nothing measured yet for a prefill of `tokens` tokens.
fn starting(tokens: usize) -> Self {
Self {
tokens,
..Self::default()
}
}
fn part(&mut self, i: usize, d: Duration) {
self.other += d;
self.parts[i] += d;
+1 -4
View File
@@ -56,10 +56,7 @@ impl NpuPrefill {
all_hidden: bool,
) -> Result<Option<Vec<f32>>, ModelError> {
let started = Instant::now();
self.timings = Timings {
tokens: tokens.len(),
..Timings::default()
};
self.timings = Timings::starting(tokens.len());
let c = &model.config;
let (e, n) = (c.n_embd, tokens.len());
self.check_request(c, cache.capacity(), n, pos0)?;