rank_compare.py 1.1 KB

1234567891011121314151617
  1. #!/usr/bin/env python3
  2. """Per-rank kernel time by category for one profile (traces gathered into DIR/rankN/)."""
  3. import collections, glob, gzip, json, re, sys
  4. d, steps = sys.argv[1], int(sys.argv[2])
  5. cats = [("roce", r"roce|Roce"), ("nccl", r"nccl"), ("moe", r"marlin|Marlin|GroupProblemShape"), ("bf16", r"wmma|nvjet|gemv|splitK"),
  6. ("fp8", r"w8a8|fp8"), ("attn", r"_fwd_kernel|attn|flash")]
  7. print("%-6s" % "rank" + "".join("%9s" % c for c, _ in cats) + "%9s%9s" % ("other", "busy"))
  8. for rd in sorted(glob.glob(d + "/rank*")):
  9. f = sorted(glob.glob(rd + "/*.gz"))[-1]
  10. ev = [e for e in json.load(gzip.open(f))["traceEvents"] if e.get("ph") == "X" and e.get("cat") == "kernel"]
  11. t = collections.defaultdict(float)
  12. for e in ev:
  13. for c, rx in cats:
  14. if re.search(rx, e["name"]): t[c] += e["dur"]; break
  15. else: t["other"] += e["dur"]
  16. tot = sum(t.values())
  17. print("%-6s" % rd.rsplit("/", 1)[1] + "".join("%9.2f" % (t[c] / 1e3 / steps) for c, _ in cats) + "%9.2f%9.2f" % (t["other"] / 1e3 / steps, (tot - t["roce"] - t["nccl"]) / 1e3 / steps))