#!/usr/bin/env python3 """Build & Publish SymbioOS Hugging Face Suite (`batistado` Namespace). Publishes three interlinked, archival Hugging Face Hub repositories: 1. Dataset : https://huggingface.co/datasets/batistado/SymbioBench-Agent 4 Dataset-Viewer configs (`phase1_multimodel_resumes`, `phase0_resumes`, `phase2_cluster_sweeps`, `policy_summaries`) + raw JSONs + vector figures. 2. Space : https://huggingface.co/spaces/batistado/SymbioOS-Explorer Always-on, zero-cold-start Static HTML5 Interactive Explorer (`sdk: static`) with Multi-Model Benchmark Inspector, Theorem 1 & 2 Interactive Tandem Simulator, and Per-Archetype Mechanism Dissection. 3. Hub Repo: https://huggingface.co/batistado/SymbioOS Rootless `symbioos` Python package, benchmark suite, IEEE TPDS LaTeX/Overleaf bundle, and figures (strictly excluding internal handoff notes). """ from __future__ import annotations import json from pathlib import Path import shutil import tempfile from typing import Any, Dict, List from huggingface_hub import HfApi REPO_ROOT = Path(__file__).resolve().parent.parent RESULTS_DIR = REPO_ROOT / "results" FIGURES_DIR = REPO_ROOT / "paper" / "figures" def _write_jsonl(path: Path, rows: List[Dict[str, Any]]) -> None: path.parent.mkdir(parents=True, exist_ok=True) with open(path, "w", encoding="utf-8") as f: for r in rows: f.write(json.dumps(r, ensure_ascii=False) + "\n") def load_all_telemetry() -> Dict[str, Any]: p0_closed = json.loads((RESULTS_DIR / "symbioos_pilot.json").read_text(encoding="utf-8")) p0_wave = json.loads((RESULTS_DIR / "symbioos_pilot_open_wave.json").read_text(encoding="utf-8")) p1_multi = json.loads((RESULTS_DIR / "phase1_multimodel_devtools.json").read_text(encoding="utf-8")) p2_sweeps = json.loads((RESULTS_DIR / "phase2_scaleout_sweeps.json").read_text(encoding="utf-8")) return { "p0_closed": p0_closed, "p0_wave": p0_wave, "p1_multi": p1_multi, "p2_sweeps": p2_sweeps, } def build_dataset_staging(stage_dir: Path, bundles: Dict[str, Any], username: str) -> None: # 1. Config 1 (default): phase1_multimodel_resumes (1,088 real pytest/clang++/git resumes) p1_rows: List[Dict[str, Any]] = [] for run in bundles["p1_multi"]["runs"]: for tr in run["turn_records"]: p1_rows.append(dict(tr)) _write_jsonl(stage_dir / "data" / "phase1_multimodel_resumes" / "train.jsonl", p1_rows) # 2. Config 2: phase0_resumes (1,080 controlled heavy-tailed resumes across closed-pool & burst-wave) p0_rows: List[Dict[str, Any]] = [] for regime_tag, src in [("closed_pool_k12", bundles["p0_closed"]), ("burst_wave_n16", bundles["p0_wave"])]: for run in src["runs"]: for tr in run["turn_records"]: row = {"regime": regime_tag, **tr} p0_rows.append(row) _write_jsonl(stage_dir / "data" / "phase0_resumes" / "train.jsonl", p0_rows) # 3. Config 3: phase2_cluster_sweeps (N=32..256 scale-out, HBM ratio, Pareto alpha, JIT delta) p2_rows: List[Dict[str, Any]] = [] for sweep_name, items in bundles["p2_sweeps"].items(): for item in items: p2_rows.append({"sweep_group": sweep_name, **item}) _write_jsonl(stage_dir / "data" / "phase2_cluster_sweeps" / "train.jsonl", p2_rows) # 4. Config 4: policy_summaries sum_rows: List[Dict[str, Any]] = [] for s in bundles["p1_multi"]["multimodel_summary"]: sum_rows.append({ "suite": "phase1_multimodel_devtools", "model_id": s["model_id"], "policy": s["policy"], "total_resumes": int(s["total_resumes"]), "ttft_p50_ms": float(s["ttft_p50_ms"]), "ttft_p95_ms": float(s["ttft_p95_ms"]), "ttft_p99_ms": float(s["ttft_p99_ms"]), "hbm_hit_rate_pct": float(s["hbm_hit_rate_pct"]), "interactive_hit_rate_pct": float(s["interactive_hit_rate_pct"]), "total_waste_mb_s_per_seed": float(s["total_waste_mb_s_per_seed"]), "episode_jct_mean_sec": float(s["episode_jct_mean_sec"]), "goodput_ep_per_min": float(s["cluster_goodput_ep_per_min"]), "slo_goodput_per_min": float(s["slo_goodput_le_600ms_per_min"]), }) for tag, src in [("phase0_closed_pool", bundles["p0_closed"]), ("phase0_burst_wave", bundles["p0_wave"])]: for s in src["summary"]: sum_rows.append({ "suite": tag, "model_id": "Qwen/Qwen2.5-3B-Instruct", "policy": s["policy"], "total_resumes": int(s["total_tool_resumes"]), "ttft_p50_ms": float(s["ttft_p50_ms"]), "ttft_p95_ms": float(s["ttft_p95_ms"]), "ttft_p99_ms": float(s["ttft_p99_ms"]), "hbm_hit_rate_pct": float(s["hbm_hit_rate_pct"]), "interactive_hit_rate_pct": float(s["interactive_hit_rate_pct"]), "total_waste_mb_s_per_seed": float(s["total_waste_mb_s_per_seed"]), "episode_jct_mean_sec": float(s["episode_jct_mean_sec"]), "goodput_ep_per_min": float(s["cluster_goodput_episodes_per_min"]), "slo_goodput_per_min": float(s["slo_goodput_resumes_le_500ms_per_min"]), }) _write_jsonl(stage_dir / "data" / "policy_summaries" / "train.jsonl", sum_rows) # Copy raw JSON results and figures raw_out = stage_dir / "raw_results" raw_out.mkdir(parents=True, exist_ok=True) for jf in RESULTS_DIR.glob("*.json"): shutil.copy2(jf, raw_out / jf.name) fig_out = stage_dir / "figures" fig_out.mkdir(parents=True, exist_ok=True) for ff in FIGURES_DIR.glob("*"): shutil.copy2(ff, fig_out / ff.name) ds_card = f"""--- license: apache-2.0 task_categories: - text-generation language: - en tags: - llm-serving - kv-cache - coding-agents - operating-systems - scheduling - gittins-index - streaming-prefill pretty_name: SymbioBench-Agent Multi-Container OS & Tiered KV Serving Telemetry size_categories: - 1K None: stage_dir.mkdir(parents=True, exist_ok=True) for ff in FIGURES_DIR.glob("*.png"): shutil.copy2(ff, stage_dir / ff.name) space_readme = f"""--- title: SymbioOS Explorer emoji: ⚡ colorFrom: blue colorTo: green sdk: static pinned: false license: apache-2.0 short_description: Interactive OS + Tiered GPU KV Tandem Explorer for SymbioOS --- # SymbioOS Interactive Explorer Interactive telemetry inspector and Theorem 1 / Theorem 2 tandem-queue simulator for [`{username}/SymbioOS`](https://huggingface.co/{username}/SymbioOS) and [`{username}/SymbioBench-Agent`](https://huggingface.co/datasets/{username}/SymbioBench-Agent). """ (stage_dir / "README.md").write_text(space_readme, encoding="utf-8") embedded_data = { "p1_multimodel": bundles["p1_multi"]["multimodel_summary"], "p1_chunks": bundles["p1_multi"]["chunk_ablation_summary"], "p0_closed": bundles["p0_closed"]["summary"], "p0_wave": bundles["p0_wave"]["summary"], "p2_hbm": bundles["p2_sweeps"]["sweep_b_hbm_ratio"], "p2_jit": bundles["p2_sweeps"]["sweep_d_jit_boundary"], } data_json = json.dumps(embedded_data) html = f""" SymbioOS — Interactive OS + GPU KV Explorer

