Skip to content

[Performance] Serve process-slot inference passes from pinned staging batches - #4306

Merged
vmoens merged 2 commits into
mainfrom
inference-server-pinned-pass
Sep 9, 2026
Merged

[Performance] Serve process-slot inference passes from pinned staging batches#4306
vmoens merged 2 commits into
mainfrom
inference-server-pinned-pass

Conversation

@vmoens

@vmoens vmoens commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Stack: #4305#4306#4307#4308; depends on #4305.

Batch process-slot inference through reusable pinned buffers, non-blocking transfers, and one CUDA event per pass. Gather/scatter replaces per-request copies; only response keys return to CPU.

server = InferenceServer(
    policy,
    transport=transport,  # ProcessSlotTransport; batched I/O is automatic
    policy_device="cuda",
)

Custom collate functions retain their existing path.

Validation: CPU inference suite and metadata regression tests pass. CUDA validation and throughput measurements pending.

@pytorch-bot

pytorch-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4306

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 4 Pending

As of commit 9ee51a0 with merge base 5076ae1 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 8, 2026
@github-actions github-actions Bot added Performance Performance issue or suggestion for improvement Documentation Improvements or additions to documentation Benchmarks rl/benchmark changes Modules Integrations/torch_geometric Integrations and removed Performance Performance issue or suggestion for improvement labels Sep 8, 2026
@vmoens
vmoens force-pushed the inference-server-pinned-pass branch from 2dff398 to 3f235b5 Compare September 8, 2026 15:55
@vmoens
vmoens changed the base branch from main to async-collector-worker-owned-replay September 8, 2026 15:55
@github-actions github-actions Bot added the Performance Performance issue or suggestion for improvement label Sep 8, 2026
@vmoens vmoens added the benchmarks/trigger Run the full benchmark suite on main right after this PR merges label Sep 8, 2026
@vmoens

vmoens commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author
Projected server pass cost: -40–50%
Projected server ceiling:   ~1,000 -> ~1,800–2,000 steps/s

These CUDA estimates remain unmeasured. No direct end-to-end gain is expected until #4305 removes the driver bottleneck.

@vmoens
vmoens force-pushed the inference-server-pinned-pass branch from 3f235b5 to c68b7e3 Compare September 8, 2026 16:35
@vmoens

vmoens commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Measured on the target hardware (64-environment DreamerV3 run on a pixel task, one 4-GPU node, process-slot inference server with a static batch of 64, compiled and CUDA-graph learner step, bf16, train ratio 16), comparing the full stack #4305 + #4306 + #4307 + #4308 (with transition_chunk_size=64) against the same configuration without these four PRs, over the same elapsed window of the two runs (1,000 s to 4,428 s after training start):

environment steps/s learner updates/s (32x256)
without the stack 361 0.70
with the stack 1,249 2.44
speed-up 3.46x 3.46x

The unthrottled collection phase before training reached 1,254 steps/s (298 before), the learner GPU now shows sustained full-utilization bursts instead of about a quarter duty cycle, and the run had no errors over the measured 1.3 hours. The two rates move together because the train ratio couples them, so the stack lifted both the collection ceiling and the learner cadence past the previous limits. This measures the combined effect of the four PRs; per-PR attribution has not been measured.

@vmoens
vmoens force-pushed the inference-server-pinned-pass branch from c68b7e3 to cd39d87 Compare September 9, 2026 09:41
Base automatically changed from async-collector-worker-owned-replay to main September 9, 2026 10:28
vmoens and others added 2 commits September 9, 2026 11:28
… batches

InferenceServer serves ProcessSlotTransport with one batched pass per
sweep. Ready slots are claimed without copying (drain_slots) and gathered
into a reusable host staging batch with one index_select per leaf
(gather_requests); the batch is copied to a persistent policy-device
batch with non-blocking transfers (pinned staging on CUDA), padded to the
CUDA-graph size by repeating the last request on device, run through the
model, and only the declared response keys are copied back to a pinned
response batch. One CUDA event per pass waits for that copy instead of
the two synchronizing TensorDict.to() calls, and resolve_batch scatters
the responses into the slots with one indexed copy per leaf before waking
the workers. The interaction code is read from the host batch (no .item()
sync) and the CUDA-graph output is consumed by the stream-ordered copy,
so the per-pass clone is gone.

The per-request path is unchanged for other transports; _run is split
into the shared drain loop plus _serve_batch/_serve_slot_batch, and
transports opt in through InferenceTransport._batched_slot_io. Custom
collate functions keep the per-request path.

Adds benchmarks/bench_inference_server.py (requests/s of the process
server behind ProcessSlotTransport with 64 clients, eager or CUDA graph)
and tests for the batched protocol and pass (CPU) plus a CUDA test for
pinned staging, padding, fresh random draws and in-place weight updates.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vmoens
vmoens force-pushed the inference-server-pinned-pass branch from cd39d87 to 9ee51a0 Compare September 9, 2026 10:28
@vmoens
vmoens merged commit e11e38e into main Sep 9, 2026
128 checks passed
@vmoens
vmoens deleted the inference-server-pinned-pass branch September 9, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmarks/trigger Run the full benchmark suite on main right after this PR merges Benchmarks rl/benchmark changes CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Documentation Improvements or additions to documentation Integrations/torch_geometric Integrations Modules Performance Performance issue or suggestion for improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant