"""Minimal repro for ray#60904: nsys report missing when GPU actor is profiled. A/B on process_group_cleanup_enabled. Driver stays alive; actor exits explicitly. """ import argparse, glob, os, subprocess, sys, time import ray def main(): ap = argparse.ArgumentParser() ap.add_argument("--group-cleanup", choices=("on", "off"), default="on") ap.add_argument("--teardown", choices=("wait", "immediate"), default="wait") args = ap.parse_args() cfg = {} if args.group_cleanup == "on" else {"process_group_cleanup_enabled": False} ctx = ray.init(address="local", num_gpus=1, include_dashboard=False, _system_config=cfg, logging_level="ERROR") session = ctx.address_info["session_dir"] nsight = {"t": "cuda,nvtx", "sample": "none", "cpuctxsw": "none", "stop-on-exit": "true"} @ray.remote(num_gpus=1, runtime_env={"nsight": nsight}, max_restarts=0) class GpuActor: def work(self): import torch x = torch.randn(2048, 2048, device="cuda") for _ in range(30): x = x @ x torch.cuda.synchronize() return os.getpid() def stop(self): ray.actor.exit_actor() a = GpuActor.remote() wpid = ray.get(a.work.remote()) # process tree snapshot while alive tree = subprocess.run(["ps", "-o", "pid,ppid,pgid,stat,args", "-p", str(wpid)], capture_output=True, text=True).stdout print(f"[{args.group_cleanup}] worker python PID={wpid}") print(tree.strip()) if args.teardown == "immediate": # Mirror workload's ds.materialize() -> ray.shutdown() with no wait. del a ray.shutdown() reps = glob.glob(f"{session}/logs/nsight/*.nsys-rep") ok = reps and os.path.getsize(reps[0]) > 0 print(f"[{args.group_cleanup}/immediate] RESULT: {'REP OK' if ok else 'NO REP'}") return try: ray.get(a.stop.remote()) except Exception: pass # driver stays alive; poll for the rep for up to 20s reps = [] for _ in range(20): time.sleep(1) reps = glob.glob(f"{session}/logs/nsight/*.nsys-rep") if reps and os.path.getsize(reps[0]) > 0: break if reps and os.path.getsize(reps[0]) > 0: print(f"[{args.group_cleanup}] RESULT: REP OK ({os.path.getsize(reps[0])//1024} KB)") else: print(f"[{args.group_cleanup}] RESULT: NO REP (nsight dir: {glob.glob(session+'/logs/nsight/*')})") ray.shutdown() if __name__ == "__main__": main()