Skill 14 · Huggingface LLM Trainer
Subchapter 14.2
references/hardware_guide.mdMarkdown7 KBView on GitHub
Choosing the right hardware (flavor) is critical for cost-effective training.
Scripts
Convert To Ggufcpu-basic - Basic CPU, testing onlycpu-upgrade - Enhanced CPUUse cases: Dataset validation, preprocessing, testing scripts Not recommended for training: Too slow for any meaningful training
| Flavor | GPU | Memory | Use Case | Cost/hour |
|---|---|---|---|---|
t4-small | NVIDIA T4 | 16GB | <1B models, demos | ~$0.50-1 |
t4-medium | NVIDIA T4 | 16GB | 1-3B models, development | ~$1-2 |
l4x1 | NVIDIA L4 | 24GB | 3-7B models, efficient training | ~$2-3 |
l4x4 | 4x NVIDIA L4 | 96GB | Multi-GPU training | ~$8-12 |
a10g-small | NVIDIA A10G | 24GB | 3-7B models, production | ~$3-4 |
a10g-large | NVIDIA A10G | 24GB | 7-13B models | ~$4-6 |
a10g-largex2 | 2x NVIDIA A10G | 48GB | Multi-GPU, large models | ~$8-12 |
a10g-largex4 | 4x NVIDIA A10G | 96GB | Multi-GPU, very large models | ~$16-24 |
a100-large | NVIDIA A100 | 40GB | 13B+ models, fast training | ~$8-12 |
| Flavor | Type | Use Case |
|---|---|---|
v5e-1x1 | TPU v5e | Small TPU workloads |
v5e-2x2 | 4x TPU v5e | Medium TPU workloads |
v5e-2x4 | 8x TPU v5e | Large TPU workloads |
Note: TPUs require TPU-optimized code. Most TRL training uses GPUs.
Tiny Models (<1B parameters)
t4-smallSmall Models (1-3B parameters)
t4-medium or a10g-smallMedium Models (3-7B parameters)
a10g-small or a10g-largeLarge Models (7-13B parameters)
a10g-large or a100-largeVery Large Models (13B+ parameters)
a100-large with LoRAMinimal Budget (<$5 total)
t4-smallSmall Budget ($5-20)
t4-medium or a10g-smallMedium Budget ($20-50)
a10g-small or a10g-largeLarge Budget ($50-200)
a10g-large or a100-largeQuick Demo/Experiment
t4-smallDevelopment/Iteration
t4-medium or a10g-smallProduction Training
a10g-large or a100-largeResearch/Experimentation
a100-largeFull fine-tuning:
Memory (GB) ≈ (Model params in billions) × 20LoRA fine-tuning:
Memory (GB) ≈ (Model params in billions) × 4Examples:
If hitting memory limits:
Use LoRA/PEFT
peft_config=LoraConfig(r=16, lora_alpha=32)Reduce batch size
per_device_train_batch_size=1Increase gradient accumulation
gradient_accumulation_steps=8 # Effective batch size = 1×8Enable gradient checkpointing
gradient_checkpointing=TrueUse mixed precision
bf16=True # or fp16=TrueUpgrade to larger GPU
Total Cost = (Hours of training) × (Cost per hour)Quick demo:
Development training:
Production training:
Large model with LoRA:
TRL automatically handles multi-GPU training with Accelerate when using multi-GPU flavors.
Multi-GPU flavors:
l4x4 - 4x L4 GPUsa10g-largex2 - 2x A10G GPUsa10g-largex4 - 4x A10G GPUsWhen to use:
Example:
hf_jobs("uv", {
"script": "train.py",
"flavor": "a10g-largex2", # 2 GPUs
"timeout": "4h",
"secrets": {"HF_TOKEN": "$HF_TOKEN"}
})No code changes needed—TRL/Accelerate handles distribution automatically.
Choose a10g when:
Choose a100 when:
Choose single GPU when:
Choose multi-GPU when:
# Model size → Hardware selection
HARDWARE_MAP = {
"<1B": "t4-small",
"1-3B": "a10g-small",
"3-7B": "a10g-large",
"7-13B": "a10g-large (LoRA) or a100-large",
">13B": "a100-large (LoRA required)"
}