[RFC] Engine primitives for external orchestrators
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
- Cần làm rõ
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- distributed-systems
Hướng nghiên cứu
This is an open RFC proposing public engine primitives (offload/reload, weight export, layout and groups, destroy guarantees, comm health, device binding), not a bounded fix. The payload names runtime/zero/stage3.py for the FusedAdam-only assertion in offload_states, and the module-level groups helpers that #9081 is changing. Done would mean maintainers agreeing on the API in the RFC thread, so start by reading that thread and #9081 rather than writing code.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
RL and multi-role training frameworks increasingly run DeepSpeed engines in their own processes, often each role in its own torch world, under an orchestrator built on Ray. Examples include verl, OpenRLHF, SkyRL, and Arctic Platform. These frameworks need a small set of guarantees from a DeepSpeed engine that today are missing, private, or limited to some configurations: moving an engine's state off and back onto the device, exporting its weights, knowing its layout and groups, releasing everything on destroy, and detecting a communication failure.
This RFC proposes that DeepSpeed provide those primitives as a supported contract, and draws a boundary: DeepSpeed would not spawn, place, or coordinate processes. Cross-process roles, asynchronous RL, programs whose ranks run different code, and colocating several roles on one device would stay in orchestration frameworks, which DeepSpeed serves without depending on any of them.
It complements #9081, which covers several engines inside one process. The two share some pieces, noted below, and #9081 is where those are specified.
Motivation
An orchestrator that hosts a DeepSpeed trainer next to a rollout or reference model typically does the following:
- runs each role in its own torch world (one engine per process);
- between phases, moves the trainer's state off the device to make room for another role, and back again;
- exports the trainer's current weights to the rollout, over a dedicated communicator across devices, or by sharing memory between processes on the same device;
- restarts or resizes a role, and needs to know that destroying an engine released its memory and communicators;
- detects that a collective failed before trusting a result or committing a checkpoint.
Each of these works only partly today. Arctic Platform's open-source code shows each workaround:
- Offloading state.
offload_states()asserts that the optimizer is DeepSpeed FusedAdam on ZeRO-3 (runtime/zero/stage3.py, "Offloading is supported only for DeepSpeed FusedAdam"), and the engine refuses when parameters are offloaded. For configurations with an offloaded optimizer, Arctic Platform calls the optimizer'soffload_statesdirectly to bypass the engine assertion (see #6596, "Extendoffload_statesto support models with cpu-based optimizer"). For engines without an optimizer, such as a reference model, it moves parameter tensors by hand. - Layout and groups. To find the sequence-parallel and expert-parallel groups it reads module-level private functions (
groups._get_sequence_parallel_group()) and callsgroups._create_expert_and_data_parallel(). #9081 is changing exactly these globals. - Weight export. Under ZeRO-3 each rank holds a partition, so exporting full weights means gathering them with
zero.GatheredParametersand streaming them out. Every framework builds its own version of that loop. - Destroy and failure. There is no documented guarantee of what
destroyreleases, and no public way to ask whether the engine's communicators have failed.
Why Arctic Platform as the reference consumer
This RFC proposes Arctic Platform as the first consumer that adopts and tests the contract, for two reasons, stated here as a disclosure as much as a rationale:
- Shared maintainers. Arctic Platform is open source (Apache-2.0), and it shares maintainers with DeepSpeed, including me. A change to a DeepSpeed primitive and its adoption in a real orchestrator can then be designed, reviewed, and tested together, and a missing or awkward piece shows up quickly.
- Governance. Snowflake, which develops Arctic Platform, is a member of DeepSpeed's Technical Steering Committee, so the commitment to keep the consumer in step with DeepSpeed is backed by an organization already accountable to the project.
Its structure also makes it a good test of the contract: its integrations with verl, TRL, SkyRL, PrimeRL, and Tinker go through its own client API and never touch DeepSpeed, and all of its DeepSpeed use is in one server-side worker. Each primitive would therefore be adopted in one place and benefit every framework it hosts.
Being the reference consumer would not make the contract Arctic Platform-specific. The primitives are meant for any orchestrator, and verl, OpenRLHF, SkyRL, and others are very welcome to review them, adopt them, and run them in their CI. None of them would depend on Arctic Platform.
Measurements
These support doing this outside DeepSpeed, with each role in its own process, even when roles share a device. Single node, 4× NVIDIA B200, torch 2.9.1:
| Cost | Result |
|---|---|
| An extra process on the same GPU | About 870 MiB of device memory per process (CUDA context with cuBLAS loaded, plus torch's reservation) |
| Each extra full-world NCCL communicator | About 580 MiB per GPU with NVLS off, 630-646 MiB with NVLS on; destroy returns all of it |
| Sharing a 16 GiB tensor between two processes on one GPU (CUDA IPC) | Zero-copy: handed over in 61 ms, no device memory allocated by the receiver, and in-place updates visible to it immediately |
offload_states() / reload_states(), ZeRO-3, 7.24B-parameter Llama config on 4 GPUs, 27.9 GiB of state per GPU |
About 1.2-1.35 s to offload and 1.05 s to reload, after a one-time 21 s first offload while pinned host buffers are allocated. The caching allocator kept about 13 GiB reserved after offload until emptied |
| A collective that one rank never joins | The call returns a wrong value without raising before torch aborts the process (about 15 s later with torch 2.15's default NCCL backend, 1-3 s after a ~75 s block with the legacy backend); the backend's error state reports TIMEOUT by then |
The group-creation and timeout checks are in DeepSpeedExamples, branch sfc-gh-truwase/multi-engines, benchmarks/multi_engines.
Proposed primitives
Names and signatures below are sketches for discussion.
- State offload and reload for every engine configuration.
engine.offload_states()andengine.reload_states()would work for every ZeRO stage, for any optimizer (not only FusedAdam), with offloaded optimizer or parameters, and for engines without an optimizer (parameters only). After an offload, an option would return cached device memory to the device (empty_cache=True), since another process may need it. Pinned host buffers would keep being reused across cycles, as they are today for ZeRO-3, so only the first offload pays the allocation. - Weight export. A supported way to stream an engine's current weights, gathered from ZeRO partitions when needed, in buckets of a chosen size and dtype, without the caller managing
GatheredParameters. For example, a generatorengine.export_weights(bucket_bytes=..., dtype=...)that yields(name, tensor)pairs in a stable order on every rank, so an orchestrator can send them over its own communicator or share them between processes. A matchingengine.import_weights(...)would let a DeepSpeed engine be the receiver. - Public layout and groups.
engine.mpuandengine.meshfrom #9081, plus a small read-only description of the layout (DP, TP, SP, EP sizes and this rank's coordinates), so orchestrators stop reading module globals. destroywith stated guarantees. Afterengine.destroy()the engine would hold no device memory, no pinned host buffers, no swap files, and no communicators it created; calling it twice would be safe; and it would still release local resources after a failure. Group release follows the ordering rules in #9081.- Health query.
engine.comm_healthy()or similar, reading each of the engine's groups' error state, so an orchestrator can check before trusting a result or committing a checkpoint. #9081 proposes calling it at engine API boundaries and before checkpoint commits; this RFC asks for it to be public. Where a backend exposes no error state, the call would say so rather than report healthy. - Device binding. An engine uses the process's device, fixed at process init, and does not depend on
LOCAL_RANKwhen the orchestrator sets the device itself (for example, one device visible per process). The process-level rules are in #9081.
Alternative considered: DeepSpeed spawns and coordinates engine processes
Instead of leaving cross-process orchestration to frameworks built on Ray (Arctic Platform, verl, OpenRLHF, and others), DeepSpeed could do it itself. The client process would hold a DeepSpeed coordinator; each engine would run as its own set of worker processes in its own torch world; and DeepSpeed would create, call, and destroy them, with local multiprocessing on one node and optionally Ray across nodes.
What it would solve. Because each engine would have its own world and process state, most of the hard parts of several engines in one process (#9081) would not arise: every rank declaring every engine's groups in the same order, group-name and split hazards between engines, shared process-wide state (random streams, construction-time patches, current device), one failure poisoning the whole process, and ordered release of groups. Per-engine seeds, programs whose ranks run different code, and resizing by restarting an engine would come naturally.
Why it is set aside:
- It changes the client programming model. The client would no longer hold the module or live output tensors: no autograd across engines, a model factory instead of passing a module to
deepspeed.initialize, and the training step and loss running inside the engine. DS-Chat, Accelerate multi-model, and HF Trainer would still need the in-process path, so DeepSpeed would carry two engine models. - It duplicates what orchestration frameworks already do. Arctic Platform runs each DeepSpeed engine in its own torch world on unmodified DeepSpeed under a Ray single controller, with weight sync between worlds and colocation by offload and sleep. verl and OpenRLHF take the same approach, running training and rollout workers as Ray actors. What those frameworks lack is a complete, public engine contract, which is what this RFC proposes.
- It would add process lifecycle, remote calls, data movement between processes, and possibly a Ray dependency to DeepSpeed, none of which single-engine users need.
Costs measured for the separate-process model, which apply equally to a DeepSpeed coordinator and to an external orchestrator (4× NVIDIA B200, torch 2.9.1): about 870 MiB of device memory per extra process on a shared GPU; zero-copy weight sharing between processes on one GPU through CUDA IPC (16 GiB in 61 ms); and about 1.2-1.35 s to offload and 1.05 s to reload 28 GiB of ZeRO-3 state per GPU for a 7.24B-parameter model. These make the separate-process model viable even on a shared device, which is why this RFC focuses on the primitives it needs rather than on where the coordinator lives.
Alternative considered: orchestrating directly on Ray
A team could also run DeepSpeed engines as its own Ray actors, with no RL framework in between. The primitives serve this case in exactly the same way: an orchestrator written directly on Ray consumes the same contract as Arctic Platform, verl, or OpenRLHF.
What a direct-on-Ray orchestrator has to build itself is what those frameworks already provide: a torch world per role (ranks, ports, and process groups), the DeepSpeed engine lifecycle, weight sync between worlds (layout mapping, communicators, colocated sharing), colocation sequencing (offload, sleep, memory handoff), and failure handling. Ray provides the building blocks that matter for the harder scenarios: actor restarts for restarting a role, placement groups for resizing one, and scheduling across several accelerator vendors.
Whether to orchestrate on raw Ray or through a framework built on it is the user's choice. DeepSpeed's job is the same either way: provide a complete, public engine contract.
Non-goals
- DeepSpeed would not spawn, place, schedule, or restart processes, and would not depend on Ray.
- No RPC, data transport between roles, or weight-sync scheduling; those belong to orchestrators.
- No changes to how a single engine trains.
Relationship to #9081
#9081 makes several engines in one process correct: per-engine groups, an all-ranks group registry, ordered release, health checks, and process-level device and seed rules. This RFC uses the same engine, viewed from outside, and asks that the pieces an orchestrator relies on be public and complete. Items 3-6 overlap with #9081 and would be specified there; items 1 and 2 are new.
Open questions
- Is
export_weightsbest as a generator over gathered buckets, or as a callback API that lets DeepSpeed overlap gathering with the caller's sends? - Should offload and reload also cover activation-checkpoint and swap state, or only parameters, gradients, and optimizer state?
- What should
destroydo with groups an orchestrator passed in (an externalmpu)? #9081 proposes never destroying them. - Which orchestration frameworks would be willing to adopt the contract and run it in their CI?
This RFC was drafted with AI assistance, including the code analysis and the measurements. I reviewed it before posting.
- 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