File size: 1,694 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
# LittleBoy: Colab worker. Paste into ONE Colab cell (CPU runtime, high RAM if available) and run.
# Needs the Colab secret STARHUGGIN (or HF_TOKEN) with notebook access enabled (key icon on the left).
# It builds LittleBoy shards from the HIGHEST index down, skipping any shard already on the Hub, so it never repeats
# the work of the PC (shards 1-24) or of the Google Cloud VM (ascending from 25). Resumable: re-run the cell after a
# disconnect.
import os
import subprocess
import sys

from google.colab import userdata

tok = next(v for v in (userdata.get(k) for k in ("STARHUGGIN", "HF_TOKEN")) if v)
with open("/root/hf_token", "w") as f:
    f.write(tok.strip())
os.chmod("/root/hf_token", 0o600)
del tok
subprocess.run([sys.executable, "-m", "pip", "install", "-q", "-U", "huggingface_hub", "hf_xet", "numpy"], check=True)

from huggingface_hub import hf_hub_download  # noqa: E402

os.makedirs("/content/lb", exist_ok=True)
for f in ("expand_kimi.py", "wsp_activate.py", "publish_littleboy.py"):
    hf_hub_download("STAR-future/Trinity", "tools/" + f, local_dir="/content/lb", token=open("/root/hf_token").read())
os.makedirs("/content/lb/none", exist_ok=True)
print("cores:", os.cpu_count())
env = dict(os.environ, HF_TOKEN_FILE="/root/hf_token")
p = subprocess.Popen([sys.executable, "-u", "/content/lb/tools/publish_littleboy.py", "--repo", "STAR-future/Trinity",
                      "--local", "/content/lb/none", "--work", "/content/lb/work", "--first", "24", "--reverse"],
                     env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
for line in p.stdout:
    if "%|" not in line:
        print(line, end="", flush=True)
print("exit", p.wait())