Skip to content

Gate partition ML/pruning in fast two pass partitions - #5317

Open
yeqing-wu wants to merge 1 commit into
AOMediaCodec:av2-encfrom
yeqing-wu:sb_tpp_ml_pruning_strategy_submission_merge
Open

Gate partition ML/pruning in fast two pass partitions#5317
yeqing-wu wants to merge 1 commit into
AOMediaCodec:av2-encfrom
yeqing-wu:sb_tpp_ml_pruning_strategy_submission_merge

Conversation

@yeqing-wu

Copy link
Copy Markdown
Contributor

This newly activates fast two pass partition for speed=2, while improving speed-quality ratio for speed=3/4.

Some of the partition ML/pruning schemes interact poorly with the fast two-pass partition search, so skip them in the dry pass and on trusted wet-pass blocks. The full policy across regimes:

  • FAST dry pass: disabled. Shape is picked from reduced-tool
    RD, and the dry pass is already fast.
  • FAST wet pass, forced: disabled. Partition is already fixed by the
    dry-pass template; the decision is discarded.
  • FAST wet pass, reopened: enabled. Block is genuinely searched.
  • CONSERVATIVE / one-pass: enabled. Predicate is inert on this path.

Anchor: commit 7361d54
Speed 4 (cpu-used=4): FG16 CTC (33 frames, class A1 and A2, RA)
Speed 3 (cpu-used=3): FG16 CTC (33 frames, class A1 and A2, RA)
Speed 2 (cpu-used=2): FG16 CTC (33 frames, class A1 and A2, RA)

1) Speed 4 (cpu-used=4)
  +------------+-------+-------+-------+-------+------+------+
  | Class      |     Y |    Cb |    Cr |  wAvg | Enc% | Dec% |
  +------------+-------+-------+-------+-------+------+------+
  | A1         | -0.73 |  0.26 | -0.05 | -0.66 |  106 |  101 |
  | A2         | -0.49 |  0.22 |  0.20 | -0.43 |  105 |  101 |
  | Avg w/o B2 | -0.56 |  0.23 |  0.12 | -0.50 |  105 |  101 |
  +------------+-------+-------+-------+-------+------+------+

2) Speed 3 (cpu-used=3)
  +------------+-------+-------+-------+-------+------+------+
  | Class      |     Y |    Cb |    Cr |  wAvg | Enc% | Dec% |
  +------------+-------+-------+-------+-------+------+------+
  | A1         | -0.75 |  0.08 |  0.17 | -0.68 |  106 |  101 |
  | A2         | -0.47 |  0.18 | -0.15 | -0.43 |  104 |  100 |
  | Avg w/o B2 | -0.55 |  0.15 | -0.05 | -0.51 |  105 |  100 |
  +------------+-------+-------+-------+-------+------+------+

3) Speed 2 (cpu-used=2)
  +------------+-------+-------+-------+-------+------+------+
  | Class      |     Y |    Cb |    Cr |  wAvg | Enc% | Dec% |
  +------------+-------+-------+-------+-------+------+------+
  | A1         | -0.50 | -2.10 | -2.72 | -0.65 |   84 |   87 |
  | A2         |  0.46 |  1.97 |  1.60 |  0.56 |   83 |   95 |
  | Avg w/o B2 |  0.17 |  0.76 |  0.32 |  0.20 |   84 |   93 |
  +------------+-------+-------+-------+-------+------+------+

STATS_CHANGED

This newly activates fast two pass partition for speed=2, while
improving speed-quality ratio for speed=3/4.

Some of the partition ML/pruning schemes interact poorly with the
fast two-pass partition search, so skip them in the dry pass and on
trusted wet-pass blocks. The full policy across regimes:

  * FAST dry pass:            disabled. Shape is picked from reduced-tool
                              RD, and the dry pass is already fast.
  * FAST wet pass, forced:    disabled. Partition is already fixed by the
                              dry-pass template; the decision is discarded.
  * FAST wet pass, reopened:  enabled. Block is genuinely searched.
  * CONSERVATIVE / one-pass:  enabled. Predicate is inert on this path.

Anchor: commit 7361d54
Speed 4 (cpu-used=4): FG16 CTC (33 frames, class A1 and A2, RA)
Speed 3 (cpu-used=3): FG16 CTC (33 frames, class A1 and A2, RA)
Speed 2 (cpu-used=2): FG16 CTC (33 frames, class A1 and A2, RA)

```
1) Speed 4 (cpu-used=4)
  +------------+-------+-------+-------+-------+------+------+
  | Class      |     Y |    Cb |    Cr |  wAvg | Enc% | Dec% |
  +------------+-------+-------+-------+-------+------+------+
  | A1         | -0.73 |  0.26 | -0.05 | -0.66 |  106 |  101 |
  | A2         | -0.49 |  0.22 |  0.20 | -0.43 |  105 |  101 |
  | Avg w/o B2 | -0.56 |  0.23 |  0.12 | -0.50 |  105 |  101 |
  +------------+-------+-------+-------+-------+------+------+

2) Speed 3 (cpu-used=3)
  +------------+-------+-------+-------+-------+------+------+
  | Class      |     Y |    Cb |    Cr |  wAvg | Enc% | Dec% |
  +------------+-------+-------+-------+-------+------+------+
  | A1         | -0.75 |  0.08 |  0.17 | -0.68 |  106 |  101 |
  | A2         | -0.47 |  0.18 | -0.15 | -0.43 |  104 |  100 |
  | Avg w/o B2 | -0.55 |  0.15 | -0.05 | -0.51 |  105 |  100 |
  +------------+-------+-------+-------+-------+------+------+

3) Speed 2 (cpu-used=2)
  +------------+-------+-------+-------+-------+------+------+
  | Class      |     Y |    Cb |    Cr |  wAvg | Enc% | Dec% |
  +------------+-------+-------+-------+-------+------+------+
  | A1         | -0.50 | -2.10 | -2.72 | -0.65 |   84 |   87 |
  | A2         |  0.46 |  1.97 |  1.60 |  0.56 |   83 |   95 |
  | Avg w/o B2 |  0.17 |  0.76 |  0.32 |  0.20 |   84 |   93 |
  +------------+-------+-------+-------+-------+------+------+
```

STATS_CHANGED
@urvangjoshi

Copy link
Copy Markdown
Contributor

@yeqing-wu : I have a general question related to the fast two pass method:
Have you tested to make sure it works as expected when extended partitions (H partitions, for example) are turned on?

Reason for asking:

  • On top of commit 44be072 (today), if I try to enable extended partitions at all speeds:
    • At speed 4, seeing a loss (e.g. 0.43% loss on A5 set) instead of gain (despite 119% enc-time) <-- unexpected
    • At speed 2, seeing a gain as expected

Given that fast two pass is enabled for speed >= 3 on that commit, I'm trying to understand something isn't fundamentally broken with this feature in combination with extended partitions.

It's more important to double check this, as you move the feature to speed 2.

Note: On commit 2abcfff (~1 week ago), the behavior was as expected (gain at both speed 2 and 4)

@yeqing-wu

Copy link
Copy Markdown
Contributor Author

Hi @urvangjoshi, thanks for your information. I haven’t conducted any special tests with the extended partitions turned on. All my tests are based on the default speed features in the av2-enc branch.

Before I run the tests, let me confirm a few things:

  1. Is my understanding correct that the extended partitions are turned off for speed >= 2 by sf->part_sf.disable_ext_partitions?
  2. How much gain did you observe in speed 2 when you turned on the extended partitions?
  3. Did you remember the gain of the extended partitions on speed >= 3 before applying the fast two-pass partition if you already did that?

Thanks
Yeqing

@urvangjoshi

Copy link
Copy Markdown
Contributor

Hi @urvangjoshi, thanks for your information. I haven’t conducted any special tests with the extended partitions turned on. All my tests are based on the default speed features in the av2-enc branch.

Before I run the tests, let me confirm a few things:

  1. Is my understanding correct that the extended partitions are turned off for speed >= 2 by sf->part_sf.disable_ext_partitions?

Correct. For my tests, I basically moved this speed feature to speed 5 (to test gains on speed 2, 3 and 4).

  1. How much gain did you observe in speed 2 when you turned on the extended partitions?
  2. Did you remember the gain of the extended partitions on speed >= 3 before applying the fast two-pass partition if you already did that?

The coding gains when enabling ext-partitions (on top of commit 2abcfff) were as follows (33 frames RA, all classes without B2):

  • Speed 4: -0.43% at 118% enc-time
  • Speed 3: -0.46% at 126% enc-time
  • Speed 2: -0.45% at 127% enc-time

The ratio isn't good enough to directly make this change, but I'm thinking about possible pruning methods to get some of the gains.

Thanks Yeqing

@yeqing-wu

yeqing-wu commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Got it. I can run some tests with sf->part_sf.disable_ext_partitions = false.

By the way, when part_sf.disable_ext_partitions is set to true, how many partition shapes would be disabled? There’s no comment in the code explaining this, so could you please elaborate on it? Does it disable all 3-ways and 4-ways partitions?

@urvangjoshi

Copy link
Copy Markdown
Contributor

Got it. I can run some tests with sf->part_sf.disable_ext_partitions = false.

By the way, when part_sf.disable_ext_partitions is set to true, how many partition shapes would be disabled? There’s no comment in the code explaining this, so could you please elaborate on it? Does it disable all 3-ways and 4-ways partitions?

This will only enable the HORZ_3 / VERT_3 (that is, H shaped) partitions.
[The 4A/4B partitions are disabled for speed >= 1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants