feat(rollout): add continuous batching generation prototype (#8368)
## Summary
Add an experimental continuous-batching generation path to DeepSpeed
rollout for OPSD/OPD evaluation.
The implementation maintains a bounded number of active request rows,
retires requests independently on EOS or when the shared generation
budget is reached, compacts surviving `StaticCache` rows when necessary,
and refills released slots with pending requests.
The existing `HybridEngineRollout.generate()` behavior remains unchanged
when continuous batching is not enabled.
## What changed
* Add `SamplingConfig.continuous_batch_size` to enable continuous
batching through the existing `generate(request, sampling)` entry point.
* Preserve the original request-row order in the returned right-padded
`RolloutBatch`.
* Keep the continuous-batching scheduler and cache lifecycle helpers
internal to the rollout implementation.
* Extend `DeepSpeedStaticCache` with per-row write positions and
active-row compaction.
* Skip unnecessary cache and attention-mask compaction during
steady-state decode.
* Add an identity-compaction fast path while preserving dead-row zeroing
for safe row reuse.
* Require Transformers cache-class support for continuous batching while
keeping the default generation path available for older models.
* Add deterministic CPU coverage for the modern `StaticCache` path.
* Update rollout tests and documentation.
## Design
Continuous batching is enabled with:
```python
SamplingConfig(continuous_batch_size=N)
```
When enabled:
1. Up to `N` request rows remain active at a time.
2. Requests retire independently when they reach EOS or the shared
generation budget.
3. Released cache rows are reused for pending requests.
4. Surviving rows are compacted only when required.
5. The final `RolloutBatch` is restored to the original request-row
order.
The scheduler is kept separate from the model backend. The rollout
backend owns prompt prefill, decode execution, cache movement, and
attention metadata construction.
## Scope and limitations
This is an experimental rollout feature intended for OPSD/OPD
evaluation.
The current implementation supports:
* One prompt row per request.
* Equal prompt widths.
* Greedy decoding.
* One sample per prompt.
* Transformers models with cache-class support.
* Single-device validation.
The following are intentionally left for follow-up work:
* Variable-width prompt alignment and dead-zone trimming.
* In-place refill.
* Paged or block-based KV cache.
* Prefix/radix cache.
* CUDA Graph support for continuous batching.
* Continuous-batching profiling.
* Shared-prefill integration.
* KV-cache offload.
* Multi-GPU/tensor-parallel validation.
Models without Transformers cache-class support continue to use the
default `generate()` path.
## Validation
Focused rollout tests:
```bash
python -m pytest -q \
tests/unit/runtime/rollout/test_continuous_batching.py \
tests/unit/runtime/rollout/test_hybrid_engine_rollout.py \
tests/unit/runtime/rollout/test_rollout_interface.py \
tests/unit/utils/test_static_cache.py
```
Focused H200 validation:
**52 passed, 2 warnings**
Coverage includes:
* Scheduler bookkeeping.
* Modern `StaticCache` prefill and decode.
* EOS-based request retirement.
* Row compaction and per-row write positions.
* Pending-request refill.
* Identity-compaction fast path.
* Dead-row clearing.
* Default generation behavior.
---------
Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Co-authored-by: Ma, Guokai <guokai.ma@gmail.com>