zaher-m's picture
download
raw
2.55 kB
"""Phase 1 checks on the chosen model: environment, parameter count, digit tokenization, smoke test.
Call runtime.setup() before importing this module.
"""
import json
import os
from pathlib import Path
from src import env_info, param_count, smoke_test, tokenizer_survey
OUT = Path("results/model_search")
def slug(repo_id):
return repo_id.replace("/", "__")
def snapshot_dir(repo_id, revision):
"""Local folder of a pinned snapshot. Offline it is read from the cache layout, because
snapshot_download in offline mode still asks the Hub for the file tree."""
if os.environ.get("HF_HUB_OFFLINE") == "1":
snap = Path(os.environ["HF_HUB_CACHE"]) / f"models--{repo_id.replace('/', '--')}" / "snapshots" / revision
if not snap.is_dir():
raise FileNotFoundError(f"{repo_id} at {revision} is not in the cache")
return snap
from huggingface_hub import snapshot_download
return Path(snapshot_download(repo_id, revision=revision))
def count_params(repo_id, revision):
params, dtypes, n_files = param_count.count_snapshot(snapshot_dir(repo_id, revision))
count = {"repo_id": repo_id, "revision": revision, "params": params, "dtypes": dtypes, "n_safetensors": n_files}
path = OUT / f"param_count_{slug(repo_id)}.json"
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(count, indent=2))
print(count)
return path
def check_tokenizer(repo_id, revision):
csv_path = tokenizer_survey.main(OUT / f"tokenizer_digits_{slug(repo_id)}.csv", {repo_id: revision})
pieces = tokenizer_survey.example_pieces(repo_id, revision)
pieces_path = OUT / f"tokenizer_pieces_{slug(repo_id)}.json"
pieces_path.write_text(json.dumps(pieces, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps(pieces, ensure_ascii=False))
return [csv_path, pieces_path]
def smoke(repo_id, revision, max_new_tokens):
paths = []
for dtype_name in ("bfloat16", "float16"):
res = smoke_test.run(repo_id, revision, dtype_name, max_new_tokens=max_new_tokens)
paths.append(smoke_test.save(res))
print(json.dumps(res, ensure_ascii=False, indent=1))
return paths
def main(rt):
cfg = rt["config"]
repo_id, revision = cfg["model"]["repo_id"], cfg["model"]["revision"]
paths = [env_info.main("logs/env_phase1.txt")]
paths.append(count_params(repo_id, revision))
paths += check_tokenizer(repo_id, revision)
paths += smoke(repo_id, revision, cfg["decoding"]["max_new_tokens"])
return paths

Xet Storage Details

Size:
2.55 kB
·
Xet hash:
fd7ccce9959bced3f56f3574d309d6811244d157337bc8f990583ea9c3567d87

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.