[RFC] Engine primitives for external orchestrators
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 8/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Activo
- Área
- distributed-systems
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 43.3k
- Forks
- 5.1k
- Merge medio
- 5 d 10 h
- PR fusionados (30 d)
- 85
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de deepspeedai/DeepSpeed
-
[Bug] DeepSpeedEngine.step leaves _running_engine_step=True permanently on exception, corrupting is_gradient_accumulation_boundary()Posiblemente ocupada @its-amann la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
deepspeedai/DeepSpeed#9190 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[Bug] PipelineEngine._exec_reduce_grads and _exec_optimizer_step leave _force_grad_boundary=True permanently after any exceptionPosiblemente ocupada @bantianyue la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
deepspeedai/DeepSpeed#9183 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
deepspeedai/DeepSpeed#9019 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
fp16 `hysteresis: 0` (or negative) makes DynamicLossScaler never lower the loss scale, so every overflowing step is skipped foreverPosiblemente ocupada @damienen la tomó hace 26 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
deepspeedai/DeepSpeed#8982 ·
Los mantenedores suelen responder en 2 días
-
[BUG] OneCycle applies the minimum momentum to the first Adam updatePosiblemente ocupada @ai-yang la tomó hace 30 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
deepspeedai/DeepSpeed#8951 ·
Los mantenedores suelen responder en 2 días
Todos los issues de deepspeedai/DeepSpeed
Issues similares
-
area/auth comp/agent P3 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
NousResearch/hermes-agent#161417 ·
Los mantenedores suelen responder en 1 día
-
accepted
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
future-agi/future-agi#4737 ·
Los mantenedores suelen responder en 1 día
-
Fix URL validation, get_version_url, and implement robust parse_url for Launchpad backendPosiblemente ocupada @patelshivani2283-lab la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
fedora-infra/anitya#2278 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Dao-AILab/flash-attention#3251 ·
Los mantenedores suelen responder en 2 días