Download scripts/tile_test.py from WeReCooking/DFlow2-4step-ONNX-WebGPU: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/WeReCooking/DFlow2-4step-ONNX-WebGPU/resolve/main/scripts/tile_test.py
- Command line
-
hf download hf://WeReCooking/DFlow2-4step-ONNX-WebGPU/scripts/tile_test.py
-
curl -L -o tile_test.py https://huggingface.co/WeReCooking/DFlow2-4step-ONNX-WebGPU/resolve/main/scripts/tile_test.py
1.37 kB
| import sys, numpy as np, onnxruntime as ort, ropes | |
| R = "/tmp/claude-0/-home-user-HF-empty/1caca391-99c3-5a94-acbe-98cceb297ce3/scratchpad/onnx_A2" | |
| so = ort.SessionOptions(); so.intra_op_num_threads = 2 | |
| trunk = ort.InferenceSession(f"{R}/vae_trunk/vae_trunk.onnx", so) | |
| head = ort.InferenceSession(f"{R}/vae_head/vae_head.onnx", so) | |
| full = ort.InferenceSession(f"{R}/vae_dec/vae_dec.onnx", so) | |
| x = np.load(sys.argv[1])["latent"].astype(np.float32) | |
| _, _, h, w = x.shape | |
| vs, vc = ropes.vae_tables(h, w) | |
| feats = trunk.run(None, {"z": x, "v_sin": vs, "v_cos": vc})[0] | |
| ref = full.run(None, {"z": x, "v_sin": vs, "v_cos": vc})[0] | |
| whole = head.run(None, {"feats": feats})[0] | |
| print("trunk+head vs single graph: max abs", float(np.abs(whole - ref).max())) | |
| core, halo = int(sys.argv[2]), int(sys.argv[3]) | |
| out = np.zeros_like(whole) | |
| for y0 in range(0, h, core): | |
| for x0 in range(0, w, core): | |
| y1, x1 = min(h, y0 + core), min(w, x0 + core) | |
| ya, xa, yb, xb = max(0, y0 - halo), max(0, x0 - halo), min(h, y1 + halo), min(w, x1 + halo) | |
| t = head.run(None, {"feats": np.ascontiguousarray(feats[:, :, ya:yb, xa:xb])})[0] | |
| out[:, :, y0 * 16:y1 * 16, x0 * 16:x1 * 16] = t[:, :, (y0 - ya) * 16:(y1 - ya) * 16, (x0 - xa) * 16:(x1 - xa) * 16] | |
| d = np.abs(out - whole) | |
| print(f"tiled core={core} halo={halo} vs whole: max abs {d.max():.2e}, mean {d.mean():.2e}") | |