perf: separate tile configuration for the grouped expert products; record the tile sweep (STRA-219)

No tile beat 4x4 for the experts; the hook (LELEKA_IGPU_MOE_TILE) stays for later experiments.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-10-15 01:32:19 +02:00
co-authored by Claude Sonnet 5.5
parent 8f827d2366
commit a08d6fbf55
2 changed files with 16 additions and 3 deletions
+14 -3
View File
@@ -125,6 +125,8 @@ pub struct Gpu {
no_bias: wgpu::Buffer,
/// Outputs per thread along the activation rows and the weight rows.
tile: (u32, u32),
/// Outputs per thread of the grouped expert products (their own tile: rows per expert are few).
moe_tile: (u32, u32),
}
#[repr(C)]
@@ -378,6 +380,14 @@ impl Gpu {
if !(1..=8).contains(&tm) || !(1..=8).contains(&tn) {
return Err(GpuError::Shape(format!("tile {tm}x{tn} is outside 1..=8")));
}
// experiment hook: LELEKA_IGPU_MOE_TILE=TMxTN
let moe_tile = std::env::var("LELEKA_IGPU_MOE_TILE")
.ok()
.and_then(|s| {
let (a, b) = s.split_once('x')?;
Some((a.parse().ok()?, b.parse().ok()?))
})
.unwrap_or((tm, tn));
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
@@ -424,7 +434,7 @@ impl Gpu {
),
gemm_moe: pipeline(
"gemm moe mxfp4",
shaders::gemm(WeightKind::Mxfp4, tm, tn, true),
shaders::gemm(WeightKind::Mxfp4, moe_tile.0, moe_tile.1, true),
),
quantize: pipeline("quantize", shaders::with_helpers(shaders::QUANTIZE)),
swiglu_quant: pipeline("swiglu quant", shaders::with_helpers(shaders::SWIGLU_QUANT)),
@@ -442,6 +452,7 @@ impl Gpu {
queue,
info,
tile: (tm, tn),
moe_tile,
})
}
@@ -688,7 +699,7 @@ impl Gpu {
for (i, expert) in chosen.iter().enumerate() {
per_expert[*expert as usize].push((i / used) as u32);
}
let rows_per_tile = 8 * self.tile.0 as usize;
let rows_per_tile = 8 * self.moe_tile.0 as usize;
let mut rowmap = Vec::with_capacity(chosen.len());
let mut tiles = Vec::new();
let mut first = vec![0usize; experts];
@@ -1077,7 +1088,7 @@ impl Recorder<'_> {
let dims_buf = self.uniform(&dims);
let bias_buffer = bias.map_or(&self.gpu.no_bias, |b| &b.buffer);
let groups = (
n.div_ceil(8 * self.gpu.tile.1 as usize) as u32,
n.div_ceil(8 * self.gpu.moe_tile.1 as usize) as u32,
plan.tile_count as u32,
1,
);
+2
View File
@@ -78,6 +78,8 @@ Limits of this result: synthetic random-id prompts (not an agent trace), three t
and the GPU path's quality is the borderline gate result above. Time-to-first-token for a real request also
includes the CPU's lm-head and the control plane; the end-to-end agent workload A/B is still to do.
After the A/B above, staging two shared-dimension blocks per barrier pair in the MXFP4 GEMM (bit-identical output) took a single 1024-token GPU prefill from 15.9 s to 13.6 s (75 tok/s; the A/B table was measured before this change). Other expert tiles per thread (6x6, 4x3, 3x4, 6x4, 4x6, 5x5, `LELEKA_IGPU_MOE_TILE`) were not faster than 4x4; the machine warmed up during that sweep, so small differences there are not meaningful.
Where the GPU time goes (earlier single runs): experts are the floor (the grouped GEMM runs at 0.6-0.85 TOPS of
integer work against 4.49 TOPS for `dot4I8Packed` alone, `examples/dot4_peak.rs`, tile sweep with
`LELEKA_IGPU_TILE`), and attention grows with the square of the context (one full layer over a 512-token batch