ml: 1x1 PReLU convs on ConvPoint, mbf 41 -> 33 ms on Pixel
- Commit
51c6c6321ffec8dbfd08764646a3864ab19e5c8b- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-26 00:28 UTC (1 month ago)
- Parents
62faa63
Diff
library/ml/src/main/rust/src/nets/mod_part9.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part9.rs b/library/ml/src/main/rust/src/nets/mod_part9.rsindex a6ea8792fb..625c1effeb 100644--- a/library/ml/src/main/rust/src/nets/mod_part9.rs+++ b/library/ml/src/main/rust/src/nets/mod_part9.rs@@ -174,8 +174,7 @@ impl<'a> Builder<'a> { && stride == &(1, 1) && pad == &(0, 0) && si.h == so.h- && si.w == so.w- && !matches!(act, Act::PRelu(_));+ && si.w == so.w; if tiled { let positions = so.h * so.w; let tiles =@@ -187,6 +186,7 @@ impl<'a> Builder<'a> { out: at(*out)?, weight: *weight, bias: *bias,+ act_weight: *act_weight, in_c: si.c, in_h: si.h, in_w: si.w,
library/ml/src/main/rust/src/nets/reference_part2.rs
diff --git a/library/ml/src/main/rust/src/nets/reference_part2.rs b/library/ml/src/main/rust/src/nets/reference_part2.rsindex 627d212131..0001546a27 100644--- a/library/ml/src/main/rust/src/nets/reference_part2.rs+++ b/library/ml/src/main/rust/src/nets/reference_part2.rs@@ -110,16 +110,16 @@ impl Reference { for channel in 0..p.out_c { let bias = self.weight(p.bias, channel)?; let shift = self.fused_shift(p, channel)?;+ let slope = self.slope(p, channel)?; for position in 0..positions { let mut total = 0.0f32; for input in 0..p.in_c { total += self.weight(p.weight, channel * p.in_c + input)? * self.load(p.in0, input * positions + position)?; }- // `Builder::conv` refuses to route a PRelu here, so the slope is never read. let index = channel * positions + position; let folded =- activate(total + bias, p.act, 0.0) + self.fused_res(p, index)? + shift;+ activate(total + bias, p.act, slope) + self.fused_res(p, index)? + shift; self.store(p.out, index, self.fused_quant(p, folded)?)?; } }
library/ml/src/main/rust/src/vulkan/parity_part6.rs
diff --git a/library/ml/src/main/rust/src/vulkan/parity_part6.rs b/library/ml/src/main/rust/src/vulkan/parity_part6.rsindex 37c69cf5c6..cdb39f37e0 100644--- a/library/ml/src/main/rust/src/vulkan/parity_part6.rs+++ b/library/ml/src/main/rust/src/vulkan/parity_part6.rs@@ -510,4 +510,21 @@ fn blocked_int8_convs_agree_with_the_reference() { )), "{what} missed the blocked path"); compare(&format!("a blocked int8 {what}"), plan, source.data().to_vec(), &[&input]); }+}++/// A 1x1 with a fused PReLU on `conv_point.comp` (MobileFaceNet's projections): 20 channels+/// and 15x15 positions are ragged against the tile, and the slope is read per channel.+#[test]+#[ignore = "needs a Vulkan device"]+fn a_pointwise_conv_with_prelu_agrees_with_the_reference() {+ let input = spread(24 * 15 * 15, 3.0);+ let source = Invented::new(3);+ let plan = build(&source, &[Shape::new(24, 15, 15)], |b, ids| {+ b.conv(ids[0], 0, 20, (1, 1), (1, 1), (1, 1), (0, 0, 0, 0), 1, Act::PRelu(2))+ });+ assert!(plan.ops.iter().any(|op| matches!(+ op,+ crate::nets::Op::Dispatch { kind: crate::nets::Kind::ConvPoint, .. }+ )));+ compare("a pointwise conv with PReLU", plan, source.into_data(), &[&input]); }\ No newline at end of file