Repository navigation
perf(batch): batch diarization and VAD across a worker flight - #22368
Conversation
The locked GPU chain ran community-1 segmentation twice per unit (inside VAD and again inside diarization) and the WeSpeaker ResNet trunk once per (chunk, local speaker) pair, although the three local speakers of a chunk share one waveform. FlightPyannote removes that duplicated model work and packs the remaining forwards across one flight's units: - one raw segmentation pass per unit feeds VAD (CPU aggregation and binarization, same as VoiceActivityDetection.apply) and diarization (get_segmentations hook); - one trunk forward per 10s chunk, pooled per local speaker with the same masks (get_embeddings hook); - chunks pack across units at the pinned model batch size, so no forward is larger than the serial one and peak VRAM does not grow. Clustering, reconstruction and labels stay pyannote's own per-unit apply. Units above BATCH_PIPELINE_FLIGHT_BATCH_SECONDS (default 1800), unsupported model layouts, non-fatal packed failures and CUDA OOM inside the packed path take the unchanged serial calls; other fatal CUDA errors still quarantine the chain. BATCH_PIPELINE_FLIGHT_BATCHING_ENABLED is a kill switch, on by default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
CI note: two failures are pre-existing on origin/main 0d8e125 and are not caused by this PR. Both reproduce locally on a clean detached origin/main worktree with no changes from this PR:
The stack gauntlet does not construct flight models, so it runs the serial worker path. I merged origin/main into the branch (644e436). |
# Conflicts: # backend/diarizer/batch_pipeline.py # config/deployment-setting-classification.json
|
CI at 33f49ff (merged origin/main, including #22352). Every remaining failure is pre-existing on origin/main 267b255. I reproduced each one on a clean detached main worktree with none of this PR's changes:
The Hermetic Merge Gate and Backend unit suite failures are aggregates of these. The batch_pipeline flight, worker, worker_io, runtime, chart and disposition suites all pass (201 passed). Merge resolution with #22352: when flight packing is off, decode and VAD stay interleaved per item, so prefetch still overlaps them. When packing is on, the group is decoded through prefetch, then one packed segmentation pass runs. Async persist still bounds in-flight writes in the final loop. |
Review: CPU equivalence on random weights does not cover the L4. Packing moves a unit's tail chunk out of its own batch-of-one forward, so cuDNN may choose another kernel; on the production checkpoint that is unmeasured. - BATCH_PIPELINE_FLIGHT_BATCHING_ENABLED now defaults off in code, env parsing (only the exact value true enables it), Helm and the registry (rollout, fail closed, review_by 2026-10-26). - A cached-embedding shape mismatch now recomputes serially instead of failing the item. - diarizer/batch_pipeline_flight_qualify.py: paired serial vs packed run on one L4 with community-1 3533c8cf and batch pin 8 over a mixed-length multi-speaker flight. Gates on VAD span equality, speaker counts, speaker-assignment agreement and the CUDA peak of both paths. - load_pyannote_pair is shared by the worker and the qualification, so both build identical models. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ker-gpu Compose flight packing with speech-only diarization. When speech-only is on, the compacted waveform keeps its serial pyannote apply: there is no full-unit packed embedding or cached segmentation, and the uncached get_embeddings hook uses the per-file shared trunk only. Packed segmentation still feeds VAD. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # backend/docs/feature-flag-registry.md
Re-review: the gate compared the shared trunk with itself, scored a path that speech-only skips, and failed open. - Serial references (VAD, diarization, compacted diarization, raw segmentation, embeddings) are captured on the unpatched pipeline before FlightPyannote.create, in the qualify script and in the CPU test. - The gate scores two configurations. speech_only (Helm default) runs packed VAD and then the worker's own _diarize_unit on the compacted waveform through the per-file trunk hook. full_unit runs diarize_many. The exit status follows the deployment's speech-only setting, so a full_unit pass cannot authorize the flag while speech-only is on. - Fail closed: an unpacked unit fails; a non-positive serial CUDA baseline is insufficient evidence (exit 2). - The pyannote fixture is function-scoped, so each test's serial references come from an unhooked pipeline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and GPU paired-run gates (#22426) * feat(parity): contract (j) parity gate, (h) soak checks, F6 corpus and GPU paired-run gates Lane 5 of the legacy-retire swarm (M1 slice): - scripts/parity/parity_gate.py: rows 1-8 of contract (j) on --surface staging and --surface prod-shadow (rows 3-6 gate ladder ADVANCE), parity_report.json, PARITY_PASS/FAIL/PENDING last line, data_loss for rows 5/7 (ROLLBACK_ZERO). - scripts/parity/soak_check.py: the ten 12h legacy-dark soak checks; the lost-recording census must start at draining; all four legacy queues including sync-backfill-fresh; read-only live collectors. - scripts/parity/fleet_sample.py: rows 3/4 from the fleet gate's JSON sample (strict 121s dispatch breach) and the gate's data-loss tokens. - testing/quality_corpus: pinned public corpus (AMI/LibriSpeech/VoxConverse + silence), production-chain runner, scorer, and the paired runs gating #22368 (flight batching: qualify receipt re-verified plus chain pair) and #22358 (short-speech skip: fired units vs full diarizer), with an L4 Job template for staging. No GCP access in tests; reports carry aggregates and opaque keys only. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(parity): load scipy/jiwer at import so timed unit calls stay under the CPU guard Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ebt list for workers/consumer.py recovery_disposition.py is reverted to integration's version (freeze table); re-add the enum-derived constants after #22368 lands. REASON_UNKNOWN_TOTAL keeps the stub's name and both counters are pre-initialised per family. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…esh ratchet baselines Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
sync) Conflict in .github/actions/sync-backfill-lifecycle/action.yml: main's #22460 and lane 7's B4 (#22455) both stop trains re-pointing backfill at the retired sync-backfill queue. Resolved to one resolution step (ops-queues): prod reads the ops file (fail-closed, lane 7); other projects take the manifest's SYNC_BACKFILL_TASKS_QUEUE/SYNC_TASKS_QUEUE (main), sync-backfill only as default. The queue reconcile step keeps main's manifest-driven queue name. #22460's test is adapted to the single resolution step.
…atchet (lane 14 M1) (#22422) * feat(observability): reason enums, label AST check and batch-stage env ratchet (lane 14 M1) Contract (e): utils/observability/reasons.py with ReasonFamily, per-family enums, reason_label() and omi_reason_unknown_total. live_reason and recovery_disposition now derive their frozensets from the enums (behaviour-neutral; misses are also counted). Adds the shrink-only label-argument AST check and the batch-stage env-read ratchet. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * refactor(batch): derive worker validation constants from the reason enums (lane 14) Values unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Hold recovery_disposition.py until #22368; adopt stub counter name; debt list for workers/consumer.py recovery_disposition.py is reverted to integration's version (freeze table); re-add the enum-derived constants after #22368 lands. REASON_UNKNOWN_TOTAL keeps the stub's name and both counters are pre-initialised per family. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * env ratchet: pending allowances for reads lane 9 moves (C2) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * reason-label debt: lane 10 legacy_dark sites (closed via own enum helper) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Re-add enum-derived recovery_disposition constants after #22368; refresh ratchet baselines Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Drop the pending alert-metric allowances now that reasons.py produces both counters Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * feat(listen): populate app_build on omi_listen_accepted_total from X-App-Version (lane 14) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * refactor(observability): derive fallback ALLOWED_REASONS from FallbackReason (#21932 landed) Adds the nine reasons #21932 introduced; set unchanged (65 values). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * reasons: add ShadowParityOutcome (lane 12); debt entry for external_list_reads Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * refactor(batch): WorkResult/RecoveryWork closed sets from WorkOutcome and WorkerValidationReason (values unchanged) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * chore(changelog): none fragment (integration carries app edits relative to main; lane 14 is backend-only) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Restore app/ from integration (formatter collateral); drop none changelog fragment Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * Restore app/ exactly from integration (undo formatter collateral) Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(listen): read app_version fail-safe so partial device contexts cannot break session start Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Summary
The dedicated batch worker repeats pyannote model work inside each locked flight:
SpeakerDiarization.get_embeddingssends the full ResNet34 forward once per (chunk, local speaker) pair, even though all three local speakers of a chunk share the same waveform. Only the statistics-pooling masks differ.diarizer/batch_pipeline_flight.py(FlightPyannote) removes the duplicated work and packs what remains across the flight's units:pre_aggregation_hook,aggregate, crop and_binarizesteps asVoiceActivityDetection.apply. Diarization reads the same scores through itsget_segmentationshook.forward_frames/forward_embedding), pooled per local speaker with the masksget_embeddingswould build. The mask selection forexclude_overlapis unchanged.BATCH_PIPELINE_MODEL_BATCH_SIZE: segmentation takes B chunks, and the trunk takes B chunks instead of B pairs. Crops are generated lazily, one batch at a time.apply. The hooks fall through to the original methods whenever no precomputed feature is supplied.PipelineWorkergets an optionalflight_models. The decode loop and the final assemble loop are split so that a single packed call can run between them. Item semantics, failure stages and result types are unchanged.Composition with #22358 (speech-only diarization, default on)
Speech-only diarization runs the diarizer on a compacted waveform, so full-unit packed embeddings and the cached full-unit segmentation must not reach it. When it is on, the worker skips
_flight_diarize, and_diarize_unitkeeps its serial pyannoteapply. Theget_embeddingshook gives that uncached call the per-file shared trunk only: the same masks over the compacted file's own segmentation. Packed segmentation then serves VAD alone. When speech-only is off, full-unit packing applies as described above. The flight tests cover both modes.Safety and fallback
BATCH_PIPELINE_FLIGHT_BATCHING_ENABLEDdefaults off in code, in env parsing (only the exact valuetrueenables it; unset,false,0andyesall mean off), in Helm (worker.flightBatchingEnabled: false) and in the registry (rollout, fail closed, review_by 2026-10-26). Off is exactly the pre-PR serial path:FlightPyannoteis never constructed and no hooks are installed.BATCH_PIPELINE_FLIGHT_BATCH_SECONDS, default 1800 audio seconds per packed group (valid range above 0 up to 7200). Production flights average 287s, p95 795s, max 1,400s. A unit over the budget takes the serial calls.outcome=disabled reason=…);process_batchconcurrency and the chain lock are unchanged.Enablement gate (required before the flag is set on anywhere)
CPU equality on random weights does not cover the L4. Packing moves each unit's last chunk out of its own batch-of-one forward into a shared batch of 8, so cuDNN may choose another kernel. A shift of about 1e-5 in an embedding, or a powerset frame near 0.5, could change a VBx assignment, and that is unmeasured on the production checkpoint.
The gate is
diarizer/batch_pipeline_flight_qualify.py, run on one isolated dev L4 with community-1 revision3533c8cf8e369892e6b79ff1bf80f7b0286a54eeand batch pin 8. Use public or consented multi-speaker audio, such as AMI far-field meetings or a pendant clip with two voices:load_pyannote_pair, so the models are identical.FlightPyannote.createinstalls its hooks.speech_onlyis the Helm default and the configuration that authorizes the flag today. Packed segmentation feeds VAD, then the worker's own_diarize_unitdiarizes the compacted waveform through the per-file shared-trunk hook. Evidence is VAD-only because the harness runs no ASR.full_unitapplies when speech-only is off. Full-unitdiarize_manyruns, and raw segmentation and embeddings are compared against the unpatched pipeline.--speech-onlysetting. Afull_unitpass never authorizes the flag while speech-only is on.ChainMemoryProbepeaks for each configuration.vadanddiarizetimers measure GPU time for this path only once they wrap_flight_segment/vad_spansand_flight_diarize.Ramp plan for the flag:
worker.flightBatchingEnabled=trueon dev and hold for 24h. Watch two signals:event=batch_chain_memorypeaks;batch_flight_fallbackandworker_failedcounts.Equivalence (CPU, real pyannote 4.0.3)
tests/unit/test_batch_pipeline_flight.py:exclude_overlap=True) and compare the packed path with the serial calls on synthetic units of 3.5s, 10s, 12.25s and 21.5s. Results:Documented tolerance: on a GPU, packing changes batch composition, so cuDNN may pick different kernels. Expect float-level differences (on the order of 1e-6) in segmentation scores and embeddings, the same class of difference the existing batch-size pin already allows. A borderline clustering decision could in principle flip. The quantities computed are mathematically identical.
Expected GPU-time saving once enabled (estimate, not measured on an L4)
Local CPU measurement on a 285s, 7-unit synthetic flight (M5, 4 threads, so not GPU timing):
These ratios come from the code structure: about 3× fewer trunk forwards, about 2× fewer segmentation forwards, and fewer partial batches.
Mapping that to an L4 is an estimate. pyannote turns TF32 off, so the trunk runs in FP32. ResNet34 costs about 47 GFLOP per 10s chunk, and the serial path runs about 3 pairs per audio-second, so an average flight is about 40 TFLOP, roughly 2.5–4.5s of GPU time. Parakeet BF16 ASR is about 0.1–0.2s per flight. Removing about two-thirds of the trunk work and half of the segmentation work should save about 2–3.5 GPU-seconds per flight. The flight interval averages 20.25s, so if these stages stay on the serial critical path that is roughly +10–17% jobs/min per L4 (about 22 → 24–26/min). Confirming it needs the stage timers from #22324 (
vad,diarization) on a matched-mix hold.Caveat after #22358: speech-only diarization is on by default. The embedding saving (about 3× fewer trunk forwards) now applies to the compacted audio actually diarized, and the segmentation dedupe benefits VAD only. Treat the figure above as an upper bound; the real number depends on the compaction ratio of production audio.
Not changed
ASR batching and windows, padded retry, the chain lock, process concurrency, VRAM per forward, admission and merge.
Test plan (after the gate re-review): targeted batch-pipeline suites (flight, flight_qualify, worker, worker_io, two_workers, runtime, chart, dispositions, gpu_skip/diarization_gate), plus characterization and sim (317 passed). Real-pyannote CPU equivalence: 17 passed. These include the speech-only compacted composition and serial embeddings captured before the hooks are installed. Gate unit tests lock the fail-closed rules: not packed fails; a zero CUDA baseline exits 2; a full-unit pass cannot authorize while speech-only is on. Typecheck is clean for the changed files. The qualification's GPU path has not been run; that is the staging gate.
Failure-Class: none
The
fix(batch)commit is a review fix to code that is unreleased and inside this PR, not a production defect class.🤖 Generated with Claude Code