DeepSpeed
Train and fine-tune models that do not fit one GPU by sharding optimizer state, gradients and parameters (ZeRO) and optionally offloading to CPU or NVMe, driven by one JSON config.
Scope: this one library: install, ZeRO config, launch, multi-node, offload, checkpoints, update, troubleshoot. It is usually reached through a trainer; the trainer's own skill covers its flags. Whether to fine-tune and method choice belong to fine-tuning-llms. DeepSpeed-MII inference is a separate product (deepspeed-mii).
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Never print tokens.
python3 -c 'import deepspeed, torch; print("deepspeed", deepspeed.__version__, "torch", torch.__version__, "cuda", torch.cuda.is_available())' 2>/dev/null
command -v deepspeed ds_report ninja nvcc; nvcc --version 2>/dev/null | tail -1
echo "CUDA_HOME=${CUDA_HOME:-unset}"
ds_report 2>/dev/null | head -60
nvidia-smi --query-gpu=index,name,memory.total,memory.used --format=csv 2>/dev/null
pip list 2>/dev/null | grep -iE '^(deepspeed|torch|transformers|accelerate|peft|trl|llamafactory) '
free -h 2>/dev/null | head -2; ulimit -l; df -h . 2>/dev/null
ls hostfile ~/.deepspeed_env 2>/dev/null; ls ds_config*.json 2>/dev/null
Decision flow
- Not installed -> PyTorch first, then
pip install deepspeed (references/install.md).
- Model plus optimizer states do not fit -> pick a ZeRO stage (
references/zero-config.md): try 2 before 3.
- Still no fit -> CPU offload, then NVMe (
references/zero-config.md).
- Using Trainer, TRL, Accelerate or LLaMA-Factory -> pass a config with
"auto" values (references/integrations.md).
- 2+ nodes -> hostfile and launcher (
references/launch-and-multinode.md).
- Need a normal checkpoint from ZeRO shards ->
zero_to_fp32 (references/checkpoints.md).
- Error text ->
references/troubleshooting.md.
Rules
- Ask before changing the system. Installs, compiler/CUDA changes, jobs and multi-node launches need approval and an undo path.
- Install PyTorch before DeepSpeed. Ops are JIT-compiled with nvcc and ninja; the system CUDA toolkit must match what PyTorch was built with (
references/install.md).
- Start at the lowest stage that fits. Each stage and offload level saves memory and costs communication; the HF docs advise ZeRO-2 unless the model does not fit.
- Use
"auto" with Hugging Face trainers. Hand-set batch size, accumulation or precision that disagree with the trainer's arguments can train silently with wrong values.
- All ranks must call
save_checkpoint. Calling it on rank 0 only hangs.
- Multi-node means SSH and open ports. Keep hostfiles, rendezvous ports and NCCL traffic on a private network; never expose them publicly.
- Pinned memory is real RAM.
pin_memory now defaults to true for offload; on hosts with a low ulimit -l set it to false if you hit OOM.
- Record the version. Run
ds_report and keep its output with the run.
- Secrets never touch output.
HF_TOKEN and WANDB_API_KEY come from the environment or 0600 files; .deepspeed_env forwards variables to workers, so keep secrets out of it.
Workflows
1. Install and check
2. Write a ZeRO config
3. Launch
4. Offload when needed
5. Multi-node
6. Save and convert
7. Update
Reference index
references/install.md: PyPI, JIT vs prebuilt ops, DS_BUILD_*, CUDA toolkit matching, ds_report.
references/zero-config.md: ZeRO stages, key fields, offload, precision, batch-size rule, templates/.
references/integrations.md: Trainer, Accelerate, TRL, PEFT, LLaMA-Factory, plain deepspeed.initialize.
references/launch-and-multinode.md: deepspeed launcher flags, hostfile, no-SSH mode, .deepspeed_env.
references/checkpoints.md: save_checkpoint, zero_to_fp32, 16-bit saves, universal checkpointing.
references/troubleshooting.md: symptoms and fixes.
references/updating.md: cadence, pins, upgrade routine.
templates/ds_zero2.json, templates/ds_zero3.json, templates/ds_zero3_offload.json, templates/hostfile.example: starters.
Companion skills
Install with npx skills add ScaleDockHQ/llm-skills --skill <name>:
fine-tuning-llms: decide, prepare data, choose method and hardware.
trl, llama-factory, axolotl, peft: trainers and adapters that call DeepSpeed.
deepspeed-mii: DeepSpeed inference. vllm: serving.
1---2name: deepspeed3description: DeepSpeed is Microsoft's training library for large models with ZeRO stages 1-3, CPU/NVMe offload, the deepspeed launcher, ds_config.json, ds_report and zero_to_fp32. Use to install it (JIT ops, nvcc, DS_BUILD_OPS), write a ZeRO config for Hugging Face Trainer, TRL, Accelerate or LLaMA-Factory, run multi-GPU or multi-node jobs with a hostfile, offload to CPU or NVMe, convert ZeRO checkpoints to fp32 weights, or fix errors such as CUDA_HOME not found, batch-size mismatch, ZeRO-3 save problems and OOM. Not for DeepSpeed-MII inference (deepspeed-mii) or method choice (fine-tuning-llms).4license: MIT5compatibility: Linux with NVIDIA (also AMD ROCm, Intel XPU/Gaudi, Ascend NPU) accelerators, PyTorch installed first, Python 3.x, a CUDA toolkit with nvcc for JIT ops, ninja. Uses deepspeed, ds_report, curl and jq via shell. Installs, jobs and checkpoint conversions need the user's approval.6metadata:7 source: https://skillmd.com/skills/scaledockhq/deepspeed8 author: ScaleDockHQ9 version: "0.1.0"10---1112# DeepSpeed1314Train and fine-tune models that do not fit one GPU by sharding optimizer state, gradients and parameters (ZeRO) and optionally offloading to CPU or NVMe, driven by one JSON config.1516**Scope:** this one library: install, ZeRO config, launch, multi-node, offload, checkpoints, update, troubleshoot. It is usually reached through a trainer; the trainer's own skill covers its flags. Whether to fine-tune and method choice belong to `fine-tuning-llms`. DeepSpeed-MII inference is a separate product (`deepspeed-mii`).1718Work through the steps in order. Load a reference only when a step names it.1920## Discover first2122Read-only. Never print tokens.2324```bash25python3 -c 'import deepspeed, torch; print("deepspeed", deepspeed.__version__, "torch", torch.__version__, "cuda", torch.cuda.is_available())' 2>/dev/null26command -v deepspeed ds_report ninja nvcc; nvcc --version 2>/dev/null | tail -127echo "CUDA_HOME=${CUDA_HOME:-unset}"28ds_report 2>/dev/null | head -6029nvidia-smi --query-gpu=index,name,memory.total,memory.used --format=csv 2>/dev/null30pip list 2>/dev/null | grep -iE '^(deepspeed|torch|transformers|accelerate|peft|trl|llamafactory) '31free -h 2>/dev/null | head -2; ulimit -l; df -h . 2>/dev/null32ls hostfile ~/.deepspeed_env 2>/dev/null; ls ds_config*.json 2>/dev/null33```3435## Decision flow36371. Not installed -> PyTorch first, then `pip install deepspeed` (`references/install.md`).382. Model plus optimizer states do not fit -> pick a ZeRO stage (`references/zero-config.md`): try 2 before 3.393. Still no fit -> CPU offload, then NVMe (`references/zero-config.md`).404. Using Trainer, TRL, Accelerate or LLaMA-Factory -> pass a config with `"auto"` values (`references/integrations.md`).415. 2+ nodes -> hostfile and launcher (`references/launch-and-multinode.md`).426. Need a normal checkpoint from ZeRO shards -> `zero_to_fp32` (`references/checkpoints.md`).437. Error text -> `references/troubleshooting.md`.4445## Rules4647- **Ask before changing the system.** Installs, compiler/CUDA changes, jobs and multi-node launches need approval and an undo path.48- **Install PyTorch before DeepSpeed.** Ops are JIT-compiled with nvcc and ninja; the system CUDA toolkit must match what PyTorch was built with (`references/install.md`).49- **Start at the lowest stage that fits.** Each stage and offload level saves memory and costs communication; the HF docs advise ZeRO-2 unless the model does not fit.50- **Use `"auto"` with Hugging Face trainers.** Hand-set batch size, accumulation or precision that disagree with the trainer's arguments can train silently with wrong values.51- **All ranks must call `save_checkpoint`.** Calling it on rank 0 only hangs.52- **Multi-node means SSH and open ports.** Keep hostfiles, rendezvous ports and NCCL traffic on a private network; never expose them publicly.53- **Pinned memory is real RAM.** `pin_memory` now defaults to true for offload; on hosts with a low `ulimit -l` set it to `false` if you hit OOM.54- **Record the version.** Run `ds_report` and keep its output with the run.55- **Secrets never touch output.** `HF_TOKEN` and `WANDB_API_KEY` come from the environment or `0600` files; `.deepspeed_env` forwards variables to workers, so keep secrets out of it.5657## Workflows5859### 1. Install and check6061- [ ] Install PyTorch, then `pip install deepspeed` (`references/install.md`).62- [ ] Verify: `ds_report` lists ops as compatible/installed; `import deepspeed` works.6364### 2. Write a ZeRO config6566- [ ] `cp templates/ds_zero2.json ds_config.json` (or `ds_zero3.json`, `ds_zero3_offload.json`) (`references/zero-config.md`).67- [ ] Keep batch, accumulation, clipping and precision as `"auto"` when a trainer fills them.6869### 3. Launch7071- [ ] Trainer or script: `deepspeed --num_gpus N train.py --deepspeed ds_config.json`, `torchrun`, or `accelerate launch` (`references/launch-and-multinode.md`).72- [ ] Verify: all ranks progress; peak GPU memory is below capacity; step time is acceptable.7374### 4. Offload when needed7576- [ ] Add `offload_optimizer` (stages 1-3) and then `offload_param` (stage 3 only) (`references/zero-config.md`).77- [ ] NVMe needs libaio and the `aio` section; check `ds_report`.7879### 5. Multi-node8081- [ ] Hostfile with `slots=`, passwordless SSH or `--no_ssh`, identical environments (`references/launch-and-multinode.md`).8283### 6. Save and convert8485- [ ] ZeRO-3 with `stage3_gather_16bit_weights_on_model_save: true`, or convert shards with `zero_to_fp32.py` (`references/checkpoints.md`).86- [ ] Verify: load the converted weights without DeepSpeed and generate.8788### 7. Update8990- [ ] Read release notes, new venv, run a smoke job (`references/updating.md`).9192## Reference index9394- `references/install.md`: PyPI, JIT vs prebuilt ops, `DS_BUILD_*`, CUDA toolkit matching, `ds_report`.95- `references/zero-config.md`: ZeRO stages, key fields, offload, precision, batch-size rule, `templates/`.96- `references/integrations.md`: Trainer, Accelerate, TRL, PEFT, LLaMA-Factory, plain `deepspeed.initialize`.97- `references/launch-and-multinode.md`: `deepspeed` launcher flags, hostfile, no-SSH mode, `.deepspeed_env`.98- `references/checkpoints.md`: `save_checkpoint`, `zero_to_fp32`, 16-bit saves, universal checkpointing.99- `references/troubleshooting.md`: symptoms and fixes.100- `references/updating.md`: cadence, pins, upgrade routine.101- `templates/ds_zero2.json`, `templates/ds_zero3.json`, `templates/ds_zero3_offload.json`, `templates/hostfile.example`: starters.102103## Companion skills104105Install with `npx skills add ScaleDockHQ/llm-skills --skill <name>`:106107- `fine-tuning-llms`: decide, prepare data, choose method and hardware.108- `trl`, `llama-factory`, `axolotl`, `peft`: trainers and adapters that call DeepSpeed.109- `deepspeed-mii`: DeepSpeed inference. `vllm`: serving.