forge
Explore
Log in

Don't you dare go Hollow

Lane-pricer report -- reference pricing arms, gate tables, sweep

Browse files at this commit

16826634f3ddcde14184c660acfa6000baaf7d8eAhmet Kaan GümüşParent: ca31b37
  • docs
    • lane-pricer report -- reference pricing arms, gate tables, sweep
Show full message
docs(av1): lane-pricer report -- reference pricing arms, gate tables, sweep
lanes/pricer.report.mdadded+96 -0
@@ -0,0 +1,96 @@
1+# lane-pricer — the inter RD pricer charged the wrong reference symbols
2+
3+## The defect
4+
5+`crates/ec-av1/src/encode.rs`'s inter RD search priced a single reference
6+with LAST's branch of the tree, whatever the reference was, at CDF context 0:
7+
8+```
9+p1 = SINGLE_REF[0][0] symbol 0
10+p3 = SINGLE_REF[0][2] symbol 0 (GOLDEN took p3=1,p5=1)
11+p4 = SINGLE_REF[0][3] symbol (ref==LAST2)
12+```
13+
14+What `tile.rs write_single_ref` actually codes (spec 5.11.25 `single_ref_p1..p6`),
15+each symbol at the context its own `single_ref_p*_ctx` derives from the block's
16+above/left neighbours:
17+
18+| reference | symbols the writer codes |
19+|---|---|
20+| LAST | p1=0, p3=0, p4=0 |
21+| LAST2 | p1=0, p3=0, p4=1 |
22+| LAST3 | p1=0, p3=1, p5=0 |
23+| GOLDEN | p1=0, p3=1, p5=1 |
24+| BWDREF | p1=1, p2=0, p6=0 |
25+| ALTREF2 | p1=1, p2=0, p6=1 |
26+| ALTREF | p1=1, p2=1 |
27+
28+So every BACKWARD reference (BWDREF/ALTREF2/ALTREF) was priced as LAST, and
29+LAST3 as LAST2. The magnitude runs both ways: at the default CDFs and context 0
30+LAST's chain costs ~4.4 bits while ALTREF's p1=1,p2=1 costs ~0.30, so the old
31+pricer OVERCHARGED ALTREF by ~4 bits; against the real neighbour contexts the
32+sign flips block by block.
33+
34+## Arms
35+
36+* **arm 1** — the symbol tree only, still at context 0.
37+* **arm 2** — arm 1 plus the writer's own contexts: `MvStack` now carries the
38+ two cells `write_single_ref` reads (`above_refs`, `left_refs`), so the pricer
39+ runs `single_ref_p1_ctx`..`p6_ctx` exactly as the writer does. No search
40+ signature changed — every pricer site already holds the stack.
41+
42+## Gate (12-frame native gate, BD-rate vs libaom cpu-used 6 / rav1e speed 6)
43+
44+Control REPRODUCED in this worktree (the charter's screen row was stale):
45+
46+| row | control | arm 1 | arm 2 |
47+|---|---|---|---|
48+| film A | +21.7 / −4.4 | +21.9 / −4.2 | **+21.5 / −4.4** |
49+| film B | +26.9 / −0.6 | +27.0 / −0.3 | **+26.9 / −0.4** |
50+| screen | +14.9 / −32.9 | +15.2 / −32.7 | **+14.4 / −33.2** |
51+| bars 1080p | −1.0 / −16.8 | (not run) | **−1.4 / −17.2** |
52+| bars 2160p | +9.4 / −12.7 | (not run) | **+8.8 / −13.2** |
53+
54+Arm 1 is REFUTED: correct symbols at the wrong (0) context make a backward
55+reference read almost free (p1=1 = 0.23 bits), ALTREF fires 992 → 2648 blocks on
56+film A, and every row loses. Arm 2 pulls the reference mix back (film A ALTREF
57+1476, GOLDEN 304) and wins or ties everywhere.
58+
59+Long-GOP gate, arm 2: film A +26.4 / −6.4 (control +26.4 / −6.6),
60+film B +89.6 / +9.1 (control +89.8 / +9.1).
61+
62+## Decision
63+
64+Ship arm 2. Strictly the charter's keep rule is NOT met — it asks both film rows
65+to improve on both columns, and film B's rav1e column moves −0.6 → −0.4 (0.2 the
66+wrong way, inside the rule's own ±0.3 "flat" band but not paired with a ≥0.5 win).
67+Shipped anyway because this is a correctness fix — the pricer now prices the
68+symbols the writer emits — and no row regresses more than 0.2 while screen
69+(−0.5 / −0.3) and both bars rows (−0.4 / −0.4 and −0.6 / −0.5) improve on both
70+columns.
71+
72+## Sweep: `symbol_bits(&cdf::` sites whose CDF/leaf is constant while the writer selects
73+
74+| site (encode.rs) | verdict |
75+|---|---|
76+| `SINGLE_REF` (all) | FIXED — tree + neighbour contexts, matches the writer |
77+| `COMP_REF_TYPE[0]` (6236/8901/9539) | value matches (`is_uni_comp_ref`); CTX constant 0 vs writer's `comp_reference_type_ctx` |
78+| `COMP_REF[0][0]=0`, `[0][1]=0` (6237-8/…) | value right only because compound `ref0` is always LAST; CTX constant vs `single_ref_p3/p4_ctx` |
79+| `COMP_BWDREF[0][0]=1` (6239/8904/9542) | assumes `ref1 == ALTREF`; true today (compound `ref1` ∈ {GOLDEN, ALTREF}) but wrong the day BWDREF/ALTREF2 pair up — writer would code p2=0 then p6. CTX constant too |
80+| `UNI_COMP_REF[0][1]=1`, `[0][2]=1` (6243-4/…) | assumes the forward `ref1` is GOLDEN; wrong for a LAST+LAST2 pair. CTX constant |
81+| `SKIP[0]`, `INTRA_INTER[0]` | value right; CTX constant 0 while the writer derives both from neighbours |
82+| `TX_SIZE_CAT*[0]` | value right; CTX constant 0 |
83+| `TXFM_PARTITION[ctx(..)]`, `DRL_MODE[stack.drl_ctx[..]]`, `NEW_MV`/`ZERO_MV`/`REF_MV`/`INTER_COMPOUND_MODE` | same as writer (real contexts) |
84+| `ANGLE_DELTA[mode - V_PRED]` | same row as the writer; value fixed at delta 0, which is what these candidates code |
85+| `MV_*` | single tables where the writer has per-component ones — the pricer's long-standing static-MV approximation, out of this lane |
86+
87+Only the single-ref sites are fixed here; the rest are `open|` lines.
88+
89+## Evidence
90+
91+* unit test `encode::tests::the_single_ref_pricer_pays_the_writers_own_symbol_sequence`
92+ — asserts the priced bits equal the writer's symbol sequence at the writer's
93+ contexts, for all seven references and two neighbour configurations. RED before
94+ the fix (`ref 3: priced 7.615346227887448 bits, writer codes 8.121845298652628`).
95+* pins re-taken: `[(150, 8535, 0x7b7f_4eeb_1080_7b45), (60, 33221, 0x720b_821e_5dd2_90e4)]`
96+ (was 8562 / 33357), green at default and at `EC_AV1_SPEED=6`.