SymbioOS: Closed-Loop Rootless POSIX Sandbox Scheduling & Streaming KV Promotion

Interactive Telemetry Explorer across 2,168 Real MPS Hardware Resumes (Qwen2.5-3B, Qwen2.5-7B, OLMoE-1B-7B) & 256-Sandbox Tandem Sweeps
4.82×
Lower Median Resume TTFT (262.6 ms vs 1265.7 ms on Qwen2.5-3B)
95.2%
Interactive pytest/lint HBM KV Hit Rate (vs 59.5% Continuum)
5.70×
Higher Strict-SLO Goodput on Sparse MoE OLMoE-1B-7B
7.98×
Faster Post-exit(0) Prefill via 1-Token BPE Lookback Streaming

1. Verified Multi-Architecture & Load-Regime Benchmark Inspector

2. Interactive HBM Capacity Frontier & Theorem 2 JIT Stopping Explorer (N = 128)

3. Publication Figures (Type-42 Vector Suite)

SymbioOS Architecture Phase 0 TTFT Decomposition Multi-Model Real DevTools Cluster Scale-Out Sweeps
""" (stage_dir / "index.html").write_text(html, encoding="utf-8") def build_hub_system_repo_staging(hub_dir: Path, username: str) -> None: hub_dir.mkdir(parents=True, exist_ok=True) # Copy clean code, tests, scripts, paper, and metadata (strictly excluding HANDOFF_CONTEXT.md!) for rel_file in ["LICENSE", "CITATION.cff", "pyproject.toml"]: shutil.copy2(REPO_ROOT / rel_file, hub_dir / rel_file) for folder in ["symbioos", "tests", "scripts"]: shutil.copytree( REPO_ROOT / folder, hub_dir / folder, ignore=shutil.ignore_patterns("__pycache__", "*.pyc", ".DS_Store"), ) shutil.copytree( REPO_ROOT / "pilot", hub_dir / "pilot", ignore=shutil.ignore_patterns("__pycache__", "*.pyc", ".DS_Store", ".devtool_scratch*", ".build_scratch*"), ) shutil.copytree( REPO_ROOT / "paper", hub_dir / "paper", ignore=shutil.ignore_patterns("*.aux", "*.bbl", "*.blg", "*.log", "*.out", ".DS_Store"), ) for png in FIGURES_DIR.glob("*.png"): shutil.copy2(png, hub_dir / png.name) hub_card = f"""--- license: apache-2.0 library_name: symbioos tags: - llm-serving - kv-cache - coding-agents - operating-systems - gittins-index - streaming-prefill - pytorch --- # SymbioOS — Closed-Loop Rootless POSIX Sandbox Scheduling & White-Box Streaming KV Promotion * **Benchmark Dataset (`2,168` Hardware Resumes + `256`-Sandbox Sweeps):** [`{username}/SymbioBench-Agent`](https://huggingface.co/datasets/{username}/SymbioBench-Agent) * **Interactive Explorer Space:** [`{username}/SymbioOS-Explorer`](https://huggingface.co/spaces/{username}/SymbioOS-Explorer) * **Source Code & Proofs:** [`github.com/batistado/symbioos`](https://github.com/batistado/symbioos) * **IEEE TPDS Overleaf / LaTeX Bundle:** [`paper/symbioos_tpds_overleaf.zip`](paper/symbioos_tpds_overleaf.zip) ## Overview Autonomous software engineering agents (`SWE-agent`, `OpenHands`) alternate between GPU token generation and host POSIX tool execution (`pytest`, `clang++`, `git`). Existing inference engines (`Continuum`, `UNISON/SPEAR`, `vLLM`) and OS schedulers (`CFS`, `AgentCgroup`) operate open-loop: CPU contention stretches interactive `pytest` containers past GPU TTL cliffs, silent socket hangs stay pinned in scarce HBM, and thousands of `stdout` tokens wait until `exit(0)` to begin prefill. ![SymbioOS Architecture](fig1_architecture_overview.png) `SymbioOS` closes this loop in **rootless user space**: 1. **Unstopped-Quantum Sub-Turn Filtration (`SubTurnRTTCFilter`):** Parses live `[XX%]` milestones and tracks silence strictly during unstopped quanta (`!is_sigstopped`), demoting stalled waits at `1.25s` without false-positive evictions on CPU-throttled imports. 2. **KV-Weighted Gittins `os.killpg` Priority (`KVWeightedGittinsScheduler`) & Theorem-2 JIT Staging (`OptimalStoppingJITController`):** Prioritizes hot-HBM interactive suites while staging evicted caches back just in time. 3. **1-Token BPE Lookback Streaming Micro-Prefill (`LookbackBPEStreamer`):** Pre-encodes `256`-token chunks of append-only `stdout` during GPU slack with exact token and logit parity (`cos_sim = 0.999997`, `7.98x` faster post-exit prefill). ![Multi-Model Results](fig3_multimodel_devtools.png) ## Quick Install ```bash pip install git+https://github.com/batistado/symbioos.git ``` ## Citation ```bibtex @article{{syed2026symbioos, title = {{{{SymbioOS}}: Closed-Loop Rootless {{POSIX}} Sandbox Scheduling and White-Box Streaming {{KV}} Promotion for Tool-Intensive Agent Clusters}}, author = {{Syed, Mohammed Kamran and Rentala, Anudeep and Rahul, Somesh and Pai, Raghuram Malpe and Dara, Krishna Suman}}, journal = {{IEEE Transactions on Parallel and Distributed Systems (TPDS)}}, year = {{2026}}, url = {{https://github.com/batistado/symbioos}} }} ``` """ (hub_dir / "README.md").write_text(hub_card, encoding="utf-8") def main() -> int: api = HfApi() username = api.whoami()["name"] ds_repo_id = f"{username}/SymbioBench-Agent" space_repo_id = f"{username}/SymbioOS-Explorer" hub_repo_id = f"{username}/SymbioOS" bundles = load_all_telemetry() with tempfile.TemporaryDirectory(prefix="symbioos_hf_") as tmp: tmp_path = Path(tmp) ds_dir = tmp_path / "dataset" sp_dir = tmp_path / "space" hb_dir = tmp_path / "hub" build_dataset_staging(ds_dir, bundles, username=username) api.create_repo(repo_id=ds_repo_id, repo_type="dataset", private=False, exist_ok=True) api.upload_folder( repo_id=ds_repo_id, repo_type="dataset", folder_path=str(ds_dir), commit_message="Publish SymbioBench-Agent v1.0 multi-architecture & cluster-scale telemetry", ) print(f"[1/3 SUCCESS] Dataset -> https://huggingface.co/datasets/{ds_repo_id}", flush=True) build_static_space_staging(sp_dir, bundles, username=username) api.create_repo( repo_id=space_repo_id, repo_type="space", space_sdk="static", private=False, exist_ok=True, ) api.upload_folder( repo_id=space_repo_id, repo_type="space", folder_path=str(sp_dir), commit_message="Publish interactive SymbioOS & SymbioBench-Agent Static Explorer", ) print(f"[2/3 SUCCESS] Space -> https://huggingface.co/spaces/{space_repo_id}", flush=True) build_hub_system_repo_staging(hb_dir, username=username) api.create_repo(repo_id=hub_repo_id, repo_type="model", private=False, exist_ok=True) api.upload_folder( repo_id=hub_repo_id, repo_type="model", folder_path=str(hb_dir), commit_message="Publish SymbioOS v1.0 runtime, benchmarks, and IEEE TPDS manuscript bundle", ) print(f"[3/3 SUCCESS] Hub -> https://huggingface.co/{hub_repo_id}", flush=True) return 0 if __name__ == "__main__": raise SystemExit(main())