File size: 1,562 Bytes
9d945e1 | 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 | """Session start: report GPU and disk, install the few pip packages set 5 needs, check Drive and the HF secret.
The HF token is read from Colab Secrets (HF_TOKEN) and only its presence is reported; it is exported to the
process environment for huggingface_hub and never printed.
"""
import os
import subprocess
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from common5 import OUT_DRIVE, OUT_LOCAL, disk_free_gb, drive_ok, env_report, log, write_json # noqa: E402
smi, df = env_report()
print(smi)
print(df)
log(f"free disk on /content: {disk_free_gb():.0f} GB")
need = ["torch-fidelity", "diffusers", "timm", "torchdiffeq"]
subprocess.run([sys.executable, "-m", "pip", "install", "-q", *need], check=True)
try:
from google.colab import userdata
tok = userdata.get("HF_TOKEN")
os.environ["HF_TOKEN"] = tok
hf = "present"
except Exception as e: # secret missing or notebook access not granted
hf = f"unavailable ({type(e).__name__})"
log("HF_TOKEN:", hf)
log("Drive mounted:", drive_ok(), "->", OUT_DRIVE if drive_ok() else OUT_LOCAL)
import torch # noqa: E402
write_json(OUT_LOCAL / "step0" / "env.json", {
"gpu": torch.cuda.get_device_name() if torch.cuda.is_available() else None,
"gpu_mem_gb": round(torch.cuda.get_device_properties(0).total_memory / 1e9, 1) if torch.cuda.is_available() else None,
"torch": torch.__version__, "python": sys.version.split()[0], "free_disk_gb": round(disk_free_gb()),
"hf_token": hf, "drive": drive_ok(), "nvidia_smi": smi, "df": df})
|