Download native-eiffel/test_render_graph.py from peih/matrix-shooter-train: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/peih/matrix-shooter-train/resolve/main/native-eiffel/test_render_graph.py
- Command line
-
hf download hf://peih/matrix-shooter-train/native-eiffel/test_render_graph.py
-
curl -L -o test_render_graph.py https://huggingface.co/peih/matrix-shooter-train/resolve/main/native-eiffel/test_render_graph.py
1.73 kB
| """CUDA-graph rendering must equal eager rendering bit for bit; and how long a frame takes.""" | |
| import json, statistics, time | |
| import torch | |
| from engine_client import Engine | |
| from native_render import NativeRenderer | |
| engine = Engine() | |
| frames = [] | |
| for i in range(400): | |
| ev = [{'action': 'enter', 'phase': 'down'}, {'action': 'enter', 'phase': 'up'}] if i == 5 else [] | |
| if 40 <= i < 380 and i % 24 == 0: | |
| ev.append({'action': 'w', 'phase': 'down' if (i // 24) % 2 == 0 else 'up'}) | |
| if 60 <= i < 380 and i % 37 == 0: | |
| ev += [{'action': 'j', 'phase': 'down'}, {'action': 'j', 'phase': 'up'}] | |
| header, scene = engine.advance(round((i + 1) * 2.5), ev, capture=i % 4 == 0, state=False) | |
| if i % 4 == 0: | |
| frames.append({k: v.copy() for k, v in scene.items()}) | |
| engine.close() | |
| eager = NativeRenderer(engine.scene, engine.scene_arrays, graphs=False) | |
| graph = NativeRenderer(engine.scene, engine.scene_arrays, graphs=True) | |
| same = sum(int(torch.equal(eager.render(f), graph.render(f))) for f in frames[10:]) | |
| rows = {} | |
| for name, r in (('eager', eager), ('graphs', graph)): | |
| cpu, gpu = [], [] | |
| for f in frames[10:]: | |
| torch.cuda.synchronize() | |
| s, e = torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True) | |
| t = time.perf_counter(); s.record(); r.render(f); e.record(); submit = time.perf_counter() - t | |
| e.synchronize(); cpu.append(submit * 1e3); gpu.append(s.elapsed_time(e)) | |
| rows[name] = dict(submit_ms=round(statistics.median(cpu), 3), ready_ms=round(statistics.median(gpu), 3), | |
| ready_p95_ms=round(sorted(gpu)[int(len(gpu) * .95)], 3)) | |
| print(json.dumps(dict(frames=len(frames) - 10, identical=f'{same}/{len(frames) - 10}', **rows))) | |