Skip to content

perf(batch): overlap bounded CPU decode across GPU flights - #23490

Closed
Git-on-my-level wants to merge 8 commits into
mainfrom
x1-batch-concurrency
Closed

Git-on-my-level wants to merge 8 commits into
mainfrom
x1-batch-concurrency

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

The dedicated batch worker already overlaps two pump flights and batches STT windows, but its first audio fetch/decode still runs behind the exclusive GPU-chain lock. Prepare a bounded number of CPU decodes while the previous flight is on the GPU, consuming each result through the unchanged worker and fenced publication path.

BATCH_PIPELINE_WORKER_DECODE_CONCURRENCY / Helm worker.decodeConcurrency defaults to 1 (current behavior and rollback; takes effect at worker restart under the existing Recreate/drain strategy). Values 2–4 permit 1–3 prepared items across all pump lanes, with a shared 1,800-admitted-audio-second budget and the existing IO executor. GPU concurrency stays 1, model batch/precision/checkpoints stay fixed, and incremental VRAM per prepared lease is zero. Failed decodes stay per-item; stopped/cancelled flights drain read-ahead; renewal, token/privacy/admission fences, CUDA quiescence and owner-ordered commits remain in their existing paths.

Production evidence was read with ro-prod through ops/pq.sh, with no user data or Cloud Logging. Oct 19–23 L4 daily GPU means were 0.12–3.01%, with 10,266 MiB maximum framebuffer. Historical worker lease/queue/stage queries returned EMPTY, so a dominant per-stage time cannot be claimed. The earlier 21–22 leases/min/node is historical, not current qualified capacity. Four L4s need at least 95.75 useful units/min/node for 383/min; this PR does not certify that target or realize the estimated ~$6k/month savings.

Qualification and ramp (lead/p90 owns expansion; staging owner operates the window; target packet 2026-10-26, renew/report a blocker if unavailable):

  • Keep N=1 until paired dev/staging L4 runs on an immutable public/synthetic corpus pass. Run N=1 → 2 → 1 → 3 → 1 → 4 with ≥30-minute saturated plateaus, exact image/model/config receipts, and complete obligation reconciliation. Compare full words/clocks, normalized speaker labels, WER/deletions, DER and retained source sample coverage against N=1. Inject decode failure, lease theft and interruption.
  • Measure unique useful units and audio-seconds/node-minute, claim/decode/GPU-lock/VAD/ASR/diarization/persistence/publication time, ready/owner-wait tails, held/retried/expired leases, projection backlog, GPU duty/CUDA/framebuffer peaks and container RAM/CPU. Adopt the existing stage profiler before making a stage-dominance or fleet-capacity claim.
  • Select the smallest N with repeatable gain, unchanged correctness/freshness, and worst observed peak plus ≥20% device/container headroom. Default remains 1 until this passes. A later authorized production ramp is 1 → 2 → measured maximum, batch workers only; the guard arms after one full 30-minute new-state window. Custody loss, duplicate commit, quality/fresh-tail regression, OOM or restarts return N to 1. No deploy, node/spend increase, admission change or legacy retirement is authorized by this PR.

Validation: the full 11-file targeted backend set passed 327 tests (2 skipped) through backend/test.sh, with an explicit file list, BACKEND_PYTEST_WORKERS=4, nice -n 19 and the unchanged CPU-time guard. This includes 23 new limiter/parity/overlap/fencing/failure cases, including re-leased context and cancellation-during-discard regressions. The synthetic latency model is illustrative only; GPU qualification has not run. Read-only Luna reviews through 73d356dad410 returned SHIP; the subsequent retry-context and discard fixes are covered by the parent-run regression tests and remain part of this PR’s human review.

Run report: omi-workspace:data/run-2026-10-12-subscription-overhaul/reports/x1-batch-concurrency.md.

Product invariants affected

none

Failure-Class: none

The fix: commits repair retry-context, cancellation cleanup and optional-handle typing issues introduced while developing this unshipped read-ahead feature; they are not repairs of a released production incident. A re-leased segment skips read-ahead while an earlier attempt remains in flight, preserving the decoder's per-segment language/context cache. The regression forces a replacement lease during an old GPU call and requires exactly one accepted result with intact language metadata. A structural prepared-resource contract makes the optional factory/cleanup boundary explicit to the unchanged type checker.

