Download runpod/stream_v2_20b.sh from Infinity08/KAWK50M-Project: direct link, hf CLI and curl.
- Browser
- Download file 4.12 kB
-
https://huggingface.co/datasets/Infinity08/KAWK50M-Project/resolve/main/runpod/stream_v2_20b.sh
- Command line
-
hf download hf://datasets/Infinity08/KAWK50M-Project/runpod/stream_v2_20b.sh
-
curl -L -o stream_v2_20b.sh https://huggingface.co/datasets/Infinity08/KAWK50M-Project/resolve/main/runpod/stream_v2_20b.sh
4.12 kB
| set -euo pipefail | |
| PROJECT_DIR="${PROJECT_DIR:-/workspace/KAWK50M}" | |
| OUTPUT_ROOT="${OUTPUT_ROOT:-data/tokenized-v2-20b/stream}" | |
| INITIAL_MANIFEST="${INITIAL_MANIFEST:-data/tokenized-v2-20b/initial/manifest.json}" | |
| TOKENIZER_DIR="${TOKENIZER_DIR:-artifacts/tokenizer-20k-v3}" | |
| REVISION="${REVISION:-af9c13333eb981300149d5ca60a8e9d659b276b9}" | |
| TARGET_TOKENS="${TARGET_TOKENS:-20000000000}" | |
| DATASET_SHARDS="${DATASET_SHARDS:-4}" | |
| SKIP_PER_SHARD="${SKIP_PER_SHARD:-1625000}" | |
| FILTER_WORKERS_PER_STREAM="${FILTER_WORKERS_PER_STREAM:-4}" | |
| RESUME="${RESUME:-0}" | |
| cd "${PROJECT_DIR}" | |
| source "${PROJECT_DIR}/.venv/bin/activate" | |
| ulimit -c 0 | |
| if [[ ! -f "${INITIAL_MANIFEST}" ]]; then | |
| echo "Initial token manifest is missing: ${INITIAL_MANIFEST}" >&2 | |
| exit 1 | |
| fi | |
| if [[ -e "${OUTPUT_ROOT}" && "${RESUME}" != "1" ]]; then | |
| echo "Refusing to overwrite existing stream output: ${OUTPUT_ROOT}" >&2 | |
| exit 1 | |
| fi | |
| mkdir -p "${OUTPUT_ROOT}" | |
| read -r initial_tokens tokens_per_worker < <( | |
| python - "${INITIAL_MANIFEST}" "${TARGET_TOKENS}" "${DATASET_SHARDS}" <<'PY' | |
| import json | |
| import math | |
| import sys | |
| initial = int(json.load(open(sys.argv[1], encoding="utf-8"))["tokens"]) | |
| target = int(sys.argv[2]) | |
| workers = int(sys.argv[3]) | |
| remaining = target - initial | |
| if remaining <= 0: | |
| raise SystemExit("Initial corpus already reaches the target") | |
| print(initial, math.ceil(remaining / workers)) | |
| PY | |
| ) | |
| echo "initial_tokens=${initial_tokens} tokens_per_stream=${tokens_per_worker}" | |
| pids=() | |
| for ((worker = 0; worker < DATASET_SHARDS; worker++)); do | |
| worker_dir="${OUTPUT_ROOT}/part-$(printf '%02d' "${worker}")" | |
| worker_log="/workspace/kawk-v2-stream-20b-worker-$(printf '%02d' "${worker}").log" | |
| resume_args=() | |
| if [[ -e "${worker_dir}" ]]; then | |
| if [[ "${RESUME}" != "1" || ! -f "${worker_dir}/state.json" ]]; then | |
| echo "Worker output exists without a resumable state: ${worker_dir}" >&2 | |
| exit 1 | |
| fi | |
| resume_args+=(--resume) | |
| fi | |
| python -u -m scripts.stream_tokenize_fineweb2 \ | |
| --revision "${REVISION}" \ | |
| --tokenizer-dir "${TOKENIZER_DIR}" \ | |
| --output-dir "${worker_dir}" \ | |
| --dataset-num-shards "${DATASET_SHARDS}" \ | |
| --dataset-shard-index "${worker}" \ | |
| --skip-documents "${SKIP_PER_SHARD}" \ | |
| --max-output-tokens "${tokens_per_worker}" \ | |
| --tokens-per-chunk 250000000 \ | |
| --shuffle-buffer 10000 \ | |
| --seed "$((42 + worker))" \ | |
| --workers "${FILTER_WORKERS_PER_STREAM}" \ | |
| --worker-batch-size 64 \ | |
| --tokenize-batch-size 512 \ | |
| "${resume_args[@]}" \ | |
| > "${worker_log}" 2>&1 & | |
| pids+=("$!") | |
| echo "worker=${worker} pid=${pids[-1]} log=${worker_log}" | |
| done | |
| status=0 | |
| for pid in "${pids[@]}"; do | |
| if ! wait "${pid}"; then | |
| status=1 | |
| fi | |
| done | |
| if (( status != 0 )); then | |
| echo "At least one stream-tokenization worker failed." >&2 | |
| exit "${status}" | |
| fi | |
| python - "${INITIAL_MANIFEST}" "${OUTPUT_ROOT}" "${TARGET_TOKENS}" <<'PY' | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| from pathlib import Path | |
| initial_manifest = Path(sys.argv[1]) | |
| output_root = Path(sys.argv[2]) | |
| target = int(sys.argv[3]) | |
| initial = json.loads(initial_manifest.read_text(encoding="utf-8")) | |
| states = [ | |
| json.loads(path.read_text(encoding="utf-8")) | |
| for path in sorted(output_root.glob("part-*/state.json")) | |
| ] | |
| summary = { | |
| "initial_tokens": int(initial["tokens"]), | |
| "stream_workers": len(states), | |
| "stream_tokens": sum(int(state["tokens_written"]) for state in states), | |
| "total_tokens": int(initial["tokens"]) | |
| + sum(int(state["tokens_written"]) for state in states), | |
| "complete": bool(states) and all(bool(state["complete"]) for state in states), | |
| "revision": sorted({state["revision"] for state in states}), | |
| } | |
| if not summary["complete"] or summary["total_tokens"] < target: | |
| raise SystemExit(f"Incomplete 20B stream: {summary}") | |
| (output_root.parent / "manifest.json").write_text( | |
| json.dumps(summary, ensure_ascii=False, indent=2) + "\n", | |
| encoding="utf-8", | |
| ) | |
| print(json.dumps(summary, ensure_ascii=False, indent=2)) | |
| PY | |
| python -m scripts.preflight --config configs/pretrain_v2_20b_5090.yaml | |
| echo "KAWK50M v2 20B token corpus complete." | |