"""Build the post-FC2 authoritative GB10 baseline and profile summary.""" from __future__ import annotations import argparse import json from pathlib import Path def load(path: Path) -> dict: return json.loads(path.read_text(encoding="utf-8")) def delta(current: float, previous: float) -> dict: return { "previous": previous, "current": current, "absolute_change": current - previous, "percent_change": (current / previous - 1.0) * 100.0, } def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) parser.add_argument("--output", type=Path, required=True) args = parser.parse_args() benchmarks = args.root / "benchmarks" resident = load(benchmarks / "gb10-post-fc2-resident-baseline-20260826.json") block = load(benchmarks / "gb10-post-fc2-block24-profile-20260826.json") nsys = load(benchmarks / "gb10-post-fc2-warmed-step-nsys-summary-20260826.json") ncu = load(benchmarks / "gb10-post-fc2-block24-targeted-summary-20260826.json") previous = load(benchmarks / "gb10-fully-fused-fresh-nsight-summary.json") current_components = nsys["components"] previous_components = previous["one_warmed_sampling_step"]["components"] component_comparison = { name: delta( current_components[name]["milliseconds"], previous_components[name]["milliseconds"], ) for name in current_components } ranking = sorted( ( { "component": name, "milliseconds": values["milliseconds"], "percent_of_kernel_time": values["percent_of_kernel_time"], } for name, values in current_components.items() ), key=lambda row: row["milliseconds"], reverse=True, ) previous_step = previous["one_warmed_sampling_step"] report = { "name": "gb10-post-fc2-production-profile", "measurement_date": "2026-08-26", "source_commit": resident["source_commit"], "measurement_overlay": ( "the measurement image included deferred step events and latent hashes plus an opt-in " "100-token synthetic-text request; the final production overlay gates diagnostics to " "that benchmark request, and model math is unchanged" ), "image": resident["image"], "device": "NVIDIA GB10", "compute_capability": "SM121", "tools": { "torch": "2.9.1+cu130", "cuda": "13.0", "nsight_systems": "2025.3.2.474-253236389321v0", "nsight_compute": "2025.3.1", }, "workload": { "resolution": [1344, 768], "frames": 124, "packed_tokens": 37810, "text_tokens": 100, "steps": 12, "seed": 440420, "attention": "sage2", }, "configuration": { "H3_NVFP4_SCALE_BACKEND": "vortex", "H3_NVFP4_SCALE_VERSION": "1", "H3_FUSED_ELEMENTWISE": "1", "H3_NVFP4_MODULATE_FUSION": "1", "H3_NVFP4_SWIGLU_FUSION": "1", "H3_NVFP4_FC2_LT_SPLITK1": "1", "H3_SAGE_QKV_LAYOUT": "strided_nhd", }, "authoritative_resident_baseline": { "sampling_seconds": resident["sampling_seconds"], "median_sampling_seconds": resident["median_sampling_seconds"], "per_step_seconds": resident["sampling_steps"], "peak_allocated_bytes": resident["sampling_peak_allocated_bytes"], "peak_reserved_bytes": resident["sampling_peak_reserved_bytes"], "latent_checksums": resident["latent_checksums"], "fc2_dispatch": resident["fc2_dispatch"], "measurement_policy": resident["measurement_policy"], }, "block_24": { "uninstrumented_module_p50_ms": block["module_forward"]["p50_s"] * 1000.0, "uninstrumented_module_samples": block["module_forward"]["count"], "synchronized_decomposition_is_attribution_only": True, "fc2_schedule_note": ( "profile_h3_block.py decomposes generic NVFP4 linear calls and bypasses " "forward_swiglu/guarded FC2; use resident NSYS and targeted NCU for production FC2" ), }, "one_warmed_sampling_step_nsys": { "elapsed_seconds": load( benchmarks / "gb10-post-fc2-warmed-step-capture-20260826.json" )["elapsed_seconds"], "gpu_span_seconds": nsys["gpu_span_ns"] / 1.0e9, "kernel_time_seconds": nsys["kernel_time_ns"] / 1.0e9, "gpu_operation_count": nsys["gpu_operation_count"], "kernel_count": nsys["kernel_count"], "kernel_busy_percent_of_span": nsys["kernel_busy_percent_of_span"], "launch_gaps": nsys["launch_gaps"], "cpu_gpu_overlap": nsys["cpu_gpu_overlap"], "components": current_components, }, "block_24_targeted_ncu": ncu, "comparison_to_pre_fc2_profile": { "previous_summary": "benchmarks/gb10-fully-fused-fresh-nsight-summary.json", "block_24_p50_ms": delta( block["module_forward"]["p50_s"] * 1000.0, previous["block_24"]["uninstrumented_module_p50_ms"], ), "block_24_comparison_note": ( "same-script decomposition control only; it excludes guarded FC2 and must not " "be interpreted as the production FC2 gain" ), "warmed_step_gpu_span_seconds": delta( nsys["gpu_span_ns"] / 1.0e9, previous_step["gpu_span_seconds"], ), "warmed_step_kernel_time_seconds": delta( nsys["kernel_time_ns"] / 1.0e9, previous_step["kernel_time_seconds"], ), "warmed_step_kernel_count": delta( nsys["kernel_count"], previous_step["kernel_launches"], ), "components": component_comparison, }, "bottleneck_ranking": ranking, "decision": { "authoritative_exact_baseline": ( f"{resident['median_sampling_seconds']:.6f} s median resident sampling" ), "time_bottleneck": ( "Sage2 remains dominant at 62.36% of warmed-step kernel time; its mainloop " "is 241.91 ms average in NSYS and 259.00 ms in the NCU replay." ), "secondary_bottlenecks": ( "NVFP4 GEMMs are 19.95%, packing 9.70%, norm/RoPE 5.19%, and gate/add 2.63%." ), "next_optimization": ( "None started. Sage2 is the next-ranked investigation target; any implementation " "requires a separate approved experiment after this baseline is accepted." ), }, "artifacts": [ "benchmarks/gb10-post-fc2-resident-baseline-20260826.json", "benchmarks/gb10-post-fc2-block24-profile-20260826.json", "benchmarks/gb10-post-fc2-warmed-step-capture-20260826.json", "benchmarks/gb10-post-fc2-warmed-step-20260826.nsys-rep", "benchmarks/gb10-post-fc2-warmed-step-20260826.sqlite", "benchmarks/gb10-post-fc2-warmed-step-stats_cuda_gpu_trace.csv", "benchmarks/gb10-post-fc2-warmed-step-stats_cuda_kern_exec_trace.csv", "benchmarks/gb10-post-fc2-warmed-step-stats_nvtx_gpu_proj_trace.csv", "benchmarks/gb10-post-fc2-warmed-step-stats_cuda_gpu_kern_sum.csv", "benchmarks/gb10-post-fc2-warmed-step-stats_cuda_api_sum.csv", "benchmarks/gb10-post-fc2-block24-targeted-capture-20260826.json", "benchmarks/gb10-post-fc2-block24-targeted-20260826.ncu-rep", "benchmarks/gb10-post-fc2-block24-targeted-20260826.csv", "benchmarks/gb10-post-fc2-block24-targeted-traffic-capture-20260826.json", "benchmarks/gb10-post-fc2-block24-targeted-traffic-20260826.ncu-rep", "benchmarks/gb10-post-fc2-block24-targeted-traffic-20260826.csv", "benchmarks/gb10-post-fc2-warmed-step-nsys-summary-20260826.json", "benchmarks/gb10-post-fc2-block24-targeted-summary-20260826.json", ], } args.output.parent.mkdir(parents=True, exist_ok=True) args.output.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") print(json.dumps(report, indent=2)) if __name__ == "__main__": main()