Upload folder using huggingface_hub
Browse files
src/mathcompose/train/train.py
CHANGED
|
@@ -30,16 +30,19 @@ def _presets_for(vram_gb: float) -> dict:
|
|
| 30 |
"""Per-GPU QLoRA defaults for a ~1.5B model. Explicit CLI flags override these;
|
| 31 |
these override the yaml config."""
|
| 32 |
big = vram_gb >= 70 # 80GB A100/H100 vs 40GB
|
|
|
|
|
|
|
|
|
|
| 33 |
return {
|
| 34 |
# T4 has no bf16 and its fp16 GradScaler has been unreliable -> amp off (fp32).
|
| 35 |
-
"t4": dict(batch_size=1, grad_accum=16, max_length=2048, grad_ckpt="on",
|
| 36 |
-
"l4": dict(batch_size=
|
| 37 |
-
"a100": dict(batch_size=
|
| 38 |
-
max_length=4096, grad_ckpt="
|
| 39 |
-
"h100": dict(batch_size=
|
| 40 |
-
"generic_big": dict(batch_size=
|
| 41 |
-
"generic_mid": dict(batch_size=
|
| 42 |
-
"generic_small": dict(batch_size=1, grad_accum=16, max_length=2048, grad_ckpt="on",
|
| 43 |
}
|
| 44 |
|
| 45 |
|
|
@@ -71,6 +74,9 @@ def detect_gpu_preset(force: str = "auto") -> tuple[str, dict]:
|
|
| 71 |
|
| 72 |
|
| 73 |
def build_and_train(args) -> str:
|
|
|
|
|
|
|
|
|
|
| 74 |
import torch
|
| 75 |
from datasets import load_dataset
|
| 76 |
from transformers import AutoModelForCausalLM
|
|
|
|
| 30 |
"""Per-GPU QLoRA defaults for a ~1.5B model. Explicit CLI flags override these;
|
| 31 |
these override the yaml config."""
|
| 32 |
big = vram_gb >= 70 # 80GB A100/H100 vs 40GB
|
| 33 |
+
# Gradient checkpointing stays ON everywhere: with Qwen's 152k vocab the logits
|
| 34 |
+
# + activations at seq 4096 dwarf the (tiny, 4-bit) weights, so checkpointing is
|
| 35 |
+
# what keeps even an 80GB card in budget. Effective batch is ~16 via accumulation.
|
| 36 |
return {
|
| 37 |
# T4 has no bf16 and its fp16 GradScaler has been unreliable -> amp off (fp32).
|
| 38 |
+
"t4": dict(batch_size=1, grad_accum=16, max_length=2048, grad_ckpt="on", amp="off"),
|
| 39 |
+
"l4": dict(batch_size=2, grad_accum=8, max_length=3072, grad_ckpt="on", amp="auto"),
|
| 40 |
+
"a100": dict(batch_size=8 if big else 4, grad_accum=2 if big else 4,
|
| 41 |
+
max_length=4096, grad_ckpt="on", amp="auto"),
|
| 42 |
+
"h100": dict(batch_size=8, grad_accum=2, max_length=4096, grad_ckpt="on", amp="auto"),
|
| 43 |
+
"generic_big": dict(batch_size=4, grad_accum=4, max_length=4096, grad_ckpt="on", amp="auto"),
|
| 44 |
+
"generic_mid": dict(batch_size=2, grad_accum=8, max_length=3072, grad_ckpt="on", amp="auto"),
|
| 45 |
+
"generic_small": dict(batch_size=1, grad_accum=16, max_length=2048, grad_ckpt="on", amp="auto"),
|
| 46 |
}
|
| 47 |
|
| 48 |
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
def build_and_train(args) -> str:
|
| 77 |
+
import os
|
| 78 |
+
# reduce fragmentation OOMs (set before CUDA initializes)
|
| 79 |
+
os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
|
| 80 |
import torch
|
| 81 |
from datasets import load_dataset
|
| 82 |
from transformers import AutoModelForCausalLM
|