seu-3dgs / code /hf_release.py
Lightcap's picture
Upload folder using huggingface_hub
121e1fb verified
Raw
History Blame Contribute Delete
9.77 kB
"""Publish the SEU-3DGS artifacts to a HuggingFace dataset repo.
Uploads whatever currently exists (idempotent), so it can be run once for the
code and trained models and again after the campaign for the results, logs,
figures, and dataset card. Token is read from the HF_TOKEN environment variable.
"""
import glob
import json
import os
from huggingface_hub import HfApi, create_repo
REPO = "Lightcap/seu-3dgs"
ROOT = "/root/seu"
SCENES = ["chair", "lego", "ficus", "hotdog"]
TOK = os.environ["HF_TOKEN"]
api = HfApi()
def card():
summ = {}
for s in SCENES:
p = os.path.join(ROOT, "results", s, "train_summary.json")
if os.path.exists(p):
summ[s] = json.load(open(p))
has_parquet = os.path.isdir(os.path.join(ROOT, "results", "parquet", "single_bit_upsets"))
lines = []
lines.append("---")
lines.append("license: mit")
lines.append("tags:")
for t in ["gaussian-splatting", "fault-tolerance", "single-event-upset",
"reliability", "radiance-fields", "computer-graphics"]:
lines.append(f" - {t}")
lines.append("pretty_name: Single-Event Upsets in 3D Gaussian Splatting")
if has_parquet:
# Point the dataset viewer at the per-injection Parquet records so it
# browses the millions of single-bit upset rows (not the summary JSONs).
lines.append("configs:")
lines.append(" - config_name: single_bit_upsets")
lines.append(" data_files:")
lines.append(" - split: train")
lines.append(" path: data/single_bit_upsets/*.parquet")
lines.append(" - config_name: multi_upset")
lines.append(" data_files:")
lines.append(" - split: train")
lines.append(" path: data/multi_upset/*.parquet")
else:
lines.append("viewer: false")
lines.append("---\n")
lines.append("# Single-Event Upsets in 3D Gaussian Splatting Rendering\n")
lines.append("Artifacts for the paper *Single-Event Upsets in 3D Gaussian Splatting "
"Rendering: Bit-Level Criticality, Spatial Extent, and a Parallel Support "
"Guard* (F. Alpay and B. Kilictas).\n")
lines.append("A trained 3DGS model is a large floating-point array resident in GPU "
"memory, so a single-event upset is one flipped bit in one parameter. "
"This repository releases the fault-injection engine, the trained models, "
"the per-cell aggregated records of more than three million controlled "
"single-bit upsets, the multi-upset records, the throughput measurements, "
"the logs (including the periodic device-utilization trace), and the "
"scripts that regenerate every figure and table in the paper.\n")
if summ:
lines.append("## Trained scenes\n")
lines.append("| scene | primitives | PSNR (dB) | SSIM |")
lines.append("|---|---:|---:|---:|")
for s in SCENES:
if s in summ:
d = summ[s]
lines.append(f"| {s} | {int(d['n_gaussians']):,} | {d['test_psnr']:.2f} | {d['test_ssim']:.4f} |")
lines.append("")
lines.append("## Layout\n")
lines.append("```")
lines.append("code/ training, fault-injection engine, campaign, analysis, figures")
lines.append("models/ trained gsplat checkpoints per scene (model.pt)")
lines.append("data/ per-injection records as Parquet (browsable in the viewer)")
lines.append("results/ aggregate.json, bench.json, multiupset/largescene records, summaries")
lines.append("logs/ campaign / driver / GPU-utilisation logs")
lines.append("figures/ regenerated figures, tables, and numbers.tex")
lines.append("```\n")
lines.append("Paper: see PAPER_URL below. Reproduce with `code/` following `code/`'s "
"header comments; the GPU run used an RTX 5090 (sm_120), PyTorch 2.12 / "
"CUDA 13, gsplat 1.5.3.\n")
lines.append("PAPER_URL: __ARXIV_LINK_PLACEHOLDER__\n")
if has_parquet:
lines.append("The per-injection records are browsable in the dataset viewer "
"(`single_bit_upsets`: one row per single-bit upset, several million "
"rows; `multi_upset`: accumulated-dose records), stored as Parquet under "
"`data/`.\n")
return "\n".join(lines)
FIELD_NAMES = ["means", "scales", "quats", "opacities", "sh0", "shN"]
BCLASS = {0: "sign", 1: "exp", 2: "mantissa"}
def write_parquet(root):
"""Convert the per-injection .npz shards into viewer-friendly Parquet, one
file per (scene, precision), with readable field/bit-class names."""
import glob
import numpy as np
import pandas as pd
sb_dir = os.path.join(root, "results", "parquet", "single_bit_upsets")
mu_dir = os.path.join(root, "results", "parquet", "multi_upset")
os.makedirs(sb_dir, exist_ok=True); os.makedirs(mu_dir, exist_ok=True)
n = 0
for fp in sorted(glob.glob(os.path.join(root, "results", "campaign", "shard_*.npz"))):
d = np.load(fp, allow_pickle=True); a = d["data"]; cols = list(d["cols"]); meta = list(d["meta"])
df = pd.DataFrame(a, columns=cols)
df["scene"] = meta[0]; df["precision"] = meta[1]
df["field"] = df["field_id"].astype(int).map(lambda i: FIELD_NAMES[i])
df["bitclass"] = df["bitclass"].astype(int).map(BCLASS)
df["guarded"] = fp.endswith("_guard.npz")
df = df.drop(columns=["field_id"])
df.to_parquet(os.path.join(sb_dir, os.path.basename(fp).replace(".npz", ".parquet")), index=False)
n += len(df)
for fp in sorted(glob.glob(os.path.join(root, "results", "multiupset", "multiupset_*.npz"))):
d = np.load(fp, allow_pickle=True); a = d["data"]; cols = list(d["cols"]); meta = list(d["meta"])
df = pd.DataFrame(a, columns=cols)
df["scene"] = meta[0]; df["precision"] = meta[1]; df["guarded"] = fp.endswith("_guard.npz")
df.to_parquet(os.path.join(mu_dir, os.path.basename(fp).replace(".npz", ".parquet")), index=False)
print(f"wrote parquet: {n} single-bit-upset rows")
return n
def main():
create_repo(REPO, repo_type="dataset", token=TOK, exist_ok=True, private=False)
print("repo ready:", REPO)
# convert per-injection records to Parquet so the dataset viewer can browse
# the millions of rows (skips gracefully if the campaign has not produced shards)
try:
if glob.glob(os.path.join(ROOT, "results", "campaign", "shard_*.npz")):
write_parquet(ROOT)
api.upload_folder(folder_path=os.path.join(ROOT, "results", "parquet"),
path_in_repo="data", repo_id=REPO, repo_type="dataset",
token=TOK, allow_patterns=["*.parquet"])
print("uploaded data/ (parquet)")
except Exception as e:
print("parquet step skipped:", e)
# dataset card
cpath = "/tmp/README_hf.md"
open(cpath, "w").write(card())
api.upload_file(path_or_fileobj=cpath, path_in_repo="README.md", repo_id=REPO,
repo_type="dataset", token=TOK)
print("uploaded README.md")
# code
if os.path.isdir(os.path.join(ROOT, "code")):
api.upload_folder(folder_path=os.path.join(ROOT, "code"), path_in_repo="code",
repo_id=REPO, repo_type="dataset", token=TOK,
allow_patterns=["*.py", "*.sh"])
print("uploaded code/")
# trained models
for s in SCENES:
mp = os.path.join(ROOT, "results", s, "model.pt")
if os.path.exists(mp):
api.upload_file(path_or_fileobj=mp, path_in_repo=f"models/{s}/model.pt",
repo_id=REPO, repo_type="dataset", token=TOK)
print("uploaded model", s)
# results (aggregated, small)
res_files = ["results/agg/aggregate.json", "results/bench.json"]
for rf in res_files:
p = os.path.join(ROOT, rf)
if os.path.exists(p):
api.upload_file(path_or_fileobj=p, path_in_repo="results/" + os.path.basename(p),
repo_id=REPO, repo_type="dataset", token=TOK)
print("uploaded", rf)
mu = os.path.join(ROOT, "results", "multiupset")
if os.path.isdir(mu):
api.upload_folder(folder_path=mu, path_in_repo="results/multiupset",
repo_id=REPO, repo_type="dataset", token=TOK, allow_patterns=["*.npz"])
print("uploaded multiupset")
for s in SCENES:
ts = os.path.join(ROOT, "results", s, "train_summary.json")
if os.path.exists(ts):
api.upload_file(path_or_fileobj=ts, path_in_repo=f"results/train_summary_{s}.json",
repo_id=REPO, repo_type="dataset", token=TOK)
# logs
if os.path.isdir(os.path.join(ROOT, "logs")):
api.upload_folder(folder_path=os.path.join(ROOT, "logs"), path_in_repo="logs",
repo_id=REPO, repo_type="dataset", token=TOK, allow_patterns=["*.log"])
gu = os.path.join(ROOT, "results", "gpu_util.log")
if os.path.exists(gu):
api.upload_file(path_or_fileobj=gu, path_in_repo="logs/gpu_util.log",
repo_id=REPO, repo_type="dataset", token=TOK)
print("uploaded logs")
# figures (after make_figs)
gen = os.path.join(ROOT, "results", "generated")
if os.path.isdir(gen):
api.upload_folder(folder_path=gen, path_in_repo="figures", repo_id=REPO,
repo_type="dataset", token=TOK)
print("uploaded figures/")
print("HF_RELEASE_DONE https://huggingface.co/datasets/" + REPO)
if __name__ == "__main__":
main()