[RFC] Engine primitives for external orchestrators

Aperta
#9,152 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
8/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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's offload_states directly to bypass the engine assertion (see #6596, "Extend offload_states to 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 calls groups._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.GatheredParameters and streaming them out. Every framework builds its own version of that loop.
  • Destroy and failure. There is no documented guarantee of what destroy releases, 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.

  1. State offload and reload for every engine configuration. engine.offload_states() and engine.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.
  2. 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 generator engine.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 matching engine.import_weights(...) would let a DeepSpeed engine be the receiver.
  3. Public layout and groups. engine.mpu and engine.mesh from #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.
  4. destroy with stated guarantees. After engine.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.
  5. 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.
  6. Device binding. An engine uses the process's device, fixed at process init, and does not depend on LOCAL_RANK when 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

  1. Is export_weights best as a generator over gathered buckets, or as a callback API that lets DeepSpeed overlap gathering with the caller's sends?
  2. Should offload and reload also cover activation-checkpoint and swap state, or only parameters, gradients, and optimizer state?
  3. What should destroy do with groups an orchestrator passed in (an external mpu)? #9081 proposes never destroying them.
  4. 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.

Lingua principale
Python
Stelle
43.3k
Fork
5.1k
Merge medio
5g 10h
PR unite (30g)
85

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepspeedai/DeepSpeed

Tutte le issue di deepspeedai/DeepSpeed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.