Add Stage 2 curriculum and graceful checkpoint shutdown
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
- `check_laoyao_megatron_inference_ready.sh`: 检查 checkpoint、端口、GPU 和相关容器状态。
|
||||
- `query_laoyao_megatron_server.sh`: 对 Megatron inference server 发送简单 prompt。
|
||||
- `stop_laoyao_megatron_server.sh`: 停止 Megatron inference server 容器。
|
||||
- `graceful_stop_megatron_training.sh`: 向 torchrun 的训练 worker 发送信号,在当前
|
||||
iteration 完成后临时保存 checkpoint 并安全退出。
|
||||
|
||||
## g0050 下载与部署
|
||||
|
||||
@@ -59,3 +61,52 @@ bash scripts/resume_pretrain_8192_8gpu_mbs14.sh
|
||||
- `save_interval=2500`, `eval_interval=15000`, `eval_iters=10`
|
||||
- `--use-distributed-optimizer --overlap-grad-reduce --overlap-param-gather`
|
||||
- `--recompute-granularity full --recompute-method uniform --recompute-num-layers 1`
|
||||
|
||||
## Stage1-2 多 shard 恢复训练
|
||||
|
||||
`resume_stage1_2_pretrain_8192_8gpu_mbs14.sh` 用于从 stage1-2 Megatron
|
||||
checkpoint 恢复。stage1-2 weighted manifest 包含数百个 indexed dataset prefix;每个
|
||||
rank 会同时 mmap 对应的 `.bin`、`.idx` 和 dataset index 文件。Docker 默认
|
||||
`nofile=1024` 会在数据集初始化阶段触发:
|
||||
|
||||
```text
|
||||
OSError: [Errno 24] Too many open files
|
||||
```
|
||||
|
||||
因此该入口固定设置:
|
||||
|
||||
```text
|
||||
--ulimit nofile=1048576:1048576
|
||||
```
|
||||
|
||||
不要通过减少 shard 或丢弃数据绕过这个限制。恢复前应确认 `LOAD_DIR` 下的
|
||||
`latest_checkpointed_iteration.txt` 指向目标 checkpoint,并保留 `load_optim=True` 和
|
||||
`load_rng=True` 以恢复优化器与 RNG 状态。
|
||||
|
||||
## 信号触发的临时 checkpoint
|
||||
|
||||
`laoyao_2b_moe_pretrain.py` 默认启用 Megatron-Bridge 原生 distributed signal
|
||||
handler,并监听 `SIGINT`。收到信号后,各 rank 会:
|
||||
|
||||
1. 完成当前 iteration。
|
||||
2. 使用标准 checkpoint 路径保存模型、优化器、LR scheduler、RNG 和数据迭代状态。
|
||||
3. 完成分布式 barrier 后退出。
|
||||
|
||||
不要直接执行 `docker kill --signal=SIGINT <container>`。容器 PID 1 是
|
||||
`torchrun`;它收到 SIGINT 后会启动 elastic worker 回收流程,可能在 checkpoint
|
||||
写完前终止 rank。应运行:
|
||||
|
||||
```bash
|
||||
CHECKPOINT_DIR=/mnt/beegfs/yi/laoyao-2b-pretraining/runs/<run>/checkpoints \
|
||||
bash scripts/graceful_stop_megatron_training.sh <container-name>
|
||||
```
|
||||
|
||||
脚本通过 `docker top` 只选择 torchrun 的直接 worker 子进程,不会误发给
|
||||
dataloader worker,也不会先终止 torchrun。默认等待 900 秒且不会在超时后自动
|
||||
强杀容器。训练入口也支持显式切换信号:
|
||||
|
||||
```text
|
||||
--graceful-exit-signal SIGINT # 默认
|
||||
--graceful-exit-signal SIGTERM
|
||||
--disable-graceful-exit-on-signal
|
||||
```
|
||||
|
||||
@@ -4,7 +4,7 @@ set -euo pipefail
|
||||
REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
||||
IMAGE_TAG="${IMAGE_TAG:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
BASE_IMAGE="${BASE_IMAGE:-ti-coding-agent/nemo-bridge-flashattn4:26.06}"
|
||||
INSTALL_FLASH_ATTN4="${INSTALL_FLASH_ATTN4:-0}"
|
||||
INSTALL_FLASH_ATTN4="${INSTALL_FLASH_ATTN4:-1}"
|
||||
|
||||
export http_proxy="${http_proxy:-http://100.72.0.101:8888}"
|
||||
export https_proxy="${https_proxy:-http://100.72.0.101:8888}"
|
||||
@@ -24,13 +24,25 @@ docker build \
|
||||
docker run --rm --gpus all --ipc=host --network=host "$IMAGE_TAG" bash -lc '
|
||||
python3 - <<PY
|
||||
import importlib.metadata as metadata
|
||||
for package in ["torch", "transformer-engine", "flash-attn", "flash-attn-4", "nvidia-cutlass-dsl", "megatron-core", "megatron-bridge"]:
|
||||
import flash_attn.cute.interface
|
||||
for package in [
|
||||
"torch",
|
||||
"transformer-engine",
|
||||
"flash-attn",
|
||||
"flash-attn-4",
|
||||
"nvidia-cutlass-dsl",
|
||||
"nvidia-cutlass-dsl-libs-base",
|
||||
"nvidia-cutlass-dsl-libs-cu13",
|
||||
"megatron-core",
|
||||
"megatron-bridge",
|
||||
]:
|
||||
try:
|
||||
print(package, metadata.version(package))
|
||||
except metadata.PackageNotFoundError:
|
||||
print(package, "MISSING")
|
||||
import cutlass
|
||||
print("cutlass import OK")
|
||||
print("flash_attn.cute.interface import OK")
|
||||
PY
|
||||
'
|
||||
|
||||
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DATA_ROOT="${DATA_ROOT:-/data/yi/laoyao-2b-pretraining}"
|
||||
CONFIRM_DELETE="${CONFIRM_DELETE:-0}"
|
||||
|
||||
required=(
|
||||
"${DATA_ROOT}/megatron/stage2_1_8192_glm52_zh10_v3_20260719/manifest.json"
|
||||
"${DATA_ROOT}/megatron/stage2_1_8192_glm52_zh10_v3_20260719/source_audit.json"
|
||||
"${DATA_ROOT}/megatron/stage2_2_8192_glm52_zh10_v3_20260719/manifest.json"
|
||||
"${DATA_ROOT}/megatron/stage2_2_8192_glm52_zh10_v3_20260719/source_audit.json"
|
||||
)
|
||||
for path in "${required[@]}"; do
|
||||
[[ -f "$path" ]] || { echo "REFUSE: missing replacement artifact $path" >&2; exit 1; }
|
||||
done
|
||||
|
||||
python3 - "${required[@]}" <<'PY'
|
||||
import json, sys
|
||||
for manifest_path, audit_path in zip(sys.argv[1::2], sys.argv[2::2]):
|
||||
manifest = json.load(open(manifest_path))
|
||||
audit = json.load(open(audit_path))
|
||||
tokens = int(manifest.get("total_tokens", 0))
|
||||
total = max(int(audit.get("tokens", 0)), 1)
|
||||
zh = int(audit.get("tokens_by_language", {}).get("zh", 0)) / total
|
||||
if tokens < 49_000_000_000 or audit.get("fatal_issues") or audit.get("quota_shortfalls"):
|
||||
raise SystemExit(f"REFUSE: replacement failed validation: {manifest_path}")
|
||||
if not 0.09 <= zh <= 0.11:
|
||||
raise SystemExit(f"REFUSE: invalid Chinese fraction {zh:.6f}: {audit_path}")
|
||||
PY
|
||||
|
||||
deprecated=(
|
||||
"${DATA_ROOT}/normalized/stage2_1_general10_code30_science30_qa30_50b_seeded_v2_20260718"
|
||||
"${DATA_ROOT}/normalized/stage2_2_general18_code2_science10_qa70_50b_seeded_v2_20260718"
|
||||
"${DATA_ROOT}/megatron/stage2_1_8192_glm52_50b_v1_20260718"
|
||||
"${DATA_ROOT}/normalized/stage2_1_all_sources_smoke_20260718"
|
||||
"${DATA_ROOT}/normalized/stage2_1_seeded_split_smoke_20260718"
|
||||
"${DATA_ROOT}/normalized/stage2_2_seeded_split_smoke_20260718"
|
||||
"${DATA_ROOT}/normalized/stage2_qa_glm_smoke_100k_20260717"
|
||||
"${DATA_ROOT}/smoke/stage2_1_megatron_8192_20260718"
|
||||
"${DATA_ROOT}/smoke/stage2_multiproc_20260718"
|
||||
)
|
||||
|
||||
printf 'Validated replacements. Deprecated paths:\n'
|
||||
du -sh "${deprecated[@]}" 2>/dev/null || true
|
||||
if [[ "$CONFIRM_DELETE" != "1" ]]; then
|
||||
echo "Dry run only. Set CONFIRM_DELETE=1 to remove these paths."
|
||||
exit 0
|
||||
fi
|
||||
rm -rf -- "${deprecated[@]}"
|
||||
echo "Deprecated Stage 2 data removed."
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CONTAINER_NAME="${1:-${CONTAINER_NAME:-laoyao-stage2-1-plainqa-cpt}}"
|
||||
CHECKPOINT_DIR="${CHECKPOINT_DIR:-}"
|
||||
GRACEFUL_SIGNAL="${GRACEFUL_SIGNAL:-INT}"
|
||||
EXPECTED_WORKERS="${EXPECTED_WORKERS:-8}"
|
||||
WAIT_SECONDS="${WAIT_SECONDS:-900}"
|
||||
POLL_SECONDS="${POLL_SECONDS:-5}"
|
||||
|
||||
case "$GRACEFUL_SIGNAL" in
|
||||
INT|SIGINT) GRACEFUL_SIGNAL=INT ;;
|
||||
TERM|SIGTERM) GRACEFUL_SIGNAL=TERM ;;
|
||||
*)
|
||||
echo "ERROR: GRACEFUL_SIGNAL must be INT or TERM, got: $GRACEFUL_SIGNAL" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null || true)" != "true" ]]; then
|
||||
echo "ERROR: container is not running: $CONTAINER_NAME" >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
container_top="$(docker top "$CONTAINER_NAME" -eo pid,ppid,args)"
|
||||
torchrun_pid="$(
|
||||
awk '/[/]usr[/]local[/]bin[/]torchrun|torchrun --nproc_per_node/ {print $1; exit}' <<<"$container_top"
|
||||
)"
|
||||
if [[ -z "$torchrun_pid" ]]; then
|
||||
echo "ERROR: torchrun process not found in container: $CONTAINER_NAME" >&2
|
||||
exit 4
|
||||
fi
|
||||
|
||||
mapfile -t worker_pids < <(
|
||||
awk -v parent="$torchrun_pid" \
|
||||
'$2 == parent && /laoyao_2b_moe_pretrain[.]py/ {print $1}' \
|
||||
<<<"$container_top"
|
||||
)
|
||||
if [[ "${#worker_pids[@]}" -ne "$EXPECTED_WORKERS" ]]; then
|
||||
echo "ERROR: expected $EXPECTED_WORKERS direct torchrun workers, found ${#worker_pids[@]}" >&2
|
||||
printf 'candidate process tree:\n%s\n' "$container_top" >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
tracker="${CHECKPOINT_DIR:+${CHECKPOINT_DIR}/latest_checkpointed_iteration.txt}"
|
||||
before_checkpoint="unknown"
|
||||
if [[ -n "$tracker" && -f "$tracker" ]]; then
|
||||
before_checkpoint="$(tr -d '[:space:]' < "$tracker")"
|
||||
fi
|
||||
|
||||
echo "container=$CONTAINER_NAME"
|
||||
echo "torchrun_pid=$torchrun_pid"
|
||||
echo "worker_pids=${worker_pids[*]}"
|
||||
echo "signal=SIG${GRACEFUL_SIGNAL}"
|
||||
echo "checkpoint_before=$before_checkpoint"
|
||||
echo "Sending the signal to rank workers only; torchrun PID 1 remains alive while checkpointing."
|
||||
kill "-${GRACEFUL_SIGNAL}" "${worker_pids[@]}"
|
||||
|
||||
deadline=$((SECONDS + WAIT_SECONDS))
|
||||
while [[ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null || true)" == "true" ]]; do
|
||||
if (( SECONDS >= deadline )); then
|
||||
echo "ERROR: graceful shutdown did not finish within ${WAIT_SECONDS}s." >&2
|
||||
echo "The script will not force-kill the container while a checkpoint may be in progress." >&2
|
||||
exit 6
|
||||
fi
|
||||
|
||||
current_checkpoint="$before_checkpoint"
|
||||
if [[ -n "$tracker" && -f "$tracker" ]]; then
|
||||
current_checkpoint="$(tr -d '[:space:]' < "$tracker")"
|
||||
fi
|
||||
echo "waiting: elapsed=${SECONDS}s checkpoint=${current_checkpoint}"
|
||||
sleep "$POLL_SECONDS"
|
||||
done
|
||||
|
||||
after_checkpoint="unknown"
|
||||
if [[ -n "$tracker" && -f "$tracker" ]]; then
|
||||
after_checkpoint="$(tr -d '[:space:]' < "$tracker")"
|
||||
fi
|
||||
|
||||
echo "container_stopped=true"
|
||||
echo "checkpoint_after=$after_checkpoint"
|
||||
if [[ -n "$tracker" && "$after_checkpoint" == "$before_checkpoint" ]]; then
|
||||
echo "ERROR: container exited without advancing the checkpoint tracker." >&2
|
||||
exit 7
|
||||
fi
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
STAGE="${1:-all}"
|
||||
case "$STAGE" in
|
||||
1|2|all|download|build-1|build-2|tokenize-1|tokenize-2) ;;
|
||||
*) echo "usage: $0 {1|2|all|download|build-1|build-2|tokenize-1|tokenize-2}" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
DATA_ROOT="${DATA_ROOT:-/data/yi/laoyao-2b-pretraining}"
|
||||
RAW_ROOT="${RAW_ROOT:-${DATA_ROOT}/raw/stage2_curriculum_v1}"
|
||||
TOKENIZER_MODEL="${TOKENIZER_MODEL:-${REPO_ROOT}/tokenizer/glm5.2}"
|
||||
DATA_IMAGE="${DATA_IMAGE:-laoyao/stage2-data:20260717}"
|
||||
MEGATRON_IMAGE="${MEGATRON_IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
CATALOG="${CATALOG:-${REPO_ROOT}/dataset/pretrain/configs/stage2_source_catalog_20260717.json}"
|
||||
HASH_DB="${HASH_DB:-${DATA_ROOT}/no_replay/stage1_2_text_hashes.sqlite3}"
|
||||
PARALLEL_FILES="${PARALLEL_FILES:-32}"
|
||||
TOKENIZER_THREADS_PER_FILE="${TOKENIZER_THREADS_PER_FILE:-8}"
|
||||
MEGATRON_WORKERS_PER_FILE="${MEGATRON_WORKERS_PER_FILE:-4}"
|
||||
AUDIT_WORKERS="${AUDIT_WORKERS:-32}"
|
||||
DOWNLOAD_WORKERS="${DOWNLOAD_WORKERS:-8}"
|
||||
DOWNLOAD_ALL="${DOWNLOAD_ALL:-0}"
|
||||
OVERWRITE_NORMALIZED="${OVERWRITE_NORMALIZED:-0}"
|
||||
OVERWRITE_MEGATRON="${OVERWRITE_MEGATRON:-0}"
|
||||
SKIP_DOWNLOAD="${SKIP_DOWNLOAD:-1}"
|
||||
SKIP_RAW_AUDIT="${SKIP_RAW_AUDIT:-1}"
|
||||
|
||||
HF_TOKEN="${HF_TOKEN:-}"
|
||||
MODELSCOPE_TOKEN="${MODELSCOPE_TOKEN:-}"
|
||||
if [[ "$SKIP_DOWNLOAD" != "1" ]]; then
|
||||
: "${HF_TOKEN:?HF_TOKEN is required}"
|
||||
: "${MODELSCOPE_TOKEN:?MODELSCOPE_TOKEN is required}"
|
||||
fi
|
||||
|
||||
mkdir -p "${DATA_ROOT}/logs" "$RAW_ROOT"
|
||||
|
||||
download_sources() {
|
||||
local source_args=()
|
||||
if [[ "$DOWNLOAD_ALL" != "1" ]]; then
|
||||
source_args=(
|
||||
--source general_chinese_cci3_hq
|
||||
--source general_chinese_skypile
|
||||
--source qa_chinese_openbmb_l3
|
||||
)
|
||||
fi
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-e HF_TOKEN="$HF_TOKEN" -e MODELSCOPE_TOKEN="$MODELSCOPE_TOKEN" \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/download_stage2_curriculum_sources.py \
|
||||
--catalog "$CATALOG" \
|
||||
--output-root "$RAW_ROOT" \
|
||||
--workers "$DOWNLOAD_WORKERS" \
|
||||
"${source_args[@]}"
|
||||
}
|
||||
|
||||
audit_raw_sources() {
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/audit_stage2_raw_sources.py \
|
||||
--catalog "$CATALOG" \
|
||||
--raw-root "$RAW_ROOT" \
|
||||
--rows-per-source 10000 \
|
||||
--output "${DATA_ROOT}/reports/stage2_raw_source_audit_v3_20260719.json" \
|
||||
--strict
|
||||
}
|
||||
|
||||
stage_recipe() {
|
||||
if [[ "$1" == "1" ]]; then
|
||||
echo "${REPO_ROOT}/dataset/pretrain/configs/stage2_1_general10_zh10_code30_science30_qa30_50b_plainqa_cpt_v4_20260722.json"
|
||||
else
|
||||
echo "${REPO_ROOT}/dataset/pretrain/configs/stage2_2_general18_zh10_code2_science10_qa70_50b_plainqa_cpt_v4_20260722.json"
|
||||
fi
|
||||
}
|
||||
|
||||
normalized_dir() {
|
||||
echo "${DATA_ROOT}/normalized/stage2_${1}_zh10_50b_plainqa_cpt_v4_20260722"
|
||||
}
|
||||
|
||||
megatron_dir() {
|
||||
echo "${DATA_ROOT}/megatron/stage2_${1}_8192_glm52_plainqa_cpt_v4_20260722"
|
||||
}
|
||||
|
||||
build_stage() {
|
||||
local stage="$1" recipe normalized audit overwrite=()
|
||||
recipe="$(stage_recipe "$stage")"
|
||||
normalized="$(normalized_dir "$stage")"
|
||||
audit="${normalized}/audit.json"
|
||||
[[ "$OVERWRITE_NORMALIZED" == "1" ]] && overwrite=(--overwrite)
|
||||
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/build_stage2_curriculum_dataset.py \
|
||||
--recipe "$recipe" \
|
||||
--catalog "$CATALOG" \
|
||||
--raw-root "$RAW_ROOT" \
|
||||
--output-dir "$normalized" \
|
||||
--tokenizer "$TOKENIZER_MODEL" \
|
||||
--exclude-hash-db "$HASH_DB" \
|
||||
--exclude-hash-mode memory \
|
||||
--parallel-files "$PARALLEL_FILES" \
|
||||
--tokenizer-threads-per-file "$TOKENIZER_THREADS_PER_FILE" \
|
||||
--tokenizer-batch-size 1024 \
|
||||
--output-shard-rows 100000 \
|
||||
"${overwrite[@]}"
|
||||
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/audit_stage2_normalized.py \
|
||||
--input-dir "$normalized" \
|
||||
--build-report "${normalized}/report.json" \
|
||||
--recipe "$recipe" \
|
||||
--allow-quota-shortfall science_nemotron_scientific_code \
|
||||
--workers "$AUDIT_WORKERS" \
|
||||
--output "$audit" \
|
||||
--strict
|
||||
}
|
||||
|
||||
tokenize_stage() {
|
||||
local stage="$1" normalized output manifest overwrite=()
|
||||
normalized="$(normalized_dir "$stage")"
|
||||
output="$(megatron_dir "$stage")"
|
||||
manifest="${output}/manifest.json"
|
||||
[[ -f "${normalized}/audit.json" ]] || { echo "missing audit: ${normalized}/audit.json" >&2; exit 1; }
|
||||
[[ "$OVERWRITE_MEGATRON" == "1" ]] && overwrite=(--overwrite)
|
||||
mkdir -p "$output"
|
||||
|
||||
docker run --rm --ipc=host --network=host \
|
||||
--ulimit memlock=-1 --ulimit stack=67108864 \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$MEGATRON_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/convert_pretrain_parquet_to_megatron.py \
|
||||
--input "${normalized}/*.parquet" \
|
||||
--output-dir "$output" \
|
||||
--manifest "$manifest" \
|
||||
--megatron-dir /opt/Megatron-Bridge/3rdparty/Megatron-LM \
|
||||
--tokenizer-type HuggingFaceTokenizer \
|
||||
--tokenizer-model "$TOKENIZER_MODEL" \
|
||||
--text-key text \
|
||||
--output-prefix-prefix "stage2_${stage}_8192_glm52_plainqa_cpt_v4" \
|
||||
--parallel-files "$PARALLEL_FILES" \
|
||||
--workers-per-file "$MEGATRON_WORKERS_PER_FILE" \
|
||||
--batch-size 8192 \
|
||||
--chunksize 128 \
|
||||
--max-seq-len 8192 \
|
||||
"${overwrite[@]}"
|
||||
|
||||
cp "${normalized}/audit.json" "${output}/source_audit.json"
|
||||
cp "${normalized}/report.json" "${output}/source_build_report.json"
|
||||
python3 - "$manifest" "${output}/source_audit.json" <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
|
||||
manifest = json.load(open(sys.argv[1]))
|
||||
audit = json.load(open(sys.argv[2]))
|
||||
prefixes = manifest.get("ok_prefixes") or []
|
||||
bin_files = [Path(f"{prefix}.bin") for prefix in prefixes]
|
||||
idx_files = [Path(f"{prefix}.idx") for prefix in prefixes]
|
||||
missing = [str(path) for path in (*bin_files, *idx_files) if not path.is_file()]
|
||||
if missing:
|
||||
raise SystemExit(f"missing {len(missing)} indexed-dataset files; first={missing[0]}")
|
||||
bin_bytes = sum(path.stat().st_size for path in bin_files)
|
||||
if bin_bytes % 4:
|
||||
raise SystemExit(f"GLM-5.2 uint32 token binaries have a non-divisible byte count: {bin_bytes}")
|
||||
tokens = bin_bytes // 4
|
||||
reported_tokens = int(manifest.get("total_tokens", 0))
|
||||
zh = int(audit.get("tokens_by_language", {}).get("zh", 0)) / max(int(audit.get("tokens", 0)), 1)
|
||||
if tokens < 49_000_000_000:
|
||||
raise SystemExit(f"tokenized dataset is incomplete: {tokens}")
|
||||
if audit.get("fatal_issues") or audit.get("quota_shortfalls"):
|
||||
raise SystemExit("normalized audit did not pass")
|
||||
if not 0.09 <= zh <= 0.11:
|
||||
raise SystemExit(f"Chinese token fraction is invalid: {zh:.6f}")
|
||||
print(
|
||||
f"STAGE2_READY tokens={tokens} manifest_reported_tokens={reported_tokens} "
|
||||
f"prefixes={len(prefixes)} zh_fraction={zh:.6f}"
|
||||
)
|
||||
PY
|
||||
}
|
||||
|
||||
if [[ "$STAGE" == "tokenize-1" ]]; then
|
||||
tokenize_stage 1
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$STAGE" == "tokenize-2" ]]; then
|
||||
tokenize_stage 2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$SKIP_DOWNLOAD" != "1" ]]; then
|
||||
download_sources
|
||||
fi
|
||||
if [[ "$SKIP_RAW_AUDIT" != "1" ]]; then
|
||||
audit_raw_sources
|
||||
fi
|
||||
[[ "$STAGE" == "download" ]] && exit 0
|
||||
|
||||
if [[ "$STAGE" == "build-1" ]]; then
|
||||
build_stage 1
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$STAGE" == "build-2" ]]; then
|
||||
build_stage 2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$STAGE" == "1" || "$STAGE" == "all" ]]; then
|
||||
build_stage 1
|
||||
tokenize_stage 1
|
||||
fi
|
||||
if [[ "$STAGE" == "2" || "$STAGE" == "all" ]]; then
|
||||
build_stage 2
|
||||
tokenize_stage 2
|
||||
fi
|
||||
Executable
+203
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
STAGE="${1:-all}"
|
||||
case "$STAGE" in
|
||||
1|2|all|download|tokenize-1|tokenize-2) ;;
|
||||
*) echo "usage: $0 {1|2|all|download|tokenize-1|tokenize-2}" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
DATA_ROOT="${DATA_ROOT:-/data/yi/laoyao-2b-pretraining}"
|
||||
RAW_ROOT="${RAW_ROOT:-${DATA_ROOT}/raw/stage2_curriculum_v1}"
|
||||
TOKENIZER_MODEL="${TOKENIZER_MODEL:-${REPO_ROOT}/tokenizer/glm5.2}"
|
||||
DATA_IMAGE="${DATA_IMAGE:-laoyao/stage2-data:20260717}"
|
||||
MEGATRON_IMAGE="${MEGATRON_IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
CATALOG="${CATALOG:-${REPO_ROOT}/dataset/pretrain/configs/stage2_source_catalog_20260717.json}"
|
||||
HASH_DB="${HASH_DB:-${DATA_ROOT}/no_replay/stage1_2_text_hashes.sqlite3}"
|
||||
PARALLEL_FILES="${PARALLEL_FILES:-32}"
|
||||
TOKENIZER_THREADS_PER_FILE="${TOKENIZER_THREADS_PER_FILE:-8}"
|
||||
MEGATRON_WORKERS_PER_FILE="${MEGATRON_WORKERS_PER_FILE:-4}"
|
||||
AUDIT_WORKERS="${AUDIT_WORKERS:-32}"
|
||||
DOWNLOAD_WORKERS="${DOWNLOAD_WORKERS:-8}"
|
||||
DOWNLOAD_ALL="${DOWNLOAD_ALL:-0}"
|
||||
OVERWRITE_NORMALIZED="${OVERWRITE_NORMALIZED:-0}"
|
||||
OVERWRITE_MEGATRON="${OVERWRITE_MEGATRON:-0}"
|
||||
|
||||
HF_TOKEN="${HF_TOKEN:-}"
|
||||
MODELSCOPE_TOKEN="${MODELSCOPE_TOKEN:-}"
|
||||
if [[ "$STAGE" != tokenize-* ]]; then
|
||||
: "${HF_TOKEN:?HF_TOKEN is required}"
|
||||
: "${MODELSCOPE_TOKEN:?MODELSCOPE_TOKEN is required}"
|
||||
fi
|
||||
|
||||
mkdir -p "${DATA_ROOT}/logs" "$RAW_ROOT"
|
||||
|
||||
download_sources() {
|
||||
local source_args=()
|
||||
if [[ "$DOWNLOAD_ALL" != "1" ]]; then
|
||||
source_args=(
|
||||
--source general_chinese_cci3_hq
|
||||
--source general_chinese_skypile
|
||||
--source qa_chinese_openbmb_l3
|
||||
)
|
||||
fi
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-e HF_TOKEN="$HF_TOKEN" -e MODELSCOPE_TOKEN="$MODELSCOPE_TOKEN" \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/download_stage2_curriculum_sources.py \
|
||||
--catalog "$CATALOG" \
|
||||
--output-root "$RAW_ROOT" \
|
||||
--workers "$DOWNLOAD_WORKERS" \
|
||||
"${source_args[@]}"
|
||||
}
|
||||
|
||||
audit_raw_sources() {
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/audit_stage2_raw_sources.py \
|
||||
--catalog "$CATALOG" \
|
||||
--raw-root "$RAW_ROOT" \
|
||||
--rows-per-source 10000 \
|
||||
--output "${DATA_ROOT}/reports/stage2_raw_source_audit_v3_20260719.json" \
|
||||
--strict
|
||||
}
|
||||
|
||||
stage_recipe() {
|
||||
if [[ "$1" == "1" ]]; then
|
||||
echo "${REPO_ROOT}/dataset/pretrain/configs/stage2_1_general10_zh10_code30_science30_qa30_50b_v3_20260719.json"
|
||||
else
|
||||
echo "${REPO_ROOT}/dataset/pretrain/configs/stage2_2_general18_zh10_code2_science10_qa70_50b_v3_20260719.json"
|
||||
fi
|
||||
}
|
||||
|
||||
normalized_dir() {
|
||||
echo "${DATA_ROOT}/normalized/stage2_${1}_zh10_50b_v3_20260719"
|
||||
}
|
||||
|
||||
megatron_dir() {
|
||||
echo "${DATA_ROOT}/megatron/stage2_${1}_8192_glm52_zh10_v3_20260719"
|
||||
}
|
||||
|
||||
build_stage() {
|
||||
local stage="$1" recipe normalized audit overwrite=()
|
||||
recipe="$(stage_recipe "$stage")"
|
||||
normalized="$(normalized_dir "$stage")"
|
||||
audit="${normalized}/audit.json"
|
||||
[[ "$OVERWRITE_NORMALIZED" == "1" ]] && overwrite=(--overwrite)
|
||||
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/build_stage2_curriculum_dataset.py \
|
||||
--recipe "$recipe" \
|
||||
--catalog "$CATALOG" \
|
||||
--raw-root "$RAW_ROOT" \
|
||||
--output-dir "$normalized" \
|
||||
--tokenizer "$TOKENIZER_MODEL" \
|
||||
--exclude-hash-db "$HASH_DB" \
|
||||
--exclude-hash-mode memory \
|
||||
--parallel-files "$PARALLEL_FILES" \
|
||||
--tokenizer-threads-per-file "$TOKENIZER_THREADS_PER_FILE" \
|
||||
--tokenizer-batch-size 1024 \
|
||||
--output-shard-rows 100000 \
|
||||
"${overwrite[@]}"
|
||||
|
||||
docker run --rm --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$DATA_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/audit_stage2_normalized.py \
|
||||
--input-dir "$normalized" \
|
||||
--build-report "${normalized}/report.json" \
|
||||
--recipe "$recipe" \
|
||||
--allow-quota-shortfall science_nemotron_scientific_code \
|
||||
--workers "$AUDIT_WORKERS" \
|
||||
--output "$audit" \
|
||||
--strict
|
||||
}
|
||||
|
||||
tokenize_stage() {
|
||||
local stage="$1" normalized output manifest overwrite=()
|
||||
normalized="$(normalized_dir "$stage")"
|
||||
output="$(megatron_dir "$stage")"
|
||||
manifest="${output}/manifest.json"
|
||||
[[ -f "${normalized}/audit.json" ]] || { echo "missing audit: ${normalized}/audit.json" >&2; exit 1; }
|
||||
[[ "$OVERWRITE_MEGATRON" == "1" ]] && overwrite=(--overwrite)
|
||||
mkdir -p "$output"
|
||||
|
||||
docker run --rm --ipc=host --network=host \
|
||||
--ulimit memlock=-1 --ulimit stack=67108864 \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$MEGATRON_IMAGE" \
|
||||
python3 dataset/pretrain/scripts/convert_pretrain_parquet_to_megatron.py \
|
||||
--input "${normalized}/*.parquet" \
|
||||
--output-dir "$output" \
|
||||
--manifest "$manifest" \
|
||||
--megatron-dir /opt/Megatron-Bridge/3rdparty/Megatron-LM \
|
||||
--tokenizer-type HuggingFaceTokenizer \
|
||||
--tokenizer-model "$TOKENIZER_MODEL" \
|
||||
--text-key text \
|
||||
--output-prefix-prefix "stage2_${stage}_8192_glm52_zh10_v3" \
|
||||
--parallel-files "$PARALLEL_FILES" \
|
||||
--workers-per-file "$MEGATRON_WORKERS_PER_FILE" \
|
||||
--batch-size 8192 \
|
||||
--chunksize 128 \
|
||||
--max-seq-len 8192 \
|
||||
"${overwrite[@]}"
|
||||
|
||||
cp "${normalized}/audit.json" "${output}/source_audit.json"
|
||||
cp "${normalized}/report.json" "${output}/source_build_report.json"
|
||||
python3 - "$manifest" "${output}/source_audit.json" <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
|
||||
manifest = json.load(open(sys.argv[1]))
|
||||
audit = json.load(open(sys.argv[2]))
|
||||
prefixes = manifest.get("ok_prefixes") or []
|
||||
bin_files = [Path(f"{prefix}.bin") for prefix in prefixes]
|
||||
idx_files = [Path(f"{prefix}.idx") for prefix in prefixes]
|
||||
missing = [str(path) for path in (*bin_files, *idx_files) if not path.is_file()]
|
||||
if missing:
|
||||
raise SystemExit(f"missing {len(missing)} indexed-dataset files; first={missing[0]}")
|
||||
bin_bytes = sum(path.stat().st_size for path in bin_files)
|
||||
if bin_bytes % 4:
|
||||
raise SystemExit(f"GLM-5.2 uint32 token binaries have a non-divisible byte count: {bin_bytes}")
|
||||
tokens = bin_bytes // 4
|
||||
reported_tokens = int(manifest.get("total_tokens", 0))
|
||||
zh = int(audit.get("tokens_by_language", {}).get("zh", 0)) / max(int(audit.get("tokens", 0)), 1)
|
||||
if tokens < 49_000_000_000:
|
||||
raise SystemExit(f"tokenized dataset is incomplete: {tokens}")
|
||||
if audit.get("fatal_issues") or audit.get("quota_shortfalls"):
|
||||
raise SystemExit("normalized audit did not pass")
|
||||
if not 0.09 <= zh <= 0.11:
|
||||
raise SystemExit(f"Chinese token fraction is invalid: {zh:.6f}")
|
||||
print(
|
||||
f"STAGE2_READY tokens={tokens} manifest_reported_tokens={reported_tokens} "
|
||||
f"prefixes={len(prefixes)} zh_fraction={zh:.6f}"
|
||||
)
|
||||
PY
|
||||
}
|
||||
|
||||
if [[ "$STAGE" == "tokenize-1" ]]; then
|
||||
tokenize_stage 1
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$STAGE" == "tokenize-2" ]]; then
|
||||
tokenize_stage 2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
download_sources
|
||||
audit_raw_sources
|
||||
[[ "$STAGE" == "download" ]] && exit 0
|
||||
|
||||
if [[ "$STAGE" == "1" || "$STAGE" == "all" ]]; then
|
||||
build_stage 1
|
||||
tokenize_stage 1
|
||||
fi
|
||||
if [[ "$STAGE" == "2" || "$STAGE" == "all" ]]; then
|
||||
build_stage 2
|
||||
tokenize_stage 2
|
||||
fi
|
||||
@@ -77,6 +77,7 @@ nohup docker run --rm --name "${CONTAINER_NAME}" \
|
||||
--network=host \
|
||||
--ulimit memlock=-1 \
|
||||
--ulimit stack=67108864 \
|
||||
--ulimit nofile=1048576:1048576 \
|
||||
-e CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
|
||||
-v "${HOST_WORKSPACE}:${CONTAINER_WORKSPACE}" \
|
||||
-w "${REPO_ROOT}" \
|
||||
|
||||
Executable
+156
@@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
IMAGE="${IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
STAGE2_1_RUN="${STAGE2_1_RUN:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/stage2_1_8192_8gpu_dp8_mbs14_lr5e5_eval5k_full_recompute_zh10_v3_from_stage1_2_iter281245}"
|
||||
STAGE2_1_CKPT_ROOT="${STAGE2_1_CKPT_ROOT:-${STAGE2_1_RUN}/checkpoints}"
|
||||
EXPECTED_FINAL_ITER="${EXPECTED_FINAL_ITER:-54343}"
|
||||
MODEL_LABEL="stage2_1_iter_$(printf '%07d' "$EXPECTED_FINAL_ITER")"
|
||||
RESULT_ROOT="${RESULT_ROOT:-/data/yi/laoyao-2b-pretraining/evaluation/${MODEL_LABEL}}"
|
||||
HF_EXPORT="${RESULT_ROOT}/hf_export"
|
||||
EVAL_DIR="${RESULT_ROOT}/heldout_2p8k"
|
||||
CASE_JSON="${RESULT_ROOT}/case_study_temperature0.json"
|
||||
CASE_TEXT="${RESULT_ROOT}/case_study_temperature0.txt"
|
||||
REPORT="${RESULT_ROOT}/${MODEL_LABEL}_final_evaluation.md"
|
||||
GATE_JSON="${RESULT_ROOT}/quality_gate.json"
|
||||
STATUS_FILE="${RESULT_ROOT}/pipeline.status"
|
||||
STAGE2_2_DATA="${STAGE2_2_DATA:-/data/yi/laoyao-2b-pretraining/megatron/stage2_2_8192_glm52_zh10_v3_20260719}"
|
||||
STAGE2_2_RUN_NAME="${STAGE2_2_RUN_NAME:-stage2_2_8192_8gpu_dp8_mbs14_lr5e5_eval5k_full_recompute_zh10_v3_from_stage2_1_iter54343}"
|
||||
|
||||
mkdir -p "$RESULT_ROOT" "$EVAL_DIR/logs"
|
||||
exec > >(tee -a "${RESULT_ROOT}/pipeline.log") 2>&1
|
||||
|
||||
status() {
|
||||
printf '%s %s\n' "$(date -Is)" "$*" | tee "$STATUS_FILE"
|
||||
}
|
||||
|
||||
gpu_process_count() {
|
||||
nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null | sed '/^[[:space:]]*$/d' | wc -l
|
||||
}
|
||||
|
||||
wait_for_free_gpus() {
|
||||
while [[ "$(gpu_process_count)" -ne 0 ]]; do
|
||||
status "WAITING_FOR_FREE_GPUS count=$(gpu_process_count)"
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
status "WAITING_FOR_STAGE2_1"
|
||||
while docker ps --filter name=laoyao-stage2-1-pretrain -q | grep -q .; do
|
||||
tracker="$(cat "${STAGE2_1_CKPT_ROOT}/latest_checkpointed_iteration.txt" 2>/dev/null || echo 0)"
|
||||
status "WAITING_FOR_STAGE2_1 tracker=${tracker}"
|
||||
sleep 60
|
||||
done
|
||||
|
||||
final_iter="$(cat "${STAGE2_1_CKPT_ROOT}/latest_checkpointed_iteration.txt" 2>/dev/null || echo 0)"
|
||||
if [[ "$final_iter" != "$EXPECTED_FINAL_ITER" ]]; then
|
||||
status "BLOCKED_STAGE2_1_NOT_COMPLETE tracker=${final_iter} expected=${EXPECTED_FINAL_ITER}"
|
||||
exit 20
|
||||
fi
|
||||
FINAL_CKPT="${STAGE2_1_CKPT_ROOT}/iter_$(printf '%07d' "$EXPECTED_FINAL_ITER")"
|
||||
if [[ ! -f "${FINAL_CKPT}/.metadata" || "$(find "$FINAL_CKPT" -maxdepth 1 -name '*.distcp' | wc -l)" -ne 8 ]]; then
|
||||
status "BLOCKED_INCOMPLETE_FINAL_CHECKPOINT path=${FINAL_CKPT}"
|
||||
exit 21
|
||||
fi
|
||||
|
||||
if [[ -s "${HF_EXPORT}/model.safetensors" ]]; then
|
||||
status "REUSING_HF_EXPORT path=${HF_EXPORT}"
|
||||
else
|
||||
status "EXPORTING checkpoint=${FINAL_CKPT}"
|
||||
rm -rf "$HF_EXPORT"
|
||||
docker run --rm --name laoyao-stage2-1-final-export --ipc=host --network=host \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$IMAGE" \
|
||||
python3 tools/hf_laoyao_moe/convert_laoyao_dcp_to_hf.py \
|
||||
--checkpoint-dir "$FINAL_CKPT" \
|
||||
--tokenizer-dir tokenizer/glm5.2 \
|
||||
--output-dir "$HF_EXPORT"
|
||||
fi
|
||||
[[ -s "${HF_EXPORT}/model.safetensors" ]] || { status "BLOCKED_EXPORT_MISSING_WEIGHTS"; exit 22; }
|
||||
|
||||
wait_for_free_gpus
|
||||
status "RUNNING_2800_EVAL_AND_CASE_STUDY"
|
||||
docker run --rm --name laoyao-stage2-1-final-eval --gpus all --ipc=host --network=host \
|
||||
-e HF_EXPORT="$HF_EXPORT" \
|
||||
-e EVAL_DIR="$EVAL_DIR" \
|
||||
-e MODEL_LABEL="$MODEL_LABEL" \
|
||||
-e CASE_JSON="$CASE_JSON" \
|
||||
-e CASE_TEXT="$CASE_TEXT" \
|
||||
-e RESULT_ROOT="$RESULT_ROOT" \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$IMAGE" \
|
||||
bash -lc '
|
||||
set -euo pipefail
|
||||
pids=()
|
||||
for shard in $(seq 0 7); do
|
||||
shard_label=$(printf "%s.shard%02dof08" "$MODEL_LABEL" "$shard")
|
||||
if [[ -s "$EVAL_DIR/${shard_label}.summary.json" && -s "$EVAL_DIR/${shard_label}.per_item.jsonl" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Transformers writes trust_remote_code modules into a shared cache.
|
||||
# Isolate it per worker to avoid concurrent partial module imports.
|
||||
HF_MODULES_CACHE="/tmp/hf_modules_shard_${shard}" \
|
||||
CUDA_VISIBLE_DEVICES="$shard" python3 tools/hf_laoyao_moe/eval_heldout_2p8k.py \
|
||||
--model-dir "$HF_EXPORT" \
|
||||
--data dataset/val/data/heldout_2p8k_sft_prompt_completion.jsonl \
|
||||
--out-dir "$EVAL_DIR" \
|
||||
--model-label "$MODEL_LABEL" \
|
||||
--max-length 2048 --num-shards 8 --shard-id "$shard" \
|
||||
--device cuda --dtype bfloat16 \
|
||||
>"$EVAL_DIR/logs/shard_${shard}.log" 2>&1 &
|
||||
pids+=("$!")
|
||||
done
|
||||
if [[ ! -s "$CASE_JSON" || ! -s "$CASE_TEXT" ]]; then
|
||||
HF_MODULES_CACHE=/tmp/hf_modules_case \
|
||||
CUDA_VISIBLE_DEVICES=0 python3 tools/hf_laoyao_moe/case_study_stage2.py \
|
||||
--model-dir "$HF_EXPORT" \
|
||||
--output-json "$CASE_JSON" \
|
||||
--output-text "$CASE_TEXT" \
|
||||
--device cuda --max-new-tokens 64 \
|
||||
>"$RESULT_ROOT/case_study.log" 2>&1 &
|
||||
pids+=("$!")
|
||||
fi
|
||||
failed=0
|
||||
for pid in "${pids[@]}"; do wait "$pid" || failed=1; done
|
||||
exit "$failed"
|
||||
'
|
||||
|
||||
status "MERGING_AND_GATING"
|
||||
set +e
|
||||
python3 "${REPO_ROOT}/tools/hf_laoyao_moe/merge_eval_and_gate.py" \
|
||||
--eval-dir "$EVAL_DIR" \
|
||||
--model-label "$MODEL_LABEL" \
|
||||
--case-json "$CASE_JSON" \
|
||||
--report "$REPORT" \
|
||||
--gate-json "$GATE_JSON"
|
||||
gate_rc=$?
|
||||
set -e
|
||||
if [[ "$gate_rc" -ne 0 ]]; then
|
||||
status "BLOCKED_QUALITY_GATE_FAILED report=${REPORT}"
|
||||
exit 30
|
||||
fi
|
||||
status "QUALITY_GATE_PASSED report=${REPORT}"
|
||||
|
||||
while [[ ! -f "${STAGE2_2_DATA}/manifest.json" || ! -f "${STAGE2_2_DATA}/source_audit.json" ]]; do
|
||||
status "WAITING_FOR_STAGE2_2_DATA"
|
||||
sleep 60
|
||||
done
|
||||
wait_for_free_gpus
|
||||
|
||||
status "STARTING_STAGE2_2"
|
||||
cd "$REPO_ROOT"
|
||||
STAGE2_1_LOAD_DIR="$STAGE2_1_CKPT_ROOT" \
|
||||
RUN_NAME="$STAGE2_2_RUN_NAME" \
|
||||
bash scripts/train_stage2_2_pretrain_8192_8gpu_mbs14.sh
|
||||
|
||||
for _ in $(seq 1 60); do
|
||||
if docker ps --filter name=laoyao-stage2-2-pretrain -q | grep -q .; then
|
||||
status "STAGE2_2_CONTAINER_RUNNING run=${STAGE2_2_RUN_NAME}"
|
||||
touch "${RESULT_ROOT}/stage2_2_started.ok"
|
||||
exit 0
|
||||
fi
|
||||
sleep 10
|
||||
done
|
||||
status "BLOCKED_STAGE2_2_DID_NOT_START"
|
||||
exit 40
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT=${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}
|
||||
DATA_ROOT=${DATA_ROOT:-/data/yi/laoyao-2b-pretraining}
|
||||
AUTOMATION_ROOT=${AUTOMATION_ROOT:-${DATA_ROOT}/automation/stage2_plainqa_cpt_v4_20260722}
|
||||
REBUILD_SCRIPT=${REPO_ROOT}/scripts/rebuild_stage2_curriculum_plainqa_cpt.sh
|
||||
TRAIN_SCRIPT=${REPO_ROOT}/scripts/train_stage2_1_plainqa_cpt_8192_8gpu_mbs14.sh
|
||||
|
||||
mkdir -p "$AUTOMATION_ROOT"
|
||||
STATUS_FILE=${AUTOMATION_ROOT}/status
|
||||
|
||||
status() {
|
||||
printf '%s %s\n' "$(date -Is)" "$*" | tee "$STATUS_FILE"
|
||||
}
|
||||
|
||||
run_pair() {
|
||||
local phase=$1 stage1_arg=$2 stage2_arg=$3
|
||||
status "${phase}_STARTING"
|
||||
(
|
||||
PARALLEL_FILES=16 TOKENIZER_THREADS_PER_FILE=8 MEGATRON_WORKERS_PER_FILE=4 \
|
||||
bash "$REBUILD_SCRIPT" "$stage1_arg"
|
||||
) >"${AUTOMATION_ROOT}/${phase}_stage2_1.log" 2>&1 &
|
||||
local pid1=$!
|
||||
echo "$pid1" >"${AUTOMATION_ROOT}/${phase}_stage2_1.pid"
|
||||
(
|
||||
PARALLEL_FILES=16 TOKENIZER_THREADS_PER_FILE=8 MEGATRON_WORKERS_PER_FILE=4 \
|
||||
bash "$REBUILD_SCRIPT" "$stage2_arg"
|
||||
) >"${AUTOMATION_ROOT}/${phase}_stage2_2.log" 2>&1 &
|
||||
local pid2=$!
|
||||
echo "$pid2" >"${AUTOMATION_ROOT}/${phase}_stage2_2.pid"
|
||||
|
||||
local failed=0
|
||||
wait "$pid1" || failed=1
|
||||
wait "$pid2" || failed=1
|
||||
if [[ "$failed" -ne 0 ]]; then
|
||||
status "${phase}_FAILED"
|
||||
return 1
|
||||
fi
|
||||
status "${phase}_COMPLETE"
|
||||
}
|
||||
|
||||
run_pair NORMALIZE build-1 build-2
|
||||
run_pair TOKENIZE tokenize-1 tokenize-2
|
||||
|
||||
status "STAGE2_1_PREFLIGHT"
|
||||
PREFLIGHT_ONLY=1 bash "$TRAIN_SCRIPT" >"${AUTOMATION_ROOT}/stage2_1_preflight.log" 2>&1
|
||||
|
||||
while [[ "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null | sed '/^[[:space:]]*$/d' | wc -l)" -ne 0 ]]; do
|
||||
status "WAITING_FOR_FREE_GPUS"
|
||||
sleep 60
|
||||
done
|
||||
|
||||
status "STARTING_STAGE2_1_PLAINQA_CPT"
|
||||
bash "$TRAIN_SCRIPT" >"${AUTOMATION_ROOT}/stage2_1_launch.log" 2>&1
|
||||
for _ in $(seq 1 60); do
|
||||
if docker ps --filter name=laoyao-stage2-1-plainqa-cpt -q | grep -q .; then
|
||||
status "STAGE2_1_PLAINQA_CPT_RUNNING"
|
||||
exit 0
|
||||
fi
|
||||
sleep 10
|
||||
done
|
||||
status "STAGE2_1_PLAINQA_CPT_DID_NOT_START"
|
||||
exit 1
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
IMAGE="${IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
DATA_MANIFEST="${DATA_MANIFEST:-/data/yi/laoyao-2b-pretraining/megatron/stage2_1_8192_glm52_plainqa_cpt_v4_20260722/manifest.json}"
|
||||
DATA_AUDIT="${DATA_AUDIT:-$(dirname "$DATA_MANIFEST")/source_audit.json}"
|
||||
VALIDATION_PREFIX="${VALIDATION_PREFIX:-${REPO_ROOT}/dataset/val/megatron_8192_glm52/heldout_2p8k_text_document}"
|
||||
STAGE1_LOAD_DIR="${STAGE1_LOAD_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/stage1_2_8192_8gpu_dp8_mbs14_full_recompute_gc251_resume_222500_nohugepages/checkpoints}"
|
||||
EXPECTED_STAGE1_ITER="${EXPECTED_STAGE1_ITER:-281245}"
|
||||
RUN_NAME="${RUN_NAME:-stage2_1_plainqa_cpt_v4_8192_8gpu_dp8_mbs14_lr5e5_eval5k_from_stage1_2_iter281245}"
|
||||
RUN_DIR="${RUN_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/${RUN_NAME}}"
|
||||
CKPT_DIR="${CKPT_DIR:-${RUN_DIR}/checkpoints}"
|
||||
TENSORBOARD_DIR="${TENSORBOARD_DIR:-${RUN_DIR}/tensorboard}"
|
||||
LOG_FILE="${LOG_FILE:-${RUN_DIR}/train.log}"
|
||||
CONTAINER_NAME="${CONTAINER_NAME:-laoyao-stage2-1-plainqa-cpt}"
|
||||
|
||||
SEQ_LENGTH="${SEQ_LENGTH:-8192}"
|
||||
MICRO_BATCH_SIZE="${MICRO_BATCH_SIZE:-14}"
|
||||
GLOBAL_BATCH_SIZE="${GLOBAL_BATCH_SIZE:-112}"
|
||||
LR="${LR:-5.0e-5}"
|
||||
MIN_LR="${MIN_LR:-5.0e-6}"
|
||||
WARMUP_FRACTION="${WARMUP_FRACTION:-0.01}"
|
||||
SAVE_INTERVAL="${SAVE_INTERVAL:-2500}"
|
||||
EVAL_INTERVAL="${EVAL_INTERVAL:-5000}"
|
||||
EVAL_ITERS="${EVAL_ITERS:-10}"
|
||||
DATASET_WORKERS="${DATASET_WORKERS:-4}"
|
||||
PREFLIGHT_ONLY="${PREFLIGHT_ONLY:-0}"
|
||||
|
||||
if [[ ! -f "$DATA_MANIFEST" ]]; then
|
||||
echo "ERROR: missing Stage 2-1 Megatron manifest: $DATA_MANIFEST" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "$DATA_AUDIT" ]]; then
|
||||
echo "ERROR: missing Stage 2-1 source audit: $DATA_AUDIT" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "${VALIDATION_PREFIX}.idx" || ! -f "${VALIDATION_PREFIX}.bin" ]]; then
|
||||
echo "ERROR: missing held-out validation prefix: $VALIDATION_PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -r MANIFEST_TOKENS MANIFEST_REPORTED_TOKENS PREFIX_COUNT ZH_FRACTION <<<"$(python3 - "$DATA_MANIFEST" "$DATA_AUDIT" <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
|
||||
manifest = json.load(open(sys.argv[1]))
|
||||
audit = json.load(open(sys.argv[2]))
|
||||
if audit.get("fatal_issues") or audit.get("quota_shortfalls"):
|
||||
raise SystemExit(f"source audit failed: {sys.argv[2]}")
|
||||
prefixes = manifest.get("ok_prefixes") or []
|
||||
bin_files = [Path(f"{prefix}.bin") for prefix in prefixes]
|
||||
idx_files = [Path(f"{prefix}.idx") for prefix in prefixes]
|
||||
missing = [str(path) for path in (*bin_files, *idx_files) if not path.is_file()]
|
||||
if missing:
|
||||
raise SystemExit(f"missing {len(missing)} indexed-dataset files; first={missing[0]}")
|
||||
bin_bytes = sum(path.stat().st_size for path in bin_files)
|
||||
if bin_bytes % 4:
|
||||
raise SystemExit(f"GLM-5.2 uint32 binaries have invalid byte count: {bin_bytes}")
|
||||
actual_tokens = bin_bytes // 4
|
||||
by_language = audit.get("tokens_by_language", {})
|
||||
total = max(int(audit.get("tokens", 0)), 1)
|
||||
zh_fraction = int(by_language.get("zh", 0)) / total
|
||||
print(actual_tokens, int(manifest.get("total_tokens", 0)), len(prefixes), f"{zh_fraction:.6f}")
|
||||
PY
|
||||
)"
|
||||
if (( MANIFEST_TOKENS < 49000000000 || PREFIX_COUNT < 800 )); then
|
||||
echo "ERROR: incomplete Stage 2-1 manifest: tokens=$MANIFEST_TOKENS prefixes=$PREFIX_COUNT" >&2
|
||||
exit 1
|
||||
fi
|
||||
python3 - "$ZH_FRACTION" <<'PY'
|
||||
import sys
|
||||
value = float(sys.argv[1])
|
||||
if not 0.09 <= value <= 0.11:
|
||||
raise SystemExit(f"Chinese token fraction outside [0.09, 0.11]: {value:.6f}")
|
||||
PY
|
||||
|
||||
if [[ -z "${TRAIN_ITERS:-}" ]]; then
|
||||
TRAIN_ITERS="$(( (MANIFEST_TOKENS + SEQ_LENGTH * GLOBAL_BATCH_SIZE - 1) / (SEQ_LENGTH * GLOBAL_BATCH_SIZE) ))"
|
||||
fi
|
||||
|
||||
mkdir -p "$CKPT_DIR" "$TENSORBOARD_DIR" "$(dirname "$LOG_FILE")"
|
||||
|
||||
STAGE_TRANSITION_ARG=""
|
||||
if [[ -f "$CKPT_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
LOAD_DIR="$CKPT_DIR"
|
||||
LOAD_MODE="resume-stage2-1"
|
||||
else
|
||||
LOAD_DIR="$STAGE1_LOAD_DIR"
|
||||
LOAD_MODE="stage1-2-model-only"
|
||||
STAGE_TRANSITION_ARG="--finetune-from-checkpoint"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$LOAD_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
echo "ERROR: checkpoint tracker not found: $LOAD_DIR/latest_checkpointed_iteration.txt" >&2
|
||||
exit 1
|
||||
fi
|
||||
LOAD_ITER="$(tr -d '[:space:]' < "$LOAD_DIR/latest_checkpointed_iteration.txt")"
|
||||
if [[ "$LOAD_MODE" == "stage1-2-model-only" && "$LOAD_ITER" != "$EXPECTED_STAGE1_ITER" ]]; then
|
||||
echo "ERROR: expected Stage 1-2 iteration $EXPECTED_STAGE1_ITER, found $LOAD_ITER in $LOAD_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
if docker ps --format '{{.Names}}' | grep -Fxq "$CONTAINER_NAME"; then
|
||||
echo "ERROR: container already running: $CONTAINER_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Starting Stage 2-1 continued pretraining
|
||||
data_manifest=$DATA_MANIFEST
|
||||
manifest_tokens=$MANIFEST_TOKENS
|
||||
manifest_reported_tokens=$MANIFEST_REPORTED_TOKENS
|
||||
prefixes=$PREFIX_COUNT
|
||||
zh_fraction=$ZH_FRACTION
|
||||
train_iters=$TRAIN_ITERS
|
||||
load_mode=$LOAD_MODE
|
||||
load_dir=$LOAD_DIR
|
||||
load_iteration=$LOAD_ITER
|
||||
save_dir=$CKPT_DIR
|
||||
lr=$LR min_lr=$MIN_LR warmup_fraction=$WARMUP_FRACTION
|
||||
mbs=$MICRO_BATCH_SIZE gbs=$GLOBAL_BATCH_SIZE seq_length=$SEQ_LENGTH
|
||||
save_interval=$SAVE_INTERVAL eval_interval=$EVAL_INTERVAL eval_iters=$EVAL_ITERS
|
||||
validation_prefix=$VALIDATION_PREFIX
|
||||
EOF
|
||||
|
||||
if [[ "$PREFLIGHT_ONLY" == "1" ]]; then
|
||||
echo "Preflight passed; training was not launched."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
nohup docker run --rm --name "$CONTAINER_NAME" \
|
||||
--gpus all --ipc=host --network=host \
|
||||
--ulimit memlock=-1 --ulimit stack=67108864 --ulimit nofile=1048576:1048576 \
|
||||
-e CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$IMAGE" \
|
||||
bash -lc "torchrun --nproc_per_node=8 \
|
||||
training/megatron_bridge/laoyao_2b_moe_pretrain.py \
|
||||
--data-manifest '$DATA_MANIFEST' \
|
||||
--validation-prefix '$VALIDATION_PREFIX' \
|
||||
--seq-length '$SEQ_LENGTH' \
|
||||
--train-iters '$TRAIN_ITERS' \
|
||||
--micro-batch-size '$MICRO_BATCH_SIZE' \
|
||||
--global-batch-size '$GLOBAL_BATCH_SIZE' \
|
||||
--tensor-parallel 1 --pipeline-parallel 1 --expert-parallel 1 --context-parallel 1 \
|
||||
--split 999,1,0 --dataset-workers '$DATASET_WORKERS' \
|
||||
--lr '$LR' --min-lr '$MIN_LR' --warmup-fraction '$WARMUP_FRACTION' \
|
||||
--save-dir '$CKPT_DIR' --load-dir '$LOAD_DIR' \
|
||||
--tensorboard-dir '$TENSORBOARD_DIR' \
|
||||
--save-interval '$SAVE_INTERVAL' --keep-last-checkpoints 10 \
|
||||
--log-interval 10 --eval-interval '$EVAL_INTERVAL' --eval-iters '$EVAL_ITERS' \
|
||||
--use-distributed-optimizer --overlap-grad-reduce --overlap-param-gather \
|
||||
--recompute-granularity full --recompute-method uniform --recompute-num-layers 1 \
|
||||
$STAGE_TRANSITION_ARG" >"$LOG_FILE" 2>&1 &
|
||||
|
||||
echo "Launched container=$CONTAINER_NAME log=$LOG_FILE"
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
IMAGE="${IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
DATA_MANIFEST="${DATA_MANIFEST:-/data/yi/laoyao-2b-pretraining/megatron/stage2_1_8192_glm52_zh10_v3_20260719/manifest.json}"
|
||||
DATA_AUDIT="${DATA_AUDIT:-$(dirname "$DATA_MANIFEST")/source_audit.json}"
|
||||
VALIDATION_PREFIX="${VALIDATION_PREFIX:-${REPO_ROOT}/dataset/val/megatron_8192_glm52/heldout_2p8k_text_document}"
|
||||
STAGE1_LOAD_DIR="${STAGE1_LOAD_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/stage1_2_8192_8gpu_dp8_mbs14_full_recompute_gc251_resume_222500_nohugepages/checkpoints}"
|
||||
EXPECTED_STAGE1_ITER="${EXPECTED_STAGE1_ITER:-281245}"
|
||||
RUN_NAME="${RUN_NAME:-stage2_1_8192_8gpu_dp8_mbs14_lr5e5_eval5k_full_recompute_zh10_v3_from_stage1_2_iter281245}"
|
||||
RUN_DIR="${RUN_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/${RUN_NAME}}"
|
||||
CKPT_DIR="${CKPT_DIR:-${RUN_DIR}/checkpoints}"
|
||||
TENSORBOARD_DIR="${TENSORBOARD_DIR:-${RUN_DIR}/tensorboard}"
|
||||
LOG_FILE="${LOG_FILE:-${RUN_DIR}/train.log}"
|
||||
CONTAINER_NAME="${CONTAINER_NAME:-laoyao-stage2-1-pretrain}"
|
||||
|
||||
SEQ_LENGTH="${SEQ_LENGTH:-8192}"
|
||||
MICRO_BATCH_SIZE="${MICRO_BATCH_SIZE:-14}"
|
||||
GLOBAL_BATCH_SIZE="${GLOBAL_BATCH_SIZE:-112}"
|
||||
LR="${LR:-5.0e-5}"
|
||||
MIN_LR="${MIN_LR:-5.0e-6}"
|
||||
WARMUP_FRACTION="${WARMUP_FRACTION:-0.01}"
|
||||
SAVE_INTERVAL="${SAVE_INTERVAL:-2500}"
|
||||
EVAL_INTERVAL="${EVAL_INTERVAL:-5000}"
|
||||
EVAL_ITERS="${EVAL_ITERS:-10}"
|
||||
DATASET_WORKERS="${DATASET_WORKERS:-4}"
|
||||
PREFLIGHT_ONLY="${PREFLIGHT_ONLY:-0}"
|
||||
|
||||
if [[ ! -f "$DATA_MANIFEST" ]]; then
|
||||
echo "ERROR: missing Stage 2-1 Megatron manifest: $DATA_MANIFEST" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "$DATA_AUDIT" ]]; then
|
||||
echo "ERROR: missing Stage 2-1 source audit: $DATA_AUDIT" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "${VALIDATION_PREFIX}.idx" || ! -f "${VALIDATION_PREFIX}.bin" ]]; then
|
||||
echo "ERROR: missing held-out validation prefix: $VALIDATION_PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -r MANIFEST_TOKENS PREFIX_COUNT ZH_FRACTION <<<"$(python3 - "$DATA_MANIFEST" "$DATA_AUDIT" <<'PY'
|
||||
import json, sys
|
||||
x = json.load(open(sys.argv[1]))
|
||||
a = json.load(open(sys.argv[2]))
|
||||
if a.get("fatal_issues") or a.get("quota_shortfalls"):
|
||||
raise SystemExit(f"source audit failed: {sys.argv[2]}")
|
||||
by_language = a.get("tokens_by_language", {})
|
||||
total = max(int(a.get("tokens", 0)), 1)
|
||||
zh_fraction = int(by_language.get("zh", 0)) / total
|
||||
print(int(x.get("total_tokens", 0)), len(x.get("ok_prefixes") or []), f"{zh_fraction:.6f}")
|
||||
PY
|
||||
)"
|
||||
if (( MANIFEST_TOKENS < 49000000000 || PREFIX_COUNT < 800 )); then
|
||||
echo "ERROR: incomplete Stage 2-1 manifest: tokens=$MANIFEST_TOKENS prefixes=$PREFIX_COUNT" >&2
|
||||
exit 1
|
||||
fi
|
||||
python3 - "$ZH_FRACTION" <<'PY'
|
||||
import sys
|
||||
value = float(sys.argv[1])
|
||||
if not 0.09 <= value <= 0.11:
|
||||
raise SystemExit(f"Chinese token fraction outside [0.09, 0.11]: {value:.6f}")
|
||||
PY
|
||||
|
||||
if [[ -z "${TRAIN_ITERS:-}" ]]; then
|
||||
TRAIN_ITERS="$(( (MANIFEST_TOKENS + SEQ_LENGTH * GLOBAL_BATCH_SIZE - 1) / (SEQ_LENGTH * GLOBAL_BATCH_SIZE) ))"
|
||||
fi
|
||||
|
||||
mkdir -p "$CKPT_DIR" "$TENSORBOARD_DIR" "$(dirname "$LOG_FILE")"
|
||||
|
||||
STAGE_TRANSITION_ARG=""
|
||||
if [[ -f "$CKPT_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
LOAD_DIR="$CKPT_DIR"
|
||||
LOAD_MODE="resume-stage2-1"
|
||||
else
|
||||
LOAD_DIR="$STAGE1_LOAD_DIR"
|
||||
LOAD_MODE="stage1-2-model-only"
|
||||
STAGE_TRANSITION_ARG="--finetune-from-checkpoint"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$LOAD_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
echo "ERROR: checkpoint tracker not found: $LOAD_DIR/latest_checkpointed_iteration.txt" >&2
|
||||
exit 1
|
||||
fi
|
||||
LOAD_ITER="$(tr -d '[:space:]' < "$LOAD_DIR/latest_checkpointed_iteration.txt")"
|
||||
if [[ "$LOAD_MODE" == "stage1-2-model-only" && "$LOAD_ITER" != "$EXPECTED_STAGE1_ITER" ]]; then
|
||||
echo "ERROR: expected Stage 1-2 iteration $EXPECTED_STAGE1_ITER, found $LOAD_ITER in $LOAD_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
if docker ps --format '{{.Names}}' | grep -Fxq "$CONTAINER_NAME"; then
|
||||
echo "ERROR: container already running: $CONTAINER_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Starting Stage 2-1 continued pretraining
|
||||
data_manifest=$DATA_MANIFEST
|
||||
manifest_tokens=$MANIFEST_TOKENS
|
||||
prefixes=$PREFIX_COUNT
|
||||
zh_fraction=$ZH_FRACTION
|
||||
train_iters=$TRAIN_ITERS
|
||||
load_mode=$LOAD_MODE
|
||||
load_dir=$LOAD_DIR
|
||||
load_iteration=$LOAD_ITER
|
||||
save_dir=$CKPT_DIR
|
||||
lr=$LR min_lr=$MIN_LR warmup_fraction=$WARMUP_FRACTION
|
||||
mbs=$MICRO_BATCH_SIZE gbs=$GLOBAL_BATCH_SIZE seq_length=$SEQ_LENGTH
|
||||
save_interval=$SAVE_INTERVAL eval_interval=$EVAL_INTERVAL eval_iters=$EVAL_ITERS
|
||||
validation_prefix=$VALIDATION_PREFIX
|
||||
EOF
|
||||
|
||||
if [[ "$PREFLIGHT_ONLY" == "1" ]]; then
|
||||
echo "Preflight passed; training was not launched."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
nohup docker run --rm --name "$CONTAINER_NAME" \
|
||||
--gpus all --ipc=host --network=host \
|
||||
--ulimit memlock=-1 --ulimit stack=67108864 --ulimit nofile=1048576:1048576 \
|
||||
-e CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$IMAGE" \
|
||||
bash -lc "torchrun --nproc_per_node=8 \
|
||||
training/megatron_bridge/laoyao_2b_moe_pretrain.py \
|
||||
--data-manifest '$DATA_MANIFEST' \
|
||||
--validation-prefix '$VALIDATION_PREFIX' \
|
||||
--seq-length '$SEQ_LENGTH' \
|
||||
--train-iters '$TRAIN_ITERS' \
|
||||
--micro-batch-size '$MICRO_BATCH_SIZE' \
|
||||
--global-batch-size '$GLOBAL_BATCH_SIZE' \
|
||||
--tensor-parallel 1 --pipeline-parallel 1 --expert-parallel 1 --context-parallel 1 \
|
||||
--split 999,1,0 --dataset-workers '$DATASET_WORKERS' \
|
||||
--lr '$LR' --min-lr '$MIN_LR' --warmup-fraction '$WARMUP_FRACTION' \
|
||||
--save-dir '$CKPT_DIR' --load-dir '$LOAD_DIR' \
|
||||
--tensorboard-dir '$TENSORBOARD_DIR' \
|
||||
--save-interval '$SAVE_INTERVAL' --keep-last-checkpoints 10 \
|
||||
--log-interval 10 --eval-interval '$EVAL_INTERVAL' --eval-iters '$EVAL_ITERS' \
|
||||
--use-distributed-optimizer --overlap-grad-reduce --overlap-param-gather \
|
||||
--recompute-granularity full --recompute-method uniform --recompute-num-layers 1 \
|
||||
$STAGE_TRANSITION_ARG" >"$LOG_FILE" 2>&1 &
|
||||
|
||||
echo "Launched container=$CONTAINER_NAME log=$LOG_FILE"
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
IMAGE="${IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
DATA_MANIFEST="${DATA_MANIFEST:-/data/yi/laoyao-2b-pretraining/megatron/stage2_2_8192_glm52_plainqa_cpt_v4_20260722/manifest.json}"
|
||||
DATA_AUDIT="${DATA_AUDIT:-$(dirname "$DATA_MANIFEST")/source_audit.json}"
|
||||
VALIDATION_PREFIX="${VALIDATION_PREFIX:-${REPO_ROOT}/dataset/val/megatron_8192_glm52/heldout_2p8k_text_document}"
|
||||
STAGE2_1_LOAD_DIR="${STAGE2_1_LOAD_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/stage2_1_plainqa_cpt_v4_8192_8gpu_dp8_mbs14_lr5e5_eval5k_from_stage1_2_iter281245/checkpoints}"
|
||||
EXPECTED_STAGE2_1_ITER="${EXPECTED_STAGE2_1_ITER:-54343}"
|
||||
RUN_NAME="${RUN_NAME:-stage2_2_plainqa_cpt_v4_8192_8gpu_dp8_mbs14_lr5e5_eval5k_from_stage2_1_iter54343}"
|
||||
RUN_DIR="${RUN_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/${RUN_NAME}}"
|
||||
CKPT_DIR="${CKPT_DIR:-${RUN_DIR}/checkpoints}"
|
||||
TENSORBOARD_DIR="${TENSORBOARD_DIR:-${RUN_DIR}/tensorboard}"
|
||||
LOG_FILE="${LOG_FILE:-${RUN_DIR}/train.log}"
|
||||
CONTAINER_NAME="${CONTAINER_NAME:-laoyao-stage2-2-plainqa-cpt}"
|
||||
|
||||
SEQ_LENGTH="${SEQ_LENGTH:-8192}"
|
||||
MICRO_BATCH_SIZE="${MICRO_BATCH_SIZE:-14}"
|
||||
GLOBAL_BATCH_SIZE="${GLOBAL_BATCH_SIZE:-112}"
|
||||
LR="${LR:-5.0e-5}"
|
||||
MIN_LR="${MIN_LR:-5.0e-6}"
|
||||
WARMUP_FRACTION="${WARMUP_FRACTION:-0.01}"
|
||||
SAVE_INTERVAL="${SAVE_INTERVAL:-2500}"
|
||||
EVAL_INTERVAL="${EVAL_INTERVAL:-5000}"
|
||||
EVAL_ITERS="${EVAL_ITERS:-10}"
|
||||
DATASET_WORKERS="${DATASET_WORKERS:-4}"
|
||||
PREFLIGHT_ONLY="${PREFLIGHT_ONLY:-0}"
|
||||
|
||||
for path in "$DATA_MANIFEST" "$DATA_AUDIT"; do
|
||||
[[ -f "$path" ]] || { echo "ERROR: missing required data artifact: $path" >&2; exit 1; }
|
||||
done
|
||||
if [[ ! -f "${VALIDATION_PREFIX}.idx" || ! -f "${VALIDATION_PREFIX}.bin" ]]; then
|
||||
echo "ERROR: missing held-out validation prefix: $VALIDATION_PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -r MANIFEST_TOKENS MANIFEST_REPORTED_TOKENS PREFIX_COUNT ZH_FRACTION <<<"$(python3 - "$DATA_MANIFEST" "$DATA_AUDIT" <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
|
||||
manifest = json.load(open(sys.argv[1]))
|
||||
audit = json.load(open(sys.argv[2]))
|
||||
if audit.get("fatal_issues") or audit.get("quota_shortfalls"):
|
||||
raise SystemExit(f"source audit failed: {sys.argv[2]}")
|
||||
prefixes = manifest.get("ok_prefixes") or []
|
||||
bin_files = [Path(f"{prefix}.bin") for prefix in prefixes]
|
||||
idx_files = [Path(f"{prefix}.idx") for prefix in prefixes]
|
||||
missing = [str(path) for path in (*bin_files, *idx_files) if not path.is_file()]
|
||||
if missing:
|
||||
raise SystemExit(f"manifest references {len(missing)} missing indexed-dataset files; first={missing[0]}")
|
||||
bin_bytes = sum(path.stat().st_size for path in bin_files)
|
||||
if bin_bytes % 4:
|
||||
raise SystemExit(f"GLM-5.2 uint32 token binaries have a non-divisible byte count: {bin_bytes}")
|
||||
# The resumable converter reports only newly processed shards in total_tokens.
|
||||
# Recompute over every completed prefix so a resumed conversion is audited in full.
|
||||
actual_tokens = bin_bytes // 4
|
||||
total = max(int(audit.get("tokens", 0)), 1)
|
||||
zh_fraction = int(audit.get("tokens_by_language", {}).get("zh", 0)) / total
|
||||
print(actual_tokens, int(manifest.get("total_tokens", 0)), len(prefixes), f"{zh_fraction:.6f}")
|
||||
PY
|
||||
)"
|
||||
if (( MANIFEST_TOKENS < 49000000000 || PREFIX_COUNT < 800 )); then
|
||||
echo "ERROR: incomplete Stage 2-2 manifest: tokens=$MANIFEST_TOKENS prefixes=$PREFIX_COUNT" >&2
|
||||
exit 1
|
||||
fi
|
||||
python3 - "$ZH_FRACTION" <<'PY'
|
||||
import sys
|
||||
value = float(sys.argv[1])
|
||||
if not 0.09 <= value <= 0.11:
|
||||
raise SystemExit(f"Chinese token fraction outside [0.09, 0.11]: {value:.6f}")
|
||||
PY
|
||||
|
||||
if [[ -z "${TRAIN_ITERS:-}" ]]; then
|
||||
TRAIN_ITERS="$(( (MANIFEST_TOKENS + SEQ_LENGTH * GLOBAL_BATCH_SIZE - 1) / (SEQ_LENGTH * GLOBAL_BATCH_SIZE) ))"
|
||||
fi
|
||||
|
||||
mkdir -p "$CKPT_DIR" "$TENSORBOARD_DIR" "$(dirname "$LOG_FILE")"
|
||||
STAGE_TRANSITION_ARG=""
|
||||
if [[ -f "$CKPT_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
LOAD_DIR="$CKPT_DIR"
|
||||
LOAD_MODE="resume-stage2-2"
|
||||
else
|
||||
LOAD_DIR="$STAGE2_1_LOAD_DIR"
|
||||
LOAD_MODE="stage2-1-model-only"
|
||||
STAGE_TRANSITION_ARG="--finetune-from-checkpoint"
|
||||
fi
|
||||
if [[ ! -f "$LOAD_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
echo "ERROR: checkpoint tracker not found: $LOAD_DIR/latest_checkpointed_iteration.txt" >&2
|
||||
exit 1
|
||||
fi
|
||||
LOAD_ITER="$(tr -d '[:space:]' < "$LOAD_DIR/latest_checkpointed_iteration.txt")"
|
||||
if [[ "$LOAD_MODE" == "stage2-1-model-only" && "$LOAD_ITER" != "$EXPECTED_STAGE2_1_ITER" ]]; then
|
||||
echo "ERROR: expected Stage 2-1 iteration $EXPECTED_STAGE2_1_ITER, found $LOAD_ITER in $LOAD_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
if docker ps --format '{{.Names}}' | grep -Fxq "$CONTAINER_NAME"; then
|
||||
echo "ERROR: container already running: $CONTAINER_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Starting Stage 2-2 continued pretraining
|
||||
data_manifest=$DATA_MANIFEST
|
||||
manifest_tokens=$MANIFEST_TOKENS
|
||||
manifest_reported_tokens=$MANIFEST_REPORTED_TOKENS
|
||||
prefixes=$PREFIX_COUNT
|
||||
zh_fraction=$ZH_FRACTION
|
||||
train_iters=$TRAIN_ITERS
|
||||
load_mode=$LOAD_MODE
|
||||
load_dir=$LOAD_DIR
|
||||
load_iteration=$LOAD_ITER
|
||||
save_dir=$CKPT_DIR
|
||||
lr=$LR min_lr=$MIN_LR warmup_fraction=$WARMUP_FRACTION
|
||||
mbs=$MICRO_BATCH_SIZE gbs=$GLOBAL_BATCH_SIZE seq_length=$SEQ_LENGTH
|
||||
save_interval=$SAVE_INTERVAL eval_interval=$EVAL_INTERVAL eval_iters=$EVAL_ITERS
|
||||
EOF
|
||||
|
||||
if [[ "$PREFLIGHT_ONLY" == "1" ]]; then
|
||||
echo "Preflight passed; training was not launched."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
nohup docker run --rm --name "$CONTAINER_NAME" \
|
||||
--gpus all --ipc=host --network=host \
|
||||
--ulimit memlock=-1 --ulimit stack=67108864 --ulimit nofile=1048576:1048576 \
|
||||
-e CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$IMAGE" \
|
||||
bash -lc "torchrun --nproc_per_node=8 \
|
||||
training/megatron_bridge/laoyao_2b_moe_pretrain.py \
|
||||
--data-manifest '$DATA_MANIFEST' \
|
||||
--validation-prefix '$VALIDATION_PREFIX' \
|
||||
--seq-length '$SEQ_LENGTH' \
|
||||
--train-iters '$TRAIN_ITERS' \
|
||||
--micro-batch-size '$MICRO_BATCH_SIZE' \
|
||||
--global-batch-size '$GLOBAL_BATCH_SIZE' \
|
||||
--tensor-parallel 1 --pipeline-parallel 1 --expert-parallel 1 --context-parallel 1 \
|
||||
--split 999,1,0 --dataset-workers '$DATASET_WORKERS' \
|
||||
--lr '$LR' --min-lr '$MIN_LR' --warmup-fraction '$WARMUP_FRACTION' \
|
||||
--save-dir '$CKPT_DIR' --load-dir '$LOAD_DIR' \
|
||||
--tensorboard-dir '$TENSORBOARD_DIR' \
|
||||
--save-interval '$SAVE_INTERVAL' --keep-last-checkpoints 10 \
|
||||
--log-interval 10 --eval-interval '$EVAL_INTERVAL' --eval-iters '$EVAL_ITERS' \
|
||||
--use-distributed-optimizer --overlap-grad-reduce --overlap-param-gather \
|
||||
--recompute-granularity full --recompute-method uniform --recompute-num-layers 1 \
|
||||
$STAGE_TRANSITION_ARG" >"$LOG_FILE" 2>&1 &
|
||||
|
||||
echo "Launched container=$CONTAINER_NAME log=$LOG_FILE"
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
IMAGE="${IMAGE:-laoyao/nemo-megatron:26.06-flashattn4}"
|
||||
DATA_MANIFEST="${DATA_MANIFEST:-/data/yi/laoyao-2b-pretraining/megatron/stage2_2_8192_glm52_zh10_v3_20260719/manifest.json}"
|
||||
DATA_AUDIT="${DATA_AUDIT:-$(dirname "$DATA_MANIFEST")/source_audit.json}"
|
||||
VALIDATION_PREFIX="${VALIDATION_PREFIX:-${REPO_ROOT}/dataset/val/megatron_8192_glm52/heldout_2p8k_text_document}"
|
||||
STAGE2_1_LOAD_DIR="${STAGE2_1_LOAD_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/stage2_1_8192_8gpu_dp8_mbs14_lr5e5_eval5k_full_recompute_zh10_v3_from_stage1_2_iter281245/checkpoints}"
|
||||
EXPECTED_STAGE2_1_ITER="${EXPECTED_STAGE2_1_ITER:-54343}"
|
||||
RUN_NAME="${RUN_NAME:-stage2_2_8192_8gpu_dp8_mbs14_lr5e5_eval5k_full_recompute_zh10_v3_from_stage2_1_iter54343}"
|
||||
RUN_DIR="${RUN_DIR:-/mnt/beegfs/yi/laoyao-2b-pretraining/runs/${RUN_NAME}}"
|
||||
CKPT_DIR="${CKPT_DIR:-${RUN_DIR}/checkpoints}"
|
||||
TENSORBOARD_DIR="${TENSORBOARD_DIR:-${RUN_DIR}/tensorboard}"
|
||||
LOG_FILE="${LOG_FILE:-${RUN_DIR}/train.log}"
|
||||
CONTAINER_NAME="${CONTAINER_NAME:-laoyao-stage2-2-pretrain}"
|
||||
|
||||
SEQ_LENGTH="${SEQ_LENGTH:-8192}"
|
||||
MICRO_BATCH_SIZE="${MICRO_BATCH_SIZE:-14}"
|
||||
GLOBAL_BATCH_SIZE="${GLOBAL_BATCH_SIZE:-112}"
|
||||
LR="${LR:-5.0e-5}"
|
||||
MIN_LR="${MIN_LR:-5.0e-6}"
|
||||
WARMUP_FRACTION="${WARMUP_FRACTION:-0.01}"
|
||||
SAVE_INTERVAL="${SAVE_INTERVAL:-2500}"
|
||||
EVAL_INTERVAL="${EVAL_INTERVAL:-5000}"
|
||||
EVAL_ITERS="${EVAL_ITERS:-10}"
|
||||
DATASET_WORKERS="${DATASET_WORKERS:-4}"
|
||||
PREFLIGHT_ONLY="${PREFLIGHT_ONLY:-0}"
|
||||
|
||||
for path in "$DATA_MANIFEST" "$DATA_AUDIT"; do
|
||||
[[ -f "$path" ]] || { echo "ERROR: missing required data artifact: $path" >&2; exit 1; }
|
||||
done
|
||||
if [[ ! -f "${VALIDATION_PREFIX}.idx" || ! -f "${VALIDATION_PREFIX}.bin" ]]; then
|
||||
echo "ERROR: missing held-out validation prefix: $VALIDATION_PREFIX" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -r MANIFEST_TOKENS MANIFEST_REPORTED_TOKENS PREFIX_COUNT ZH_FRACTION <<<"$(python3 - "$DATA_MANIFEST" "$DATA_AUDIT" <<'PY'
|
||||
import json, sys
|
||||
from pathlib import Path
|
||||
|
||||
manifest = json.load(open(sys.argv[1]))
|
||||
audit = json.load(open(sys.argv[2]))
|
||||
if audit.get("fatal_issues") or audit.get("quota_shortfalls"):
|
||||
raise SystemExit(f"source audit failed: {sys.argv[2]}")
|
||||
prefixes = manifest.get("ok_prefixes") or []
|
||||
bin_files = [Path(f"{prefix}.bin") for prefix in prefixes]
|
||||
idx_files = [Path(f"{prefix}.idx") for prefix in prefixes]
|
||||
missing = [str(path) for path in (*bin_files, *idx_files) if not path.is_file()]
|
||||
if missing:
|
||||
raise SystemExit(f"manifest references {len(missing)} missing indexed-dataset files; first={missing[0]}")
|
||||
bin_bytes = sum(path.stat().st_size for path in bin_files)
|
||||
if bin_bytes % 4:
|
||||
raise SystemExit(f"GLM-5.2 uint32 token binaries have a non-divisible byte count: {bin_bytes}")
|
||||
# The resumable converter reports only newly processed shards in total_tokens.
|
||||
# Recompute over every completed prefix so a resumed conversion is audited in full.
|
||||
actual_tokens = bin_bytes // 4
|
||||
total = max(int(audit.get("tokens", 0)), 1)
|
||||
zh_fraction = int(audit.get("tokens_by_language", {}).get("zh", 0)) / total
|
||||
print(actual_tokens, int(manifest.get("total_tokens", 0)), len(prefixes), f"{zh_fraction:.6f}")
|
||||
PY
|
||||
)"
|
||||
if (( MANIFEST_TOKENS < 49000000000 || PREFIX_COUNT < 800 )); then
|
||||
echo "ERROR: incomplete Stage 2-2 manifest: tokens=$MANIFEST_TOKENS prefixes=$PREFIX_COUNT" >&2
|
||||
exit 1
|
||||
fi
|
||||
python3 - "$ZH_FRACTION" <<'PY'
|
||||
import sys
|
||||
value = float(sys.argv[1])
|
||||
if not 0.09 <= value <= 0.11:
|
||||
raise SystemExit(f"Chinese token fraction outside [0.09, 0.11]: {value:.6f}")
|
||||
PY
|
||||
|
||||
if [[ -z "${TRAIN_ITERS:-}" ]]; then
|
||||
TRAIN_ITERS="$(( (MANIFEST_TOKENS + SEQ_LENGTH * GLOBAL_BATCH_SIZE - 1) / (SEQ_LENGTH * GLOBAL_BATCH_SIZE) ))"
|
||||
fi
|
||||
|
||||
mkdir -p "$CKPT_DIR" "$TENSORBOARD_DIR" "$(dirname "$LOG_FILE")"
|
||||
STAGE_TRANSITION_ARG=""
|
||||
if [[ -f "$CKPT_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
LOAD_DIR="$CKPT_DIR"
|
||||
LOAD_MODE="resume-stage2-2"
|
||||
else
|
||||
LOAD_DIR="$STAGE2_1_LOAD_DIR"
|
||||
LOAD_MODE="stage2-1-model-only"
|
||||
STAGE_TRANSITION_ARG="--finetune-from-checkpoint"
|
||||
fi
|
||||
if [[ ! -f "$LOAD_DIR/latest_checkpointed_iteration.txt" ]]; then
|
||||
echo "ERROR: checkpoint tracker not found: $LOAD_DIR/latest_checkpointed_iteration.txt" >&2
|
||||
exit 1
|
||||
fi
|
||||
LOAD_ITER="$(tr -d '[:space:]' < "$LOAD_DIR/latest_checkpointed_iteration.txt")"
|
||||
if [[ "$LOAD_MODE" == "stage2-1-model-only" && "$LOAD_ITER" != "$EXPECTED_STAGE2_1_ITER" ]]; then
|
||||
echo "ERROR: expected Stage 2-1 iteration $EXPECTED_STAGE2_1_ITER, found $LOAD_ITER in $LOAD_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
if docker ps --format '{{.Names}}' | grep -Fxq "$CONTAINER_NAME"; then
|
||||
echo "ERROR: container already running: $CONTAINER_NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Starting Stage 2-2 continued pretraining
|
||||
data_manifest=$DATA_MANIFEST
|
||||
manifest_tokens=$MANIFEST_TOKENS
|
||||
manifest_reported_tokens=$MANIFEST_REPORTED_TOKENS
|
||||
prefixes=$PREFIX_COUNT
|
||||
zh_fraction=$ZH_FRACTION
|
||||
train_iters=$TRAIN_ITERS
|
||||
load_mode=$LOAD_MODE
|
||||
load_dir=$LOAD_DIR
|
||||
load_iteration=$LOAD_ITER
|
||||
save_dir=$CKPT_DIR
|
||||
lr=$LR min_lr=$MIN_LR warmup_fraction=$WARMUP_FRACTION
|
||||
mbs=$MICRO_BATCH_SIZE gbs=$GLOBAL_BATCH_SIZE seq_length=$SEQ_LENGTH
|
||||
save_interval=$SAVE_INTERVAL eval_interval=$EVAL_INTERVAL eval_iters=$EVAL_ITERS
|
||||
EOF
|
||||
|
||||
if [[ "$PREFLIGHT_ONLY" == "1" ]]; then
|
||||
echo "Preflight passed; training was not launched."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
nohup docker run --rm --name "$CONTAINER_NAME" \
|
||||
--gpus all --ipc=host --network=host \
|
||||
--ulimit memlock=-1 --ulimit stack=67108864 --ulimit nofile=1048576:1048576 \
|
||||
-e CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
|
||||
-v /data:/data -v /mnt/beegfs:/mnt/beegfs \
|
||||
-w "$REPO_ROOT" "$IMAGE" \
|
||||
bash -lc "torchrun --nproc_per_node=8 \
|
||||
training/megatron_bridge/laoyao_2b_moe_pretrain.py \
|
||||
--data-manifest '$DATA_MANIFEST' \
|
||||
--validation-prefix '$VALIDATION_PREFIX' \
|
||||
--seq-length '$SEQ_LENGTH' \
|
||||
--train-iters '$TRAIN_ITERS' \
|
||||
--micro-batch-size '$MICRO_BATCH_SIZE' \
|
||||
--global-batch-size '$GLOBAL_BATCH_SIZE' \
|
||||
--tensor-parallel 1 --pipeline-parallel 1 --expert-parallel 1 --context-parallel 1 \
|
||||
--split 999,1,0 --dataset-workers '$DATASET_WORKERS' \
|
||||
--lr '$LR' --min-lr '$MIN_LR' --warmup-fraction '$WARMUP_FRACTION' \
|
||||
--save-dir '$CKPT_DIR' --load-dir '$LOAD_DIR' \
|
||||
--tensorboard-dir '$TENSORBOARD_DIR' \
|
||||
--save-interval '$SAVE_INTERVAL' --keep-last-checkpoints 10 \
|
||||
--log-interval 10 --eval-interval '$EVAL_INTERVAL' --eval-iters '$EVAL_ITERS' \
|
||||
--use-distributed-optimizer --overlap-grad-reduce --overlap-param-gather \
|
||||
--recompute-granularity full --recompute-method uniform --recompute-num-layers 1 \
|
||||
$STAGE_TRANSITION_ARG" >"$LOG_FILE" 2>&1 &
|
||||
|
||||
echo "Launched container=$CONTAINER_NAME log=$LOG_FILE"
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
TOKENIZE_CONTAINER="${TOKENIZE_CONTAINER:-laoyao-stage2-1-megatron-tokenize}"
|
||||
POLL_SECONDS="${POLL_SECONDS:-60}"
|
||||
REPO_ROOT="${REPO_ROOT:-/mnt/beegfs/yi/laoyao-2b-pretraining/code/laoyao_2b_moe}"
|
||||
TRAIN_SCRIPT="${TRAIN_SCRIPT:-${REPO_ROOT}/scripts/train_stage2_1_pretrain_8192_8gpu_mbs14.sh}"
|
||||
|
||||
while [[ "$(docker inspect -f '{{.State.Running}}' "$TOKENIZE_CONTAINER" 2>/dev/null || echo missing)" == "true" ]]; do
|
||||
echo "WAIT_STAGE2_1_TOKENIZE $(date -Is)"
|
||||
sleep "$POLL_SECONDS"
|
||||
done
|
||||
|
||||
if ! docker inspect "$TOKENIZE_CONTAINER" >/dev/null 2>&1; then
|
||||
echo "ERROR: tokenization container disappeared: $TOKENIZE_CONTAINER" >&2
|
||||
exit 1
|
||||
fi
|
||||
exit_code="$(docker inspect -f '{{.State.ExitCode}}' "$TOKENIZE_CONTAINER")"
|
||||
if [[ "$exit_code" != "0" ]]; then
|
||||
echo "ERROR: tokenization failed with exit code $exit_code" >&2
|
||||
docker logs --tail 100 "$TOKENIZE_CONTAINER" >&2
|
||||
exit "$exit_code"
|
||||
fi
|
||||
|
||||
echo "STAGE2_1_TOKENIZE_DONE $(date -Is)"
|
||||
bash "$TRAIN_SCRIPT"
|
||||
Reference in New Issue
Block a user