Merge branch 'lane-av1lambda' (c2e7f4af): LAMBDA_SCALE 0.1 -> 0.05 (swept: a clean bowl with its floor at 0.0375-0.05)
Browse files at this commit1 changed file +101 -6
- crates/ec-av1/src/encode.rs +101 -6
crates/ec-av1/src/encode.rsmodified+101 -6
| @@ -82,7 +82,39 @@ fn reach_sb_px(fctx: &crate::decode::FrameCtx) -> usize { | |||
| 82 | /// third sweep, after the levels were costed through the writer's own CDFs | 82 | /// third sweep, after the levels were costed through the writer's own CDFs |
| 83 | /// too, left it there: against 0.2 the ladders are worth -1.19% against -0.98% | 83 | /// too, left it there: against 0.2 the ladders are worth -1.19% against -0.98% |
| 84 | /// on film and -0.20% against -0.14% on screen capture. | 84 | /// on film and -0.20% against -0.14% on screen capture. |
| 85 | -const LAMBDA_SCALE: f64 = 0.1; | 85 | +/// |
| 86 | +/// The fourth sweep (lane-av1lambda) ran the BD gates themselves rather than | ||
| 87 | +/// those ladders, and 0.1 was far off the point: the rate term was carrying | ||
| 88 | +/// roughly twice the weight it is worth. 640x384 gate, BD-rate vs libaom / | ||
| 89 | +/// vs rav1e for 1080p film, 2160p film, screen capture: | ||
| 90 | +/// | ||
| 91 | +/// | lambda | 1080p | 2160p | screen | | ||
| 92 | +/// |--------|-------|-------|--------| | ||
| 93 | +/// | 0.0125 | +78.0 / +31.3 | +90.8 / +46.5 | +57.2 / -0.3 | | ||
| 94 | +/// | 0.025 | +71.5 / +28.4 | +87.0 / +46.5 | +50.4 / -3.8 | | ||
| 95 | +/// | 0.0375 | +71.2 / +28.5 | +84.3 / +45.4 | +48.7 / -4.4 | | ||
| 96 | +/// | 0.05 | +71.9 / +29.6 | +87.1 / +49.3 | +48.7 / -4.0 | | ||
| 97 | +/// | 0.075 | +74.8 / +32.7 | +91.3 / +52.8 | +51.4 / -1.3 | | ||
| 98 | +/// | 0.1 | +79.2 / +36.9 | +97.7 / +58.8 | +53.1 / -0.4 | | ||
| 99 | +/// | 0.125 | +84.0 / +41.1 | +100.7 / +61.5 | +56.8 / +2.3 | | ||
| 100 | +/// | 0.15 | +86.0 / +42.9 | +104.4 / +65.2 | +59.5 / +4.2 | | ||
| 101 | +/// | 0.2 | +89.6 / +45.5 | +109.9 / +69.8 | +62.3 / +7.3 | | ||
| 102 | +/// | ||
| 103 | +/// and on the native 1920x1024 crops, which is the table that decides: | ||
| 104 | +/// | ||
| 105 | +/// | lambda | film 1080p | film 2160p | screen | | ||
| 106 | +/// |--------|------------|------------|--------| | ||
| 107 | +/// | 0.025 | +17.1 / -0.5 | +49.0 / +21.1 | +51.5 / -15.1 | | ||
| 108 | +/// | 0.0375 | +16.3 / -1.0 | +47.5 / +19.7 | +50.7 / -15.1 | | ||
| 109 | +/// | 0.05 | +17.0 / -0.3 | +47.0 / +19.2 | +51.6 / -14.2 | | ||
| 110 | +/// | 0.1 | +18.1 / +0.9 | +47.1 / +19.0 | +58.3 / -9.8 | | ||
| 111 | +/// | ||
| 112 | +/// 0.0375 is the best point on two clips of three and costs the 2160p film | ||
| 113 | +/// +0.4/+0.7, outside the +-0.3 band every other lever here is kept inside, | ||
| 114 | +/// so 0.05 ships: two clips down on both columns, the 2160p film flat | ||
| 115 | +/// (-0.1 / +0.2). It also spends ~8% more encode wall, the bits it stopped | ||
| 116 | +/// refusing. | ||
| 117 | +const LAMBDA_SCALE: f64 = 0.05; | ||
| 86 | 118 | ||
| 87 | /// [`LAMBDA_SCALE`], or whatever `EC_AV1_LAMBDA` names when the sweep that | 119 | /// [`LAMBDA_SCALE`], or whatever `EC_AV1_LAMBDA` names when the sweep that |
| 88 | /// picks it is the thing running. A release build has no such knob. | 120 | /// picks it is the thing running. A release build has no such knob. |
| @@ -96,6 +128,41 @@ fn lambda_scale() -> f64 { | |||
| 96 | } | 128 | } |
| 97 | } | 129 | } |
| 98 | 130 | ||
| 131 | +/// How a key frame's lambda differs from an inter frame's: libaom weighs the | ||
| 132 | +/// two apart (`rd_frame_type_factor`, key 128 against an inter frame's 144 out | ||
| 133 | +/// of 128), because every later frame predicts from the key frame, so an error | ||
| 134 | +/// left in it is paid for over the whole group. This encoder has no temporal | ||
| 135 | +/// propagation model at all, and this factor is the cheapest stand-in for one. | ||
| 136 | +/// Swept by `EC_AV1_LAMBDA_KEY` in a test build, like [`lambda_scale`]. | ||
| 137 | +/// | ||
| 138 | +/// MEASURED and NOT KEPT. 640x384 gate at [`LAMBDA_SCALE`] 0.05, BD vs | ||
| 139 | +/// libaom / vs rav1e: | ||
| 140 | +/// | ||
| 141 | +/// | k_key | 1080p | 2160p | screen | | ||
| 142 | +/// |---|---|---|---| | ||
| 143 | +/// | 1.0 | +71.9 / +29.6 | +87.1 / +49.3 | +48.7 / -4.0 | | ||
| 144 | +/// | 0.85 | +71.5 / +29.4 | +87.0 / +48.3 | +49.7 / -3.9 | | ||
| 145 | +/// | 0.7 | +71.3 / +28.9 | +87.2 / +48.6 | +49.4 / -4.1 | | ||
| 146 | +/// | 0.5 | +71.4 / +28.9 | +88.7 / +49.6 | +50.1 / -3.4 | | ||
| 147 | +/// | ||
| 148 | +/// The two films want the key frame coded finer and the screen capture wants | ||
| 149 | +/// the opposite, by about the same amount, and at native the whole lever is | ||
| 150 | +/// inside the +-0.3 band that decides nothing: k_key 0.7 reads +16.9 / -0.3, | ||
| 151 | +/// +47.2 / +19.2, +51.4 / -14.7 against 1.0's +17.0 / -0.3, +47.0 / +19.2, | ||
| 152 | +/// +51.6 / -14.2. A gate whose GOP is one key frame in twelve cannot see a | ||
| 153 | +/// per-frame-type weight; the real lever here is temporal propagation | ||
| 154 | +/// (libaom's `tpl`), which weighs each BLOCK by how much of it later frames | ||
| 155 | +/// predict from, not each frame. | ||
| 156 | +const KEY_LAMBDA_FACTOR: f64 = 1.0; | ||
| 157 | + | ||
| 158 | +/// [`KEY_LAMBDA_FACTOR`], or what `EC_AV1_LAMBDA_KEY` names in a test build. | ||
| 159 | +fn key_lambda_factor() -> f64 { | ||
| 160 | + match std::env::var("EC_AV1_LAMBDA_KEY").ok().and_then(|v| v.parse::<f64>().ok()) { | ||
| 161 | + Some(k) if cfg!(test) => k, | ||
| 162 | + _ => KEY_LAMBDA_FACTOR, | ||
| 163 | + } | ||
| 164 | +} | ||
| 165 | + | ||
| 99 | // Every frame's predicted coefficient bits since the last | 166 | // Every frame's predicted coefficient bits since the last |
| 100 | // `take_predicted_bits`, in coding order -- the encoder half of | 167 | // `take_predicted_bits`, in coding order -- the encoder half of |
| 101 | // `predicted_coeff_bits_track_the_tile_the_writer_wrote`'s drift measurement. | 168 | // `predicted_coeff_bits_track_the_tile_the_writer_wrote`'s drift measurement. |
| @@ -2467,8 +2534,16 @@ impl Reach { | |||
| 2467 | /// film -- 85% of them, far past libaom's own rate -- and costs another 0.3 | 2534 | /// film -- 85% of them, far past libaom's own rate -- and costs another 0.3 |
| 2468 | /// BD points on top of the 0.4 the 32x32 candidate already costs. A tool | 2535 | /// BD points on top of the 0.4 the 32x32 candidate already costs. A tool |
| 2469 | /// that wins the local RD on five blocks in six and loses ladder bytes is | 2536 | /// that wins the local RD on five blocks in six and loses ladder bytes is |
| 2470 | -/// the `local-RD-on-references` class again, not a missing footprint. The | 2537 | +/// the `local-RD-on-references` class again, not a missing footprint. |
| 2471 | -/// tool stays OFF by default; the upgrade path is the price, not the size | 2538 | +/// |
| 2539 | +/// RE-MEASURED on lane-av1lambda at [`LAMBDA_SCALE`] 0.05 (min side 8): | ||
| 2540 | +/// +16.7 / -0.5, +47.1 / +19.2, +51.8 / -14.2 against the same build with | ||
| 2541 | +/// the knob off (+17.0 / -0.3, +47.0 / +19.2, +51.6 / -14.2). The 0.7-point | ||
| 2542 | +/// loss on the 1080p film became a 0.3-point win and the other two rows went | ||
| 2543 | +/// 0.1-0.2 the other way, so OBMC is now neutral rather than a loss -- half | ||
| 2544 | +/// of the "local win, ladder loss" it was charged with was the rate weight. | ||
| 2545 | +/// It still does not meet the keep rule (two down, one flat, both columns). | ||
| 2546 | +/// The tool stays OFF by default; the upgrade path is the price, not the size | ||
| 2472 | /// (the 640x384 arm reads +78.9/+36.4, +94.9/+56.3, +54.2/+0.8 at min side 8 | 2547 | /// (the 640x384 arm reads +78.9/+36.4, +94.9/+56.3, +54.2/+0.8 at min side 8 |
| 2473 | /// against +78.8/+36.1, +95.1/+56.4, +54.5/+1.1 off -- two rows down, the | 2548 | /// against +78.8/+36.1, +95.1/+56.4, +54.5/+1.1 off -- two rows down, the |
| 2474 | /// 1080p film up, i.e. the same disagreement between the two gates). | 2549 | /// 1080p film up, i.e. the same disagreement between the two gates). |
| @@ -2523,6 +2598,24 @@ fn motion_mode_bits(write_w: usize, write_h: usize, motion: u8, warp_alphabet: b | |||
| 2523 | /// candidate above it (`obmc_min_side`): a local RD win that does not convert | 2598 | /// candidate above it (`obmc_min_side`): a local RD win that does not convert |
| 2524 | /// into ladder bytes. | 2599 | /// into ladder bytes. |
| 2525 | /// | 2600 | /// |
| 2601 | +/// RE-MEASURED on lane-av1lambda, after [`LAMBDA_SCALE`] moved 0.1 -> 0.05, | ||
| 2602 | +/// because a tool whose gain is local and whose cost is the rate it adds is | ||
| 2603 | +/// exactly what a halved rate weight re-judges. The verdict FLIPS SIGN: | ||
| 2604 | +/// | ||
| 2605 | +/// | clip | warp on | off (both at lambda 0.05) | | ||
| 2606 | +/// |---|---|---| | ||
| 2607 | +/// | film 1080p | +16.7 / -0.5 | +17.0 / -0.3 | | ||
| 2608 | +/// | film 2160p | +47.0 / +19.1 | +47.0 / +19.2 | | ||
| 2609 | +/// | screen | +51.3 / -14.3 | +51.6 / -14.2 | | ||
| 2610 | +/// | ||
| 2611 | +/// two rows down against libaom (0.3 each) with the third flat, and the rav1e | ||
| 2612 | +/// column inside 0.1 everywhere -- which reads as a keep rather than the | ||
| 2613 | +/// 0.7/0.9 loss it was. The knob still ships OFF here: the margin is 0.3 BD | ||
| 2614 | +/// points on a table whose other levers move whole points, and turning warp | ||
| 2615 | +/// on by default is a stream-feature change (`enable_warped_motion` in the | ||
| 2616 | +/// sequence header) that wants its own conformance pass, not a lambda lane's | ||
| 2617 | +/// side effect. | ||
| 2618 | +/// | ||
| 2526 | /// The WARPED_CAUSAL prediction of one square single-reference block: the | 2619 | /// The WARPED_CAUSAL prediction of one square single-reference block: the |
| 2527 | /// decoder's own warp-sample walk (`decode::find_samples` + | 2620 | /// decoder's own warp-sample walk (`decode::find_samples` + |
| 2528 | /// `warp::select_samples`), least-squares model (`warp::find_projection`) and | 2621 | /// `warp::select_samples`), least-squares model (`warp::find_projection`) and |
| @@ -5261,7 +5354,7 @@ pub(crate) fn encode_key_frame_inner( | |||
| 5261 | let search = Search { | 5354 | let search = Search { |
| 5262 | base_q_idx, | 5355 | base_q_idx, |
| 5263 | deadzone, | 5356 | deadzone, |
| 5264 | - lambda: lambda_scale() * step * step, | 5357 | + lambda: lambda_scale() * key_lambda_factor() * step * step, |
| 5265 | modes, | 5358 | modes, |
| 5266 | top_k: prune_top_k(), | 5359 | top_k: prune_top_k(), |
| 5267 | screen, | 5360 | screen, |
| @@ -11342,7 +11435,9 @@ mod tests { | |||
| 11342 | /// decision change the BD gate judges. Re-pinned again on | 11435 | /// decision change the BD gate judges. Re-pinned again on |
| 11343 | /// lane-av1skipctx: the search now prices `txb_skip`/`dc_sign` at the | 11436 | /// lane-av1skipctx: the search now prices `txb_skip`/`dc_sign` at the |
| 11344 | /// real neighbour contexts ([`Plane::coef_ctx`]) instead of zero, which | 11437 | /// real neighbour contexts ([`Plane::coef_ctx`]) instead of zero, which |
| 11345 | - /// is the same kind of decision change. | 11438 | + /// is the same kind of decision change. Re-pinned on lane-av1lambda: |
| 11439 | + /// [`LAMBDA_SCALE`] moved 0.1 -> 0.05, so every RD decision in the | ||
| 11440 | + /// search moved with it. | ||
| 11346 | #[test] | 11441 | #[test] |
| 11347 | fn the_encoders_own_streams_are_byte_identical_to_their_pins() { | 11442 | fn the_encoders_own_streams_are_byte_identical_to_their_pins() { |
| 11348 | if !have_ffmpeg() { | 11443 | if !have_ffmpeg() { |
| @@ -11364,7 +11459,7 @@ mod tests { | |||
| 11364 | }) | 11459 | }) |
| 11365 | }; | 11460 | }; |
| 11366 | let pins: [(u8, usize, u64); 2] = | 11461 | let pins: [(u8, usize, u64); 2] = |
| 11367 | - [(150, 7141, 0x3a6a_df46_9b16_d9a7), (60, 25906, 0xbf71_9320_9e50_d237)]; | 11462 | + [(150, 7130, 0x0415_8aec_b26b_195a), (60, 26185, 0x9e7b_b2c7_672b_c381)]; |
| 11368 | for (q, bytes, hash) in pins { | 11463 | for (q, bytes, hash) in pins { |
| 11369 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); | 11464 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); |
| 11370 | assert_eq!( | 11465 | assert_eq!( |