View guided diff Turn on auto-fix

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T08:58:05.226704Z 382a2bb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level marked this pull request as draft October 24, 2026 09:03
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Parking as draft (Plans & Cost). Measured result: N=2 +3%, N=3 ±0, N=4 −4% on the m1 paired pass, so read-ahead concurrency is not the batch throughput lever. The dominant stage can't be identified from current metrics; next step is adopting the existing batch stage profiler (anx card a2-batch-profiler-gap) and measuring per-stage time on a dev L4. Report: data/run-2026-10-12-subscription-overhaul/reports/x1-batch-concurrency.md (meta-repo).

Git-on-my-level added a commit that referenced this pull request Nov 1, 2026
The batch worker currently holds exclusive GPU ownership while its first
audio fetch and final encrypted writes wait on storage. This bundle
prepares a lane's first decode before the lock and settles the final
persist tail after CUDA quiescence and unlock, before fenced
publication, with lease renewal still running.

Decision: use the smaller pump-side first-item preparation instead of
rebasing draft #23490. It captures the first-fetch overlap without a
cross-flight cache, new decode-concurrency knob or new queue custody
state. All lanes share a 1,800-admitted-audio-second preparation budget
and the existing IO pool (default 3 to 5; Helm worker.ioConcurrency).
Authenticated language/stream context is bound to the actual attempt
object. IO=1 is the existing serial kill switch; it takes effect at
worker restart under the same Recreate/drain strategy.

Additional telemetry: retry-to-ready wakeups are requeued, genuine
failure retries retain retry and get one content-free INFO record.
Admission receipts distinguish timeout, transport and invalid receipt.
Unique fenced completions count capture seconds by success/silence,
including silence. CPU-only strict-VAD shadow never changes output or
skips/adds a GPU call. The waiting-lane watcher is joined before GPU
dispatch; once dispatched, the current bounded chain drains on stop.
Completion seconds cover every canonical outcome, including
no_recoverable_speech. The background-task ownership ratchet is
unchanged; prepared futures return explicitly to their owner and
cleanup/renewal handles are shielded and awaited. On this Mac, 60s
synthetic silence/tone cost 0.278/0.280 thread CPU seconds; cold first
20ms inspection cost 0.094 CPU seconds. These are host measurements, not
L4 qualification.

Validation: targeted backend/test.sh runs under omi-heavy, nice -n 19,
BACKEND_PYTEST_WORKERS=4, with an explicit file list. Tests cover
persist-before-publish, per-unit persist failure, fatal CUDA IO drain,
renewal after unlock, lost leases, SIGTERM, repeated cancellation,
cross-attempt context, global preparation bounds, privacy revocation
during upload, and unchanged fake-model payloads
(words/speakers/clocks). Final local result: **606 passed, 0 failed, 2
optional real-pyannote cases skipped across 23 files** at
**729934c72aa8bf5d31751212acf14dd2fada7953**. The final head passed the
full enforced backend type check with **0 errors**. The prescribed make
preflight passed 39 checks before the final lease/type delta; canonical
pre-push then passed all **39 shared checks**, enforced type check,
import/source closure, selected unit tests and formatting at this exact
head, with no skips. Prior-head CI found the background-task ownership
ratchet; it remains unchanged and is covered by the final local pass.
GitHub CI is running on the final head. No dev GPU run or production
access performed. `worker_flight` now ends with the model/CUDA phase;
fetch/persist leaf spans can cross its boundary, and `persist_settle`
measures the separate tail, so overlapping durations must not be added.

Rollback by piece:

- Preparation/persist separation/IO pool: worker.ioConcurrency=1 removes
pre-lock preparation and restores synchronous artifact IO under the
model lock. Revert the worker image and set worker.ioConcurrency=3 for
the previous overlap/default; config is additive and uses existing
packaged dependencies. Normal 1500s SIGTERM drain remains. If forcibly
lost, existing token/lease expiry replays retained encrypted audio; an
unreferenced result remains covered by its deletion outbox, and no
schema migration or job rewrite is needed.
- Requeue and duration/admission counters: revert image; metric
meanings/series return to old names and new counters disappear. Durable
job state and attempts do not change; dashboards must account for the
release boundary.
- Strict-VAD shadow: revert its worker code/image to remove CPU cost. It
changes no payload or durable job state, and no in-flight job needs
repair.

