Download runpod/tokenize_5b_parallel.sh from Infinity08/KAWK50M-Project: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/datasets/Infinity08/KAWK50M-Project/resolve/main/runpod/tokenize_5b_parallel.sh
- Command line
-
hf download hf://datasets/Infinity08/KAWK50M-Project/runpod/tokenize_5b_parallel.sh
-
curl -L -o tokenize_5b_parallel.sh https://huggingface.co/datasets/Infinity08/KAWK50M-Project/resolve/main/runpod/tokenize_5b_parallel.sh
2.32 kB
| set -euo pipefail | |
| PROJECT_DIR="${PROJECT_DIR:-/workspace/KAWK50M}" | |
| CLEAN_DIR="${CLEAN_DIR:-data/clean-5b}" | |
| TOKENIZED_DIR="${TOKENIZED_DIR:-data/tokenized-5b}" | |
| TOKENIZER_DIR="${TOKENIZER_DIR:-artifacts/tokenizer-20k-pilot}" | |
| WORKERS="${WORKERS:-16}" | |
| cd "${PROJECT_DIR}" | |
| source "${PROJECT_DIR}/.venv/bin/activate" | |
| if [[ -e "${TOKENIZED_DIR}" ]]; then | |
| echo "Refusing to overwrite existing output: ${TOKENIZED_DIR}" >&2 | |
| exit 1 | |
| fi | |
| mkdir -p "${TOKENIZED_DIR}/parts" | |
| tokenize_parts() { | |
| local split="$1" | |
| local split_dir="${TOKENIZED_DIR}/parts/${split}" | |
| mkdir -p "${split_dir}" | |
| find "${CLEAN_DIR}" -maxdepth 1 -type f -name "${split}-*.jsonl" -print0 \ | |
| | sort -z \ | |
| | xargs -0 -r -P "${WORKERS}" -I '{}' bash -c ' | |
| input="$1" | |
| output_dir="$2" | |
| tokenizer_dir="$3" | |
| stem="$(basename "${input%.jsonl}")" | |
| python -u -m scripts.tokenize_shard \ | |
| --input "${input}" \ | |
| --tokenizer-dir "${tokenizer_dir}" \ | |
| --output "${output_dir}/${stem}.bin" \ | |
| --batch-size 64 | |
| ' _ '{}' "${split_dir}" "${TOKENIZER_DIR}" | |
| } | |
| tokenize_parts train | |
| tokenize_parts validation | |
| tokenize_parts test | |
| python -m scripts.combine_token_parts \ | |
| --input-dir "${TOKENIZED_DIR}/parts/train" \ | |
| --output "${TOKENIZED_DIR}/train.bin" \ | |
| --max-tokens 5000000000 | |
| python -m scripts.combine_token_parts \ | |
| --input-dir "${TOKENIZED_DIR}/parts/validation" \ | |
| --output "${TOKENIZED_DIR}/validation.bin" \ | |
| --max-tokens 2000000 | |
| python -m scripts.combine_token_parts \ | |
| --input-dir "${TOKENIZED_DIR}/parts/test" \ | |
| --output "${TOKENIZED_DIR}/test.bin" \ | |
| --max-tokens 1000000 | |
| python - <<'PY' | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| root = Path("data/tokenized-5b") | |
| splits = {} | |
| for split in ("train", "validation", "test"): | |
| path = root / f"{split}.metadata.json" | |
| splits[split] = json.loads(path.read_text(encoding="utf-8")) | |
| metadata = { | |
| "tokenizer": str(Path("artifacts/tokenizer-20k-pilot").resolve()), | |
| "vocab_size": 20000, | |
| "eos_token_id": 2, | |
| "splits": splits, | |
| } | |
| (root / "metadata.json").write_text( | |
| json.dumps(metadata, ensure_ascii=False, indent=2) + "\n", | |
| encoding="utf-8", | |
| ) | |
| print(json.dumps(metadata, ensure_ascii=False, indent=2)) | |
| PY | |
| echo "Parallel 5B tokenization complete." | |