#!/bin/bash
# fineweb-edu 一个 parquet 分片 → jsonl → Megatron indexed dataset（Qwen3 tokenizer，文档末尾加 eod）。
set -euo pipefail
ROOT=/root/paddlejob/amfp-public/weiziyang/moe_dispatcher
D=/root/paddlejob/amfp-public/weiziyang/data/fineweb-edu
HF=/root/paddlejob/amfp-public/weiziyang/models/Qwen3-30B-A3B
mkdir -p $D/megatron
python - <<PY
import json, pyarrow.parquet as pq
with open("$D/megatron/fineweb_edu_000.jsonl", "w") as f:
    for b in pq.ParquetFile("$D/sample/10BT/000_00000.parquet").iter_batches(batch_size=4096, columns=["text"]):
        for t in b.column("text").to_pylist():
            f.write(json.dumps({"text": t}) + "\n")
PY
source $ROOT/bench/scripts/env.sh
cd /tmp && python $ROOT/third_party/Megatron-LM-main/tools/preprocess_data.py \
  --input $D/megatron/fineweb_edu_000.jsonl --output-prefix $D/megatron/fineweb_edu_000 \
  --tokenizer-type HuggingFaceTokenizer --tokenizer-model $HF --append-eod --workers 32
ls -la $D/megatron
