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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Daimon Training Template β RunPod
|
| 2 |
+
|
| 3 |
+
Full-parameter SFT of Qwen3.6-35B-A3B (MoE) on a single H200 SXM 141GB GPU. All 35B parameters trained in bf16 precision using DeepSpeed ZeRO-2 with CPU-offloaded Adafactor optimizer.
|
| 4 |
+
|
| 5 |
+
No LoRA. No adapters. No frozen layers. No half measures.
|
| 6 |
+
|
| 7 |
+
Liberation Labs, June 2026.
|
| 8 |
+
|
| 9 |
+
## Memory Budget
|
| 10 |
+
|
| 11 |
+
Full-parameter SFT on a 35B MoE model requires careful memory planning across GPU and CPU.
|
| 12 |
+
|
| 13 |
+
### GPU Memory (H200 SXM β 141GB VRAM)
|
| 14 |
+
|
| 15 |
+
| Component | Size | Location |
|
| 16 |
+
|-----------|------|----------|
|
| 17 |
+
| Model parameters (bf16) | ~70 GB | GPU |
|
| 18 |
+
| Activations (with gradient checkpointing) | ~20 GB | GPU |
|
| 19 |
+
| **GPU Total** | **~90 GB** | **of 141 GB** |
|
| 20 |
+
|
| 21 |
+
### CPU Memory (System RAM β 188GB)
|
| 22 |
+
|
| 23 |
+
| Component | Size | Location |
|
| 24 |
+
|-----------|------|----------|
|
| 25 |
+
| Gradients (bf16, ZeRO-2 offload) | ~70 GB | CPU |
|
| 26 |
+
| Adafactor optimizer states | ~35 GB | CPU |
|
| 27 |
+
| **CPU Total** | **~105 GB** | **of 188 GB** |
|
| 28 |
+
|
| 29 |
+
### Why Adafactor, Not AdamW
|
| 30 |
+
|
| 31 |
+
AdamW stores two fp32 states per parameter (momentum and variance):
|
| 32 |
+
- 35B params x 4 bytes x 2 states = **280 GB**
|
| 33 |
+
- System RAM available: 188 GB
|
| 34 |
+
- **Does not fit.** Not even close.
|
| 35 |
+
|
| 36 |
+
Adafactor uses factored second moments β approximately one state per parameter in mixed precision, bringing optimizer memory to ~35GB. This is the only viable optimizer for full SFT on a single node with 188GB system RAM.
|
| 37 |
+
|
| 38 |
+
### Checkpoint Storage
|
| 39 |
+
|
| 40 |
+
Full model checkpoints are **~70GB each** (entire model in bf16). With `save_total_limit=3`:
|
| 41 |
+
- Checkpoint space: ~210 GB
|
| 42 |
+
- Model cache: ~70 GB
|
| 43 |
+
- Training data: ~5-10 GB
|
| 44 |
+
- **Recommended persistent volume: 400 GB**
|
| 45 |
+
|
| 46 |
+
## Hardware Requirements
|
| 47 |
+
|
| 48 |
+
| Resource | Minimum | Recommended |
|
| 49 |
+
|----------|---------|-------------|
|
| 50 |
+
| GPU | 1x H200 SXM 141GB | 1x H200 SXM 141GB |
|
| 51 |
+
| System RAM | 180 GB | 200 GB |
|
| 52 |
+
| Disk (/workspace) | 300 GB | 400 GB |
|
| 53 |
+
|
| 54 |
+
**Why a single H200?** The H200 SXM has 141GB VRAM β enough to hold the entire 35B model in bf16 (~70GB) plus activations with gradient checkpointing (~20GB). DeepSpeed ZeRO-2 offloads optimizer states and gradients to CPU RAM. This avoids multi-GPU coordination complexity while training all parameters.
|
| 55 |
+
|
| 56 |
+
**System RAM is critical.** Unlike LoRA (where optimizer states are tiny), full SFT offloads ~105GB to CPU. Pods with < 180GB system RAM will OOM during training.
|
| 57 |
+
|
| 58 |
+
## Environment Variables
|
| 59 |
+
|
| 60 |
+
Set these in the RunPod pod template:
|
| 61 |
+
|
| 62 |
+
| Variable | Required | Description |
|
| 63 |
+
|----------|----------|-------------|
|
| 64 |
+
| `HF_TOKEN` | Yes | HuggingFace token (model is gated) |
|
| 65 |
+
| `DAIMON_CONFIG` | No | Override config path (default: bundled YAML) |
|
| 66 |
+
| `DAIMON_MODEL` | No | Override model path/ID |
|
| 67 |
+
| `DAIMON_OUTPUT` | No | Override output directory |
|
| 68 |
+
|
| 69 |
+
## Step-by-Step
|
| 70 |
+
|
| 71 |
+
### 1. Provision the Pod
|
| 72 |
+
|
| 73 |
+
- Template: `RunPod PyTorch 2.x` (or any CUDA 12.x image)
|
| 74 |
+
- GPU: `1x H200 SXM 141GB`
|
| 75 |
+
- Container disk: 50 GB (for OS + packages)
|
| 76 |
+
- Volume disk: **400 GB** (persistent, mounted at `/workspace`)
|
| 77 |
+
- Set `HF_TOKEN` in environment variables
|
| 78 |
+
- **Verify system RAM >= 180GB before starting**
|
| 79 |
+
|
| 80 |
+
### 2. Upload Template Files
|
| 81 |
+
|
| 82 |
+
Copy this directory to `/workspace/runpod-template/` on the pod:
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
# From your local machine:
|
| 86 |
+
scp -r runpod-template/ root@<pod-ip>:/workspace/
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
Or clone the repo:
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
cd /workspace && git clone <repo-url> && cp -r Daimonion/runpod-template /workspace/
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### 3. Run Setup
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
export HF_TOKEN="hf_your_token_here"
|
| 99 |
+
bash /workspace/runpod-template/setup.sh
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
This installs dependencies (pinned versions including DeepSpeed), downloads the model (~70GB), downloads training data, and verifies the environment. Takes 15-30 minutes depending on network speed.
|
| 103 |
+
|
| 104 |
+
### 4. Run Validation Tests
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
python3 /workspace/runpod-template/test_template.py
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
All 9 tests should pass before training. Tests now check both GPU VRAM and system RAM, validate the DeepSpeed ZeRO-2 config, confirm no LoRA artifacts remain, and estimate memory for both GPU and CPU.
|
| 111 |
+
|
| 112 |
+
### 5. Launch Training
|
| 113 |
+
|
| 114 |
+
```bash
|
| 115 |
+
bash /workspace/runpod-template/launch.sh
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
Training runs via `deepspeed --num_gpus=1` with ZeRO Stage 2 CPU offload. The DeepSpeed launcher manages process initialization and ZeRO optimizer wrapping.
|
| 119 |
+
|
| 120 |
+
### 6. Monitor
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
# GPU utilization and VRAM usage
|
| 124 |
+
watch -n 5 nvidia-smi
|
| 125 |
+
|
| 126 |
+
# Training logs
|
| 127 |
+
tail -f /workspace/daimon-sft/logs/training_*.log
|
| 128 |
+
|
| 129 |
+
# CPU memory (watch for offloaded optimizer pressure)
|
| 130 |
+
watch -n 10 free -g
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## Resuming After Pod Restart
|
| 134 |
+
|
| 135 |
+
If the pod is terminated (spot instance preemption, manual stop, etc.), checkpoints are saved on the persistent volume. To resume:
|
| 136 |
+
|
| 137 |
+
1. Start a new pod with the same persistent volume
|
| 138 |
+
2. Run setup.sh again (it skips already-downloaded files)
|
| 139 |
+
3. Run launch.sh β it automatically finds the latest checkpoint
|
| 140 |
+
|
| 141 |
+
The training script scans `/workspace/daimon-sft/checkpoint-*` and resumes from the most recent one.
|
| 142 |
+
|
| 143 |
+
## Post-Training
|
| 144 |
+
|
| 145 |
+
After training completes:
|
| 146 |
+
|
| 147 |
+
1. **Copy the full model:** `scp -r root@<pod-ip>:/workspace/daimon-sft/final ./daimon-full-model/`
|
| 148 |
+
- This is the complete trained model (~70GB), not just adapters
|
| 149 |
+
- It can be loaded directly with `AutoModelForCausalLM.from_pretrained()`
|
| 150 |
+
2. **Delete checkpoints:** `rm -rf /workspace/daimon-sft/checkpoint-*`
|
| 151 |
+
- Each checkpoint is ~70GB β free the space
|
| 152 |
+
3. **Terminate the pod** and delete the persistent volume if no longer needed
|
| 153 |
+
|
| 154 |
+
## Cost Estimates
|
| 155 |
+
|
| 156 |
+
Prices as of June 2026 (RunPod community cloud):
|
| 157 |
+
|
| 158 |
+
| Configuration | $/hour | Est. time | Est. total |
|
| 159 |
+
|--------------|--------|-----------|------------|
|
| 160 |
+
| 1x H200 SXM 141GB | ~$4.39 | 20-30 hrs | $88-132 |
|
| 161 |
+
|
| 162 |
+
Full SFT is slower per step than LoRA (all 35B parameters updated per step), but produces a standalone model that doesn't need adapter merging or base model inference.
|
| 163 |
+
|
| 164 |
+
## File Inventory
|
| 165 |
+
|
| 166 |
+
| File | Purpose |
|
| 167 |
+
|------|---------|
|
| 168 |
+
| `setup.sh` | First-boot: install deps (pinned versions + DeepSpeed), download model & data |
|
| 169 |
+
| `train_daimon.py` | Main training script (SFTTrainer + Adafactor + DeepSpeed ZeRO-2) |
|
| 170 |
+
| `train_daimon_config.yaml` | All hyperparameters in one place |
|
| 171 |
+
| `ds_config_zero2.json` | DeepSpeed ZeRO Stage 2 config with CPU optimizer offload |
|
| 172 |
+
| `launch.sh` | Pre-flight checks + DeepSpeed launch command |
|
| 173 |
+
| `test_template.py` | Validation tests β GPU, CPU RAM, config, memory estimates |
|
| 174 |
+
| `ds_config_zero3.json` | **(LEGACY)** Old ZeRO-3 config, no longer used |
|
| 175 |
+
|
| 176 |
+
## Configuration
|
| 177 |
+
|
| 178 |
+
Edit `train_daimon_config.yaml` to change hyperparameters. Key settings:
|
| 179 |
+
|
| 180 |
+
- `max_seq_length: 4096` β Reduced from 8192 for full SFT (activation memory scales with sequence length). Increase if needed, but monitor GPU OOM.
|
| 181 |
+
- `learning_rate: 5e-6` β Much lower than LoRA's 2e-4. Full SFT updates all parameters including MoE routing gates; higher rates destabilize routing.
|
| 182 |
+
- `optimizer: adafactor` β Only viable optimizer. AdamW needs 280GB CPU RAM.
|
| 183 |
+
- `deepspeed_config: ds_config_zero2.json` β ZeRO-2 with CPU optimizer offload.
|
| 184 |
+
- `per_device_train_batch_size: 1` β With gradient_accumulation_steps=8, effective batch is 8.
|
| 185 |
+
- `save_steps: 500` β Full model checkpoints are ~70GB each. With save_total_limit=3, up to ~210GB checkpoint space.
|
| 186 |
+
- `save_total_limit: 3` β Keep only 3 checkpoints to avoid filling the 400GB volume.
|
| 187 |
+
- `model_revision` β Pinned to a specific HuggingFace commit hash for supply-chain security.
|
| 188 |
+
|
| 189 |
+
## Known Issues and Solutions
|
| 190 |
+
|
| 191 |
+
| Issue | Cause | Fix |
|
| 192 |
+
|-------|-------|-----|
|
| 193 |
+
| GPU OOM during training | Sequence too long or batch size > 1 | Reduce max_seq_length, verify per_device_train_batch_size=1, verify gradient_checkpointing is on |
|
| 194 |
+
| CPU OOM (killed by OS) | System RAM < 180GB or other processes using RAM | Provision pod with >= 188GB RAM, kill unnecessary processes |
|
| 195 |
+
| Disk full | Full checkpoints are ~70GB each | Reduce save_total_limit, increase volume to 400GB |
|
| 196 |
+
| Silent sequence truncation | max_seq_length too low | Increase in config; script pre-splits long sequences |
|
| 197 |
+
| Training killed by agent | Background process interference | This template runs as isolated DeepSpeed process |
|
| 198 |
+
| Lost checkpoints | Saved to container disk (not volume) | All output goes to /workspace/ (persistent) |
|
| 199 |
+
| DeepSpeed optimizer conflict | Optimizer set in both DS config and script | DS config has NO optimizer block β Adafactor managed by training script |
|