[RFC] Rollout engine primitives for RL training in HybridEngineRollout
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 8/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- ai-infra-agents
Hướng nghiên cứu
This is a design RFC, not a bounded task: it proposes RolloutRecord, RolloutRequest and RolloutBatch and a single _TokenSelector across the static and continuous generate paths in the rollout code. Read the proposal and the master/proposed table first, then the existing generate() paths and deepspeed/runtime/rollout/opsd.py to see what is removed. Done means maintainers agree on the record API and the compatibility plan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
HybridEngineRollout.generate() takes left-padded prompt tensors and returns padded tensors. An RL trainer also needs each sampled token's log-probability (for the importance ratio, without a second forward), why each sample stopped, and a way to continue a sample in a later call, so a multi-turn loop can append tool output between rounds. This RFC proposes one record per sample in and out, log-probs on every decode path, and continuation of records that already hold earlier turns.
It narrows #8942 (agentic RL training on the hybrid engine) to its engine-side needs: interleaved model and environment tokens with a loss mask, per-trajectory status and log-probs, and continuing from the exact tokens sampled. The environment loop and sandboxing that #8942 also planned stay outside DeepSpeed.
Three RL examples in DeepSpeedExamples, ReTool (multi-turn tool calling), MemAgent and on-policy distillation (OPD/OPSD), build on these primitives. Each runs its own loop around generate() and holds its RL algorithm code, so DeepSpeed provides generation only.
Generate path: master and proposed
master: generate(prompt_ids, prompt_attention_mask)
├─ static: Hugging Face generate() or _generate_graph
└─ continuous: eager loop, _generate_continuous_graph, or adaptive prefill routing back to static
each path selects tokens, applies the penalty and checks EOS on its own ─► padded RolloutBatch
proposed: generate(RolloutRequest(samples=[RolloutRecord, ...]))
├─ render prompts, expand n_samples_per_prompt, compute each record's budget
├─ static or continuous, as on master, with one request per record
└─ every path: _TokenSelector ─► the engine appends the segment to its record ─► the same records
| Master | Proposed | |
|---|---|---|
| Input and output | Padded tensors, one response_start_idx |
One record per sample; a record with a response is continued |
| Token selection | Per path; the penalty rebuilds each row's history every step | One _TokenSelector (penalty from a seen-token mask, temperature, top-k/top-p, log-probs) |
| Log-probs and finish reason | None | Per token with return_log_probs; COMPLETED or TRUNCATED per record |
| Budgets | One max_new_tokens for every row |
Per record and call: min(max_new_tokens, record.max_new_tokens, max_out_tokens - context) |
| Continuous batching | Greedy-only with adaptive prefill, one sample per prompt | Sampling and several samples per prompt, one EOS read per step |
Proposal
@dataclass
class RolloutRecord:
prompt: str | list[dict] = "" # text, or chat messages rendered with the chat template
tokens: list[int] = ... # prompt and response token ids, unpadded
attention_mask: list[int] = ...
response_length: int = 0 # tokens after the prompt
loss_mask: list[int] | None = None # per response token: 1 generated, 0 added by the caller
rollout_log_probs: list[float] | None = None
status: Status = Status.PENDING # COMPLETED on EOS, TRUNCATED on a budget or the context cap
group_index: int | None = None # samples of one prompt share it
max_new_tokens: int | None = None # optional cap on this record's tokens in this call
RolloutRequest(samples: list[RolloutRecord]) -> RolloutBatch(samples: list[RolloutRecord])
- Records. A record without
tokensis rendered fromprompt. Records carry no response text; callers decodetokens[-response_length:].n_samples_per_promptexpands every record, so expanding a continued one forks it. - Continuation. A record holding a response gets one more segment. The engine writes it through one method that appends the tokens, extends
loss_maskwith 1s and the log-probs, updatesresponse_lengthand setsstatus. Afterwards the record is the caller's to edit, unchecked; by convention caller tokens get loss mask 0 and log-prob 0.0. The engine keeps no state between calls and prefills the whole context again, which is also correct after a weight update. - Budgets. They apply to one call, as in the table;
hybrid_engine.max_out_tokenscaps every context. A multi-turn loop keeps its own total and turn count and passes each record's remainder asrecord.max_new_tokens. Under ZeRO-3, ranks stop once no row on any rank has work left, counting each row's budget, and a rank with no records joins with a placeholder row. - Log-probs. Recorded after temperature; they require
top_p=1andtop_k<=0when sampling and warn with a repetition penalty, which a training forward cannot reproduce. The log-softmax runs only when they are requested. - Config.
continuous_batch_sizeandreturn_log_probssize the cache and captured graph, so they move fromSamplingConfigtoHybridEngineRolloutConfig, now a subclass ofRolloutConfig.SamplingConfiggainsrepetition_penalty. Unsupported combinations are rejected at the start ofgenerate(). - Unchanged. Adaptive prefill, segment-KI and the GDN state restore, shared prefill, graph reuse, cache trimming and aligned fronts keep working. Continuous batching for linear-attention models (Qwen3.5) stays unsupported.
Compatibility
This breaks RolloutRequest, RolloutBatch and SamplingConfig.continuous_batch_size; the docs get a migration table.
deepspeed/runtime/rollout/opsd.py (ResponseTokenBatch, JSDLossOutput, generalized_jsd_loss), the only in-repository consumer of the rollout output, moves to the OPD/OPSD example and is removed from DeepSpeed, together with its exports from deepspeed.runtime.rollout. It is training-side algorithm code, which the examples now own, and the example's version reads the records and honors loss_mask.
- Ngôn ngữ chính
- Python
- Star
- 43.3k
- Fork
- 5.1k
- Merge trung bình
- 5 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 85
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của deepspeedai/DeepSpeed
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()Có thể đã có người làm @its-amann đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
deepspeedai/DeepSpeed#9190 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exceptionCó thể đã có người làm @bantianyue đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#9183 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
deepspeedai/DeepSpeed#9019 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped foreverCó thể đã có người làm @damienen đã nhận 26 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
deepspeedai/DeepSpeed#8982 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] OneCycle applies the minimum momentum to the first Adam updateCó thể đã có người làm @ai-yang đã nhận 30 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
deepspeedai/DeepSpeed#8951 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của deepspeedai/DeepSpeed
Issue tương tự
-
area/auth comp/agent P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#161417 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Dao-AILab/flash-attention#3251 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[New Check]: sqlserver_public_network_access_disabledCó thể đã có người làm @pouria-l đã nhận hôm nay. Đang mởfeature-request status/needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
prowler-cloud/prowler#13607 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
external langchain
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
langchain-ai/docs#8184 ·
Maintainer thường phản hồi trong vòng 1 ngày