File size: 2,361 Bytes
f80e81a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Colab cell run AFTER a k3pass 'train' pass, in the same runtime: if the per-token cache did not reach the PRIVATE
dataset STAR-future/Trinity-k3cache (the org's private storage was full on 2026-11-20), free private space by
removing the layer checkpoints of that same, now finished pass (STAR-future/Trinity-k3ckpt-train: regenerable and
useless once the pass has run all 93 layers), squash its history, and upload the cache to the private dataset.
Nothing is ever made public.

    exec(open(h.hf_hub_download('STAR-future/Trinity', 'tools/colab_k3cache_rescue.py', token=os.environ['HF_TOKEN'],
                                force_download=True)).read())
"""
import json
import os
from pathlib import Path

from huggingface_hub import CommitOperationDelete, HfApi

api = HfApi(token=os.environ["HF_TOKEN"])
CACHE, CKPT = "STAR-future/Trinity-k3cache", "STAR-future/Trinity-k3ckpt-train"
NEEDED = ("summary.json", "x92.npy", "acc92.npy", "A92.npy", "Zm92.npy", "prefix92.npy", "target92.npy")
out = Path("/content/k3p/out_train")
summary = out / "summary.json"
if not summary.exists():
    raise SystemExit("no finished train pass in this runtime")
lr = json.loads(summary.read_text()).get("layers_run")
if lr != 93:
    raise SystemExit(f"train pass ran {lr} layers, not 93: nothing to rescue")
fs = api.list_repo_files(CACHE, repo_type="dataset")
if all(f"train/{n}" in fs for n in NEEDED):
    print("train cache already in the private dataset: nothing to do")
else:
    try:
        old = [f for f in api.list_repo_files(CKPT, repo_type="dataset") if f != ".gitattributes"]
        if old:
            api.create_commit(CKPT, repo_type="dataset", operations=[CommitOperationDelete(path_in_repo=f) for f in old],
                              commit_message="train pass finished (93 layers): checkpoints no longer needed")
            api.super_squash_history(repo_id=CKPT, repo_type="dataset")
            print("freed the finished pass's checkpoints:", old)
    except Exception as e:  # noqa: BLE001
        print("checkpoint cleanup failed:", type(e).__name__, str(e)[:200])
    api.upload_folder(repo_id=CACHE, repo_type="dataset", folder_path=str(out), path_in_repo="train",
                      allow_patterns=["*.npy", "*.json"], commit_message="k3pass cache train (93 layers)")
    print("train cache uploaded to the private dataset", CACHE)