Skip to content

A straightforward method for training your LLM, from downloading data to generating text.

feat(scripts): run every script straight from the repo

FareedKhan-dev2a1efb81dde0
diff --git a/scripts/chat.py b/scripts/chat.py
index d9618fb..1331990 100644
--- a/scripts/chat.py
+++ b/scripts/chat.py
@@ -5,15 +5,20 @@ Model dimensions are read from the checkpoint, so you only pass the path. Use th
template for instruction-tuned models, or --raw for base-model continuation.
One-shot:
- PYTHONPATH=. python scripts/chat.py --ckpt /ephemeral/ckpts/sft.pt --prompt "What is 13 + 29?"
- PYTHONPATH=. python scripts/chat.py --ckpt /ephemeral/ckpts/grpo.pt --prompt "..." --greedy
- PYTHONPATH=. python scripts/chat.py --ckpt /ephemeral/ckpts/base_pretrained.pt --raw --prompt "Once upon a time"
+ python scripts/chat.py --ckpt /ephemeral/ckpts/sft.pt --prompt "What is 13 + 29?"
+ python scripts/chat.py --ckpt /ephemeral/ckpts/grpo.pt --prompt "..." --greedy
+ python scripts/chat.py --ckpt /ephemeral/ckpts/base_pretrained.pt --raw --prompt "Once upon a time"
Interactive REPL (no --prompt):
- PYTHONPATH=. python scripts/chat.py --ckpt /ephemeral/ckpts/sft.pt
+ python scripts/chat.py --ckpt /ephemeral/ckpts/sft.pt
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import argparse
import torch
diff --git a/scripts/eval_post_training.py b/scripts/eval_post_training.py
index 6a76662..959c677 100644
--- a/scripts/eval_post_training.py
+++ b/scripts/eval_post_training.py
@@ -3,10 +3,10 @@ Evaluate any stage checkpoint on GSM8K (greedy) and optionally dump sample gener
Use it to build the headline "GSM8K accuracy across stages" table:
for s in base_pretrained sft dpo ppo grpo; do
- PYTHONPATH=. python scripts/eval_post_training.py --ckpt /ephemeral/ckpts/$s.pt \
+ python scripts/eval_post_training.py --ckpt /ephemeral/ckpts/$s.pt \
--label $s --limit 200 --append /ephemeral/logs/stage_table.jsonl
done
- PYTHONPATH=. python scripts/eval_post_training.py --table /ephemeral/logs/stage_table.jsonl
+ python scripts/eval_post_training.py --table /ephemeral/logs/stage_table.jsonl
Model dimensions are read from the checkpoint's stored ``cfg`` so you don't have to repeat
them. Reward checkpoints (which have a reward head, not an LM head only) still load because
@@ -15,6 +15,11 @@ we keep just the backbone keys for generation.
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import argparse
import json
import os
diff --git a/scripts/prepare_preference_data.py b/scripts/prepare_preference_data.py
index 3b0877b..3bd223e 100644
--- a/scripts/prepare_preference_data.py
+++ b/scripts/prepare_preference_data.py
@@ -7,12 +7,17 @@ Emits JSONL of ``{"prompt", "chosen", "rejected"}`` (train + held-out test). The
test split is what reward-model preference accuracy is measured on.
Example:
- PYTHONPATH=. HF_HOME=/ephemeral/hf_cache python scripts/prepare_preference_data.py \
+ HF_HOME=/ephemeral/hf_cache python scripts/prepare_preference_data.py \
--source both --max_per_source 40000 --out_dir /ephemeral/data
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import argparse
import json
import os
diff --git a/scripts/prepare_pretrain_data.py b/scripts/prepare_pretrain_data.py
index 7b71ee3..4ace471 100644
--- a/scripts/prepare_pretrain_data.py
+++ b/scripts/prepare_pretrain_data.py
@@ -8,10 +8,10 @@ Writes to /ephemeral by default (the 1.5TB disk).
Examples:
# dev split from the Pile validation file
- PYTHONPATH=. python scripts/prepare_pretrain_data.py --split val \
+ python scripts/prepare_pretrain_data.py --split val \
--out /ephemeral/data/pile_dev.h5
# one training shard
- PYTHONPATH=. python scripts/prepare_pretrain_data.py --split train --num_shards 1 \
+ python scripts/prepare_pretrain_data.py --split train --num_shards 1 \
--out /ephemeral/data/pile_train.h5
"""
diff --git a/scripts/prepare_rl_prompts.py b/scripts/prepare_rl_prompts.py
index e716772..99e8c4d 100644
--- a/scripts/prepare_rl_prompts.py
+++ b/scripts/prepare_rl_prompts.py
@@ -6,11 +6,16 @@ Build RL prompt sets ({"prompt", "gold"}) for PPO/GRPO:
where even a weak model gets some non-zero reward so RL has signal to start from)
Example:
- PYTHONPATH=. HF_HOME=/ephemeral/hf_cache python scripts/prepare_rl_prompts.py --out_dir /ephemeral/data
+ HF_HOME=/ephemeral/hf_cache python scripts/prepare_rl_prompts.py --out_dir /ephemeral/data
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import argparse
import json
import os
diff --git a/scripts/prepare_sft_data.py b/scripts/prepare_sft_data.py
index d289602..59474e3 100644
--- a/scripts/prepare_sft_data.py
+++ b/scripts/prepare_sft_data.py
@@ -10,12 +10,17 @@ Datasets (downloaded via HuggingFace ``datasets`` to /ephemeral/hf_cache):
learns the reasoning format the RL verifier rewards)
Example:
- PYTHONPATH=. HF_HOME=/ephemeral/hf_cache python scripts/prepare_sft_data.py \
+ HF_HOME=/ephemeral/hf_cache python scripts/prepare_sft_data.py \
--context_length 1024 --out_dir /ephemeral/data
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import argparse
import os
import re
diff --git a/scripts/pretrain_base.py b/scripts/pretrain_base.py
index 51e3eb4..312b738 100644
--- a/scripts/pretrain_base.py
+++ b/scripts/pretrain_base.py
@@ -8,15 +8,20 @@ a cosine LR schedule with warmup, weight-decay param groups, and periodic checkp
The original ``train_transformer.py`` is left untouched.
Single GPU:
- PYTHONPATH=. python scripts/pretrain_base.py
+ python scripts/pretrain_base.py
Both GPUs:
- PYTHONPATH=. torchrun --standalone --nproc_per_node=2 scripts/pretrain_base.py
+ torchrun --standalone --nproc_per_node=2 scripts/pretrain_base.py
Override any config field from the CLI, e.g. ``--batch_size 16 --train_steps 50000``.
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import contextlib
import os
import time
diff --git a/scripts/train_dpo.py b/scripts/train_dpo.py
index bf22286..fc6aa0f 100644
--- a/scripts/train_dpo.py
+++ b/scripts/train_dpo.py
@@ -5,12 +5,17 @@ The policy is initialized from the SFT checkpoint; a frozen deep copy of it serv
DPO/KTO reference (ORPO is reference-free). Reports implicit-reward accuracy on held-out
preferences and GSM8K dev accuracy.
- PYTHONPATH=. python scripts/train_dpo.py --loss_type dpo --beta 0.1
- PYTHONPATH=. torchrun --standalone --nproc_per_node=2 scripts/train_dpo.py
+ python scripts/train_dpo.py --loss_type dpo --beta 0.1
+ torchrun --standalone --nproc_per_node=2 scripts/train_dpo.py
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import time
import torch
diff --git a/scripts/train_grpo.py b/scripts/train_grpo.py
index 3b7e798..0b1ccc0 100644
--- a/scripts/train_grpo.py
+++ b/scripts/train_grpo.py
@@ -7,12 +7,17 @@ verifier, compute group-relative advantages, and update with a token-level clipp
surrogate + KL-to-reference penalty. An arithmetic warm-up curriculum runs first so the
policy gets non-zero reward variance before facing full GSM8K.
- PYTHONPATH=. python scripts/train_grpo.py
- PYTHONPATH=. torchrun --standalone --nproc_per_node=2 scripts/train_grpo.py
+ python scripts/train_grpo.py
+ torchrun --standalone --nproc_per_node=2 scripts/train_grpo.py
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import time
import torch
diff --git a/scripts/train_ppo.py b/scripts/train_ppo.py
index c415c4e..f9fc103 100644
--- a/scripts/train_ppo.py
+++ b/scripts/train_ppo.py
@@ -6,12 +6,17 @@ reward, or a trained reward model), add a per-token KL-to-reference penalty, com
advantages with the shared value head, then run several clipped-surrogate update epochs.
Reports mean reward, KL, value loss, clip fraction, and held-out GSM8K accuracy.
- PYTHONPATH=. python scripts/train_ppo.py --reward_source verifier
- PYTHONPATH=. torchrun --standalone --nproc_per_node=2 scripts/train_ppo.py
+ python scripts/train_ppo.py --reward_source verifier
+ torchrun --standalone --nproc_per_node=2 scripts/train_ppo.py
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import time
import torch
diff --git a/scripts/train_reward.py b/scripts/train_reward.py
index caec1ad..a9191df 100644
--- a/scripts/train_reward.py
+++ b/scripts/train_reward.py
@@ -5,13 +5,18 @@ Initializes the reward backbone from the SFT checkpoint, adds a scalar reward he
trains so chosen responses score above rejected ones. Reports held-out preference accuracy.
Single GPU:
- PYTHONPATH=. python scripts/train_reward.py
+ python scripts/train_reward.py
Both GPUs:
- PYTHONPATH=. torchrun --standalone --nproc_per_node=2 scripts/train_reward.py
+ torchrun --standalone --nproc_per_node=2 scripts/train_reward.py
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import time
import torch
diff --git a/scripts/train_sft.py b/scripts/train_sft.py
index 74fb3ce..0649fef 100644
--- a/scripts/train_sft.py
+++ b/scripts/train_sft.py
@@ -5,13 +5,18 @@ Loads the base checkpoint, trains with the prompt-masked SFT loss, periodically
masked dev loss, and saves an SFT checkpoint. DDP + bf16, single code path for 1 or N GPUs.
Single GPU:
- PYTHONPATH=. python scripts/train_sft.py
+ python scripts/train_sft.py
Both GPUs:
- PYTHONPATH=. torchrun --standalone --nproc_per_node=2 scripts/train_sft.py
+ torchrun --standalone --nproc_per_node=2 scripts/train_sft.py
"""
from __future__ import annotations
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # run from the repo without installing
+
import contextlib
import math
import time