Lead-only qualification plan (not run): after CPU admission is fed, pin
source/image/model/corpus and flags; run a saturated L4 pair with
matched synthetic/public inputs. The baseline is the pre-bundle image at
IO=3; the treatment is this image at IO=5, with all model flags held
identical. Use fixed warmup and 30-minute baseline/candidate/baseline
plateaus, swapping treatments across GPUs. IO=1 is a serial rollback
control, not the old production baseline. Compare unique fenced
completed capture/speech seconds per GPU-hour, silence separately,
complete/held/retry/expiry obligations and output
hashes/words/clocks/normalized speakers. Measure GPU lock wait/hold and
starvation, fetch/decode/persist/persist_settle/publication and
projection tails, CPU/shadow cost/throttling, host/device peaks and
restarts. Inject lease theft, privacy revoke, slow/failing uploads,
fatal CUDA and SIGTERM. Do not claim a production gain from the host
latency model or use pre-persist durations as the denominator. Filter
all queue rates with job=batch-pipeline-worker-metrics. Require
unchanged quality/custody and existing memory headroom before the lead
schedules the single Recreate roll; rollout/repair-flag reapplication
and all merge/deploy authority stay with the lead.

## Product invariants affected

none

Failure-Class: none

This is a worker performance/observability bundle. It introduces no new
workflow, admission allowance, provider route, model
checkpoint/precision, data mutation tool or runtime dependency.
admission.py, live.py and serving.py remain outside this PR.

The stockout/Recreate rollout takes all workers down together; this PR
does not start it. The lead owns qualification, merge, roll and
repair-flag reapplication.

## Review corrections (gpufix)

Grouped batches now aggregate every deferred persistence receipt instead
of settling earlier groups under GPU ownership. Their decoded buffers
are released between groups, and a later fatal group drains all earlier
writes. A cancelled preparation's running fetch drains in final cleanup
after GPU unlock while reservation and renewal remain active. Dispatch
admission rechecks now count the same closed outcomes as initial
admission, without changing permission.

Nine new regressions fail against the original production files at
729934c and pass with these corrections. They cover four/eight
3,600-second units with a blocked first-group persist, no publication
before settlement, both GPU lock boundaries, later-group fatal drain, a
running slow fetch on lease loss, and five dispatch admission outcomes.
The selected six-file backend shard passed **226 tests**, including
existing worker/IO/runtime/pump and background-task ownership coverage,
through `backend/test.sh` with an explicit file list, `omi-heavy`, `nice
-n 19`, and four workers. No production access or deployment was
performed.

The follow-up also passed all **39 make preflight gates** and the
hermetic backend E2E harness (**180 passed, 3 skipped, 2 xfailed**),
serially under `omi-heavy` and `nice -n 19`. Correction head:
**96210d94ea3fe865aa60ee64ceedb8751e2fb4db**. Its canonical pre-push
passed all 39 shared checks, the enforced full backend type check (**0
errors**, existing warnings remain), source closure, **263 selected unit
tests**, and formatting without a skip. GitHub's [checks
tab](https://github.com/BasedHardware/omi/pull/24213/checks) owns
current exact-head CI status; local checks certify source/harness
behavior, not real GPU quality or deployed behavior. Merge, L4
qualification, worker roll and release monitoring remain lead-owned.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@kodjima33 keep-or-close ping (lead2 ruling 664fd6, dropped-work audit 2026-11-09 item 7): this draft has been idle 15-17 days. Please reply with keep (and a next step) or it will be closed as not-now in 24h (after 2026-11-10 17:10Z). Closing keeps the branch; nothing is lost.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Closing as part of a stale-PR cleanup David asked for on 2026-11-26 (Shipping lead agent): it is a draft with no activity for days. Nothing is lost: the branch stays, and anyone can reopen this PR if the work is still wanted. If it still matters, reopen it and refresh it against main.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant