MCPcopy Create free account
hub / github.com/FlashSampling/FlashSampling / nsys_test

Function nsys_test

src/fused_mm_sampling/modal_lib/modal_nsys_test.py:16–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15@app.function(gpu="B200", image=nsys_image, volumes=make_volumes())
16def nsys_test():
17 os.makedirs(REPORT_DIR, exist_ok=True)
18
19 script = """
20import torch
21
22a = torch.randn(1024, 1024, device="cuda", dtype=torch.bfloat16)
23b = torch.randn(1024, 1024, device="cuda", dtype=torch.bfloat16)
24torch.cuda.synchronize()
25c = a + b
26torch.cuda.synchronize()
27"""
28 with open("/tmp/nsys_kernel.py", "w") as f:
29 f.write(script)
30
31 result = subprocess.run(
32 [
33 "nsys",
34 "profile",
35 "-o",
36 REPORT_PATH,
37 "--force-overwrite=true",
38 "python",
39 "/tmp/nsys_kernel.py",
40 ],
41 capture_output=True,
42 text=True,
43 )
44 print("=== stdout ===")
45 print(result.stdout[-3000:] if len(result.stdout) > 3000 else result.stdout)
46 print("=== stderr ===")
47 print(result.stderr[-3000:] if len(result.stderr) > 3000 else result.stderr)
48 print(f"=== returncode: {result.returncode} ===")
49
50 report_file = f"{REPORT_PATH}.nsys-rep"
51 if os.path.exists(report_file):
52 size_mb = os.path.getsize(report_file) / (1024 * 1024)
53 print(f"Report saved: {report_file} ({size_mb:.1f} MB)")
54 from modal import Volume
55
56 Volume.from_name("fused-mm-sample").commit()
57 else:
58 print(f"Report file not found at {report_file}")
59
60
61@app.local_entrypoint()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected