# Full-parameter fine-tuning with DeepSpeed ZeRO-3



Learn how to perform full-parameter fine-tuning on large models using DeepSpeed ZeRO-3 and Podstack's on-demand GPU infrastructure.



Training · 2026-08-25 · 4 min read



Modern Large Language Models (LLMs) have grown so large that even a single H100 or A100 often lacks the VRAM required for full-parameter fine-tuning. While techniques like LoRA and QLoRA offer a memory-efficient compromise, they only update a fraction of the model's weights. When your task requires the model to learn deep structural patterns or specialized domain knowledge, full-parameter fine-tuning remains the gold standard.

DeepSpeed ZeRO-3 (Zero Redundancy Optimizer Stage 3) is the industry-standard solution for this challenge. By partitioning model states (parameters, gradients, and optimizer states) across all available GPUs, ZeRO-3 allows you to train models that are significantly larger than the memory of any single device.

In this guide, we’ll walk through setting up a multi-GPU environment for full-parameter fine-tuning using DeepSpeed ZeRO-3 on Podstack.

## Understanding ZeRO-3

Before diving into the code, it is important to understand what ZeRO-3 actually does. Unlike ZeRO-1 (partitioning optimizer states) or ZeRO-2 (partitioning gradients), ZeRO-3 partitions the **model parameters** themselves. 

During the forward and backward passes, the necessary parameters are "gathered" from other GPUs just-in-time and discarded immediately after use. This creates a virtual pool of VRAM, enabling you to fine-tune a 70B parameter model across a cluster of GPUs where it otherwise wouldn't fit.

## Prerequisites

To follow this guide, you will need:
- A Podstack account.
- The Podstack API installed (`pip install podstack-sdk`).
- An environment variable `PODSTACK_API_KEY` set in your terminal.
- A Hugging Face model (e.g., Llama-3-8B or Mistral-7B) and a dataset.

## Step 1: Configuring DeepSpeed

DeepSpeed uses a JSON configuration file to manage its optimization strategies. For full-parameter fine-tuning, the `zero_optimization` block is the most critical part. Save the following as `ds_config.json`:

```json
{
  "fp16": {
    "enabled": "auto"
  },
  "bf16": {
    "enabled": "auto"
  },
  "zero_optimization": {
    "stage": 3,
    "offload_optimizer": {
      "device": "cpu",
      "pin_memory": true
    },
    "offload_param": {
      "device": "cpu",
      "pin_memory": true
    },
    "overlap_comm": true,
    "contiguous_gradients": true,
    "sub_group_size": 1e9,
    "reduce_bucket_size": "auto",
    "stage3_prefetch_bucket_size": "auto",
    "stage3_param_persistence_threshold": "auto",
    "stage3_max_live_parameters": 1e9,
    "stage3_max_reuse_distance": 1e9,
    "stage3_gather_1d_copy_size": 1e8
  },
  "gradient_accumulation_steps": "auto",
  "gradient_clipping": "auto",
  "steps_per_print": 2000,
  "train_batch_size": "auto",
  "train_micro_batch_size_per_gpu": "auto",
  "wall_clock_breakdown": false
}
```

*Tip: `offload_optimizer` and `offload_param` to `cpu` are optional but highly recommended if you are pushing the limits of your VRAM.*

## Step 2: The Training Script

Using the Hugging Face `Trainer` API makes integrating DeepSpeed seamless. The trainer automatically detects the DeepSpeed configuration if passed via the command line or the `TrainingArguments` object.

```python
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer
from datasets import load_dataset
import torch

def train():
    model_id = "meta-llama/Meta-Llama-3-8B"
    dataset = load_dataset("json", data_files="my_data.jsonl", split="train")

    tokenizer = AutoTokenizer.from_pretrained(model_id)
    tokenizer.pad_token = tokenizer.eos_token

    model = AutoModelForCausalLM.from_pretrained(
        model_id,
        torch_dtype=torch.bfloat16,
        use_cache=False # Crucial for training
    )

    training_args = TrainingArguments(
        output_dir="./llama3-finetuned",
        per_device_train_batch_size=4,
        gradient_accumulation_steps=4,
        learning_rate=2e-5,
        num_train_epochs=3,
        bf16=True,
        deepspeed="ds_config.json", # Path to the config created in Step 1
        logging_steps=10,
        save_strategy="epoch"
    )

    trainer = Trainer(
        model=model,
        args=training_args,
        train_dataset=dataset,
        data_collator=lambda data: tokenizer(
            [d["text"] for d in data], 
            padding=True, 
            truncation=True, 
            return_tensors="pt"
        )
    )

    trainer.train()

if __name__ == "__main__":
    train()
```

## Step 3: Launching on Podstack

Podstack makes it easy to spin up multi-GPU instances without the overhead of complex orchestration. Since full-parameter fine-tuning is compute-intensive, we recommend using a node with at least 4x A100 or H100 GPUs.

To launch your training job using the Podstack API:

```text
Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.
```

Because Podstack bills per second, you only pay for the exact duration of the fine-tuning process. Once the `trainer.train()` call completes, the job terminates, and the billing stops instantly.

## Practical Tips for ZeRO-3

1.  **CPU Offloading:** If you encounter Out-of-Memory (OOM) errors even with ZeRO-3, ensure `offload_optimizer` is set to `cpu`. This moves the optimizer states (which are often 2-3x larger than the model weights) to system RAM.
2.  **Network Bottlenecks:** ZeRO-3 involves significant communication between GPUs. On Podstack, our high-speed interconnects handle this efficiently, but you should always aim to keep your `gradient_accumulation_steps` high to maximize compute-to-communication ratios.
3.  **Checkpointing:** Full-parameter checkpoints are massive. Ensure your output volume has enough space to store the model weights (e.g., ~30GB for an 8B model in fp16).

## Conclusion

DeepSpeed ZeRO-3 is a transformative technology for ML engineers, turning a cluster of GPUs into a single, massive memory pool. By combining this with the on-demand, per-second billing of Podstack, you can perform high-end full-parameter fine-tuning without the capital expenditure of a permanent GPU cluster.

Once your model is fine-tuned, you can deploy it instantly as a serverless inference endpoint or a Python GPU function using the same Podstack ecosystem, ensuring a seamless transition from training to production.
