Skip to content

[pipeline] Add batched routing to path_variants - #1595

Merged
mthrok merged 1 commit into
mainfrom
batched-router
Jul 20, 2026
Merged

[pipeline] Add batched routing to path_variants#1595
mthrok merged 1 commit into
mainfrom
batched-router

Conversation

@mthrok

@mthrok mthrok commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Add a batched option to PathVariants and PipelineBuilder.path_variants.

When set, the router receives a whole batch (a list) and returns one path index per element; the batch is partitioned into per-path sub-batches (order preserved), each path processes its sub-batch as a list, and the fan-in merge concatenates the sub-batches back into one batch.

Per-item routing pays the router + fan-out/fan-in machinery once per element. For workloads that route in bulk -- e.g. a cache hit/miss split over an already-aggregated batch -- that fixed per-item cost dominates. Batched routing amortizes it over the whole batch: the router runs once per batch, each branch runs its ops once per batch, and one list (not one item) crosses each queue per batch.

Semantics:

  • Each input batch contributes exactly one sub-batch (possibly empty) to every path queue, so the queues stay in lockstep and the merge recombines an input batch's sub-batches by reading one list from each path.
  • A branch may drop elements by returning a shorter list, and must tolerate an empty input list (a path that received no elements for a batch).
  • A batched router must return exactly one index per element; otherwise the stage fails.

batched defaults to False, so existing per-item behavior is byte-identical (not backward-incompatible).

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 19, 2026
@meta-codesync

meta-codesync Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D112745035. (Because this pull request was imported automatically, there will not be any future comments.)

Add a `batched` option to `PathVariants` and `PipelineBuilder.path_variants`.

When set, the router receives a whole batch (a list) and returns one path index
per element; the batch is partitioned into per-path sub-batches (order
preserved), each path processes its sub-batch as a list, and the fan-in merge
concatenates the sub-batches back into one batch.

Per-item routing pays the router + fan-out/fan-in machinery once per element.
For workloads that route in bulk -- e.g. a cache hit/miss split over an
already-aggregated batch -- that fixed per-item cost dominates. Batched routing
amortizes it over the whole batch: the router runs once per batch, each branch
runs its ops once per batch, and one list (not one item) crosses each queue per
batch.

Semantics:
- Each input batch contributes exactly one sub-batch (possibly empty) to every
  path queue, so the queues stay in lockstep and the merge recombines an input
  batch's sub-batches by reading one list from each path.
- A branch may drop elements by returning a shorter list, and must tolerate an
  empty input list (a path that received no elements for a batch).
- A batched router must return exactly one index per element; otherwise the
  stage fails.

`batched` defaults to `False`, so existing per-item behavior is byte-identical
(not backward-incompatible).
@mthrok
mthrok merged commit 4fc5ed8 into main Jul 20, 2026
78 of 80 checks passed
@mthrok
mthrok deleted the batched-router branch July 20, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant