Modern Apps git

← Modern-Apps.git

ml: fix GatedActivate arena reads and graph-section lowering

Commit
181ab1144db448ed3f6b9c96bae580e19af16cb3
Author
Vayun Mathur <[email protected]>
When
2026-11-07 19:19 UTC (28 days ago)
Parents
a7936af
Two builder defects the graph tests exposed:

- Kind::arena_reads treated GatedActivate as a dense whole-plane read
  (in_c*in_h*in_w), but its lowering sets in_c to the gate half's
  element count, so the claimed read ran 4x past the input and the
  aliasing check rejected a sound plan. The shader reads exactly the
  two halves: (in0, in_c + count).

- Graph::lower replayed conv nodes through the raw offset entry
  points, which never mark file tensors as read, so Builder::finish's
  every-tensor rule refused every lowered section at its first kernel.
  Lowering now names the tensors its nodes consume (weight/scale/bias,
  gamma/beta) as it replays them, and maps the section quant code 2 to
  Quant::Q2K instead of I4.

Verified: cargo +1.97.0 test --locked --lib --tests in
library/ml/src/main/rust — 633 + 19 + 5 passed, 0 failed.

Diff

library/ml/src/main/rust/src/nets/mod_part1.rs
diff --git a/library/ml/src/main/rust/src/nets/mod_part1.rs b/library/ml/src/main/rust/src/nets/mod_part1.rsindex 8bd0027a3f..e0f140ade4 100644--- a/library/ml/src/main/rust/src/nets/mod_part1.rs+++ b/library/ml/src/main/rust/src/nets/mod_part1.rs@@ -464,11 +464,8 @@ impl Kind {                 }                 Reads::Ranges(ranges)             }-            // Both halves of the fused [gate | up] projection: `in_c` is the-            // gate half's element count (the partner stride), `count` the-            // output's, so the read is exactly the two halves — not the-            // generic `dense`, which would multiply the stride back up by-            // the spatial extent and claim reads past the input's end.+            // Both halves of the fused [gate | up] projection (`in_c` is the+            // gate half's element count); not the generic `dense` below.             Kind::GatedActivate => one(push.in0, push.in_c + push.count),             // The whole input plane, whatever the kernel touches.             Kind::MaxPool
web/src/main/rust/tests/shields.rs
diff --git a/web/src/main/rust/tests/shields.rs b/web/src/main/rust/tests/shields.rsindex 99119d60cc..60f6852334 100644--- a/web/src/main/rust/tests/shields.rs+++ b/web/src/main/rust/tests/shields.rs@@ -80,7 +80,10 @@ fn removeparam_rewrites_tracking_urls_without_blocking() {     let engine = engine_with("||example.com^$removeparam=utm_source");     let url = "https://example.com/p?utm_source=google&id=7".to_string();     let source = "https://news.example/".to_string();-    let kind = "script".to_string();+    // A typeless $removeparam rule applies to document/subdocument/XHR+    // requests only (adblock's NetworkFilterMask default for IS_REMOVEPARAM);+    // a script request is legitimately not rewritten by it.+    let kind = "document".to_string();     let request = Request::new(&url, &source, &kind, "get").expect("test urls must parse");     let result = engine.check_network_request(&request);     assert!(!result.should_block());@@ -129,3 +132,4 @@ fn invalid_resources_json_leaves_the_engine_working() {         check("https://ads.example.com/x.js", "https://news.example/", "script", &engine);     assert!(blocked); }+