forge
Explore
Log in

Don't you dare go Hollow

Lane-split report -- the split lambda swept, control wins, census shipped

Browse files at this commit

d8a0bf959b1dfa45014e16bc09897324957cde82Ahmet Kaan GümüşParent: 9c0f629
  • docs
    • lane-split report -- the split lambda swept, control wins, census shipped
Show full message
docs(av1): lane-split report -- the split lambda swept, control wins, census shipped

Also extracts split_census_base and enumerates its whole domain in a test.
crates/ec-av1/src/encode.rsmodified+28 -3
@@ -4283,6 +4283,13 @@ pub(crate) fn split_census_on() -> bool {
42834283 *ON
42844284 }
42854285
4286+/// Where one (site, frame type, block side) bucket starts in [`SPLIT_CENSUS`].
4287+/// Sides below 8 and above 64 fold into the end rows, which no caller offers.
4288+fn split_census_base(site: usize, key: bool, side: usize) -> usize {
4289+ let side_idx = (side.trailing_zeros() as usize).saturating_sub(3).min(3);
4290+ ((site * 2 + usize::from(!key)) * 4 + side_idx) * 10
4291+}
4292+
42864293 /// Records one split trial into [`SPLIT_CENSUS`]. `split` and `flat` are each
42874294 /// `(rate in bits, distortion as squared error)`.
42884295 fn split_census(
@@ -4294,8 +4301,7 @@ fn split_census(
42944301 flat: (f64, f64),
42954302 ) {
42964303 use std::sync::atomic::Ordering::Relaxed;
4297- let side_idx = (side.trailing_zeros() as usize).saturating_sub(3).min(3);
4298- let base = ((site * 2 + usize::from(!key)) * 4 + side_idx) * 10;
4304+ let base = split_census_base(site, key, side);
42994305 let add = |i: usize, v: u64| {
43004306 SPLIT_CENSUS[base + i].fetch_add(v, Relaxed);
43014307 };
@@ -4326,7 +4332,7 @@ pub(crate) fn dump_split_census() {
43264332 for site in 0..2 {
43274333 for key in [true, false] {
43284334 for side_idx in 0..4 {
4329- let base = ((site * 2 + usize::from(!key)) * 4 + side_idx) * 10;
4335+ let base = split_census_base(site, key, 8 << side_idx);
43304336 let v: [u64; 10] = std::array::from_fn(|i| SPLIT_CENSUS[base + i].load(Relaxed));
43314337 if v[0] == 0 {
43324338 continue;
@@ -12314,6 +12320,25 @@ pub(crate) fn encode_sequence_with_ctx(
1231412320 #[cfg(test)]
1231512321 mod tests {
1231612322
12323+ /// Every (site, frame type, block side) the census can be called with
12324+ /// lands in its own ten-counter bucket, inside the array (class
12325+ /// `enumerate-table-domain`: an off-by-one here would silently add two
12326+ /// sites' trials together).
12327+ #[test]
12328+ fn the_split_census_buckets_are_distinct_and_in_bounds() {
12329+ let mut seen = std::collections::BTreeSet::new();
12330+ for site in 0..2 {
12331+ for key in [true, false] {
12332+ for side in [8usize, 16, 32, 64] {
12333+ let base = super::split_census_base(site, key, side);
12334+ assert!(base + 10 <= super::SPLIT_CENSUS.len(), "{site} {key} {side}");
12335+ assert!(seen.insert(base), "{site} {key} {side} collides");
12336+ }
12337+ }
12338+ }
12339+ assert_eq!(seen.len(), 16);
12340+ }
12341+
1231712342 /// An [`crate::mvstack::MvStack`] with every context at zero and no
1231812343 /// neighbours, for the pricer tests below to fill the one band each of
1231912344 /// them is about.
lanes/split.report.mdadded+130 -0
@@ -0,0 +1,130 @@
1+# lane-split — the split decision's own calibration: swept, and the control wins
2+
3+lane-txd left one live hypothesis behind its refuted arm (class
4+`rd-rate-term-calibration`): the correct `tx_depth` price is a one-sided push
5+AWAY from splitting, so maybe what is mis-calibrated is the weight the split
6+trial's rate is judged under, not the price. This lane restored the correct
7+pricing (`60c3cdf6` + its pins), built the knob and the census, and swept.
8+The sweep is single-peaked and its peak IS the control weight, and every
9+point on it is worse than the row-0-priced control. The pricing fix goes back
10+out again; the census and the swept knob stay.
11+
12+## The knob
13+
14+`EC_AV1_SPLIT_LAMBDA` (`encode::split_lambda_mult`, constant `SPLIT_LAMBDA =
15+1.0`) multiplies the RATE term of the transform-SPLIT trial only — the intra
16+`tx_depth` depth>0 candidates in `code_square` and the inter var-tx depth-1
17+trial in `commit_inter_luma`. Below 1 the split is charged less for its bits
18+and fires more; above 1, less. The flat arm is untouched, so this is exactly
19+the depth-0-versus-split margin and nothing else.
20+
21+## Sweep — film B gate row, WITH the correct `tx_depth` pricing on
22+
23+Deciding gate, 12-frame native, BD-rate vs libaom cpu-used 6 / rav1e speed 6.
24+
25+| `EC_AV1_SPLIT_LAMBDA` | film B | bars 2160p |
26+|---|---|---|
27+| 0.6 | +28.4 / +0.5 | +10.5 / −11.8 |
28+| 0.8 | +26.1 / −0.9 | +10.0 / −12.2 |
29+| **1.0 (control weight)** | **+25.2 / −1.6** | **+8.7 / −13.4** |
30+| 1.25 | +25.9 / −1.1 | +8.9 / −13.2 |
31+| 1.5 | +26.2 / −0.9 | +9.3 / −13.0 |
32+| 2.0 | +26.3 / −0.8 | +11.7 / −11.4 |
33+| — control, row-0 pricing (`2caf213b`) | **+24.9 / −1.9** | +8.7 / −13.4 |
34+
35+The λ=1.0 row reproduces lane-txd's arm to the decimal, so the sweep is
36+against a reproduced control. The curve has ONE optimum, it sits at the
37+weight the encoder already uses, and it is still 0.3 worse on both columns
38+than the row-0-priced control. No re-weighting of the split's rate recovers
39+what correct pricing costs — so the split trial's λ was not the mis-calibrated
40+term either, and the class `rd-rate-term-calibration` reading of lane-txd's
41+result is refuted on its own terms.
42+
43+## Census 1 — the split DECISION (`EC_AV1_SPLIT_CENSUS=1`)
44+
45+Film B gate crop, 12 frames, q150, the shipped (row-0-priced) encoder. Rows
46+are TRIALS OFFERED by the RD search, which includes partition candidates that
47+later lose — not coded blocks; the coded-block view is census 2 below.
48+
49+```
50+site frame side offered split share% win_rate win_dist lose_rate lose_dist
51+intra key 16 7504 1671 22.3 19.07 335 25.97 444
52+intra key 32 1876 166 8.8 62.25 1381 78.58 1553
53+intra inter 8 12424 4620 37.2 9.26 362 10.26 533
54+intra inter 16 4704 942 20.0 23.29 1714 28.73 2109
55+inter inter 16 1711 167 9.8 14.96 1480 21.14 1741
56+inter inter 32 936 250 26.7 37.86 5869 38.32 6302
57+inter inter 64 5280 483 9.1 15.77 8333 16.02 8461
58+```
59+
60+`win_rate`/`lose_rate` are bits (including the `tx_depth` / `txfm_split`
61+symbols), `win_dist`/`lose_dist` squared error. Read: the winner is cheaper on
62+BOTH terms in every row — the loser is never a rate-versus-distortion trade
63+the weight could tip, which is the same thing the sweep says from the outside.
64+
65+With the correct pricing ON the shares fall exactly where lane-txd's price
66+table predicts (intra key 16: 22.3% → 21.0%, intra inter 8: 37.2% → 32.9%,
67+inter var-tx 32: 26.7% → 27.9%) — a 4-point drop on the inter frame's intra
68+blocks, which are the 66% ctx-2 population.
69+
70+## Census 2 — ours vs libaom, coded blocks, same crop and rate
71+
72+Both streams read by OUR decoder (`EC_AV1_BITCENSUS=1 syntax_census`), film B
73+gate crop 1920x1024 @ 00:40:00, 12 frames, `-g 12`. Ours q150 = 27343 payload
74+bytes; libaom `-cpu-used 6 -crf 30` = 28590. Split share = the share of coded
75+blocks whose PUBLISHED luma transform is smaller than the block, read as the
76+mass the tx-size histogram moves down against the block-size histogram.
77+
78+| | key frame | whole stream |
79+|---|---|---|
80+| ours | 4.8% | 1.0% |
81+| libaom crf 30 | 7.6% | 2.1% |
82+
83+libaom splits about twice as often as we do at the same rate — so we are on
84+the LOW side of libaom's split rate, and the sweep says every step toward
85+libaom's rate (λ 0.8, 0.6) costs 1.2 and 3.5 BD points on film B. The split
86+rate is not where film B's +25% lives; a lane that goes after it by moving
87+this margin is measuring the wrong knob.
88+
89+## Gate — the shipped tree
90+
91+Encoder output is BYTE-IDENTICAL to `2caf213b` (both stream pins green and
92+UNMOVED at 8325 / 33014, at the default preset and at `EC_AV1_SPEED=6`), so
93+the rows are the control's, re-measured here:
94+
95+| row | shipped |
96+|---|---|
97+| film A | +21.0 / −4.8 |
98+| film B | +24.9 / −1.9 |
99+| screen | +14.5 / −33.2 |
100+| bars 1080p | −2.0 / −17.6 |
101+| bars 2160p | +8.7 / −13.4 |
102+
103+`bd_rate_film_long_gop` was not run: nothing ships that moves a byte.
104+
105+## Suite
106+
107+* `--skip stream::` 338 passed / 0 failed / 32 ignored; `stream:: --skip
108+ 10bit` 200 / 0 / 15; `10bit` 42 / 0 / 1. All RC=0.
109+* `--ignored encoder::tests::every_speed_preset_decodes_sample_exact_through_both_decoders`
110+ passed.
111+* `encode::tests::the_split_census_buckets_are_distinct_and_in_bounds` — the
112+ census index enumerated over its whole domain (class
113+ `enumerate-table-domain`).
114+* `timeout 900 cargo check --workspace --all-targets -j4`: 0 errors, 0 ec-av1
115+ warnings.
116+
117+## Disposition
118+
119+`deferred: the tx_depth context pricing — built twice (lane-ctx2, lane-txd),
120+now swept against its own split weight and still losing at every point. What
121+would unblock it is NOT another calibration knob on this margin: the census
122+says the losing arm is worse on rate AND distortion together, so the depth
123+trial is choosing between two arms the search already separates cleanly.
124+Whatever film B's +25% is, it is not the transform-split margin.`
125+
126+`deferred: a bug found while building the census — encoder.rs used
127+bool::then_some to build a Drop guard, which CONSTRUCTS and then DROPS the
128+guard when the flag is off. Fixed here (then_some -> then); no other
129+then_some in the crate builds a value with a Drop impl (grep: 3 hits, all
130+Copy scalars).`