#!/usr/bin/env python3 """Persistent resident QNN worker for Fast-WAM (one NPU session per process). Loads the `action_step` HTP context ONCE, stays alive, serves inference over a TCP socket (no per-inference reload). Fast-WAM's on-device unit here is the MoT **action expert** denoise step — it cross-attends to the video KV cache produced by the video world-model DiT (`video_prefill`), which runs host-side for now (see README). role: action_step : one flow-matching denoise step of the action expert. inputs : latents_action [1,32,7], timestep [1], video_keys [30,1,98,3072], video_values [30,1,98,3072], context [1,129,4096], context_mask [1,129] output : pred_noise [1,32,7] (host applies the Euler/flow-match update) Usage: resident_worker.py """ import sys, os, socket, struct, time import numpy as np WS = os.environ.get("FASTWAM_WS", "/root/fastwam_workspace") def recvall(s, n): b = bytearray() while len(b) < n: c = s.recv(min(n - len(b), 8 << 20)) if not c: raise ConnectionError() b += c return bytes(b) def recv_tensors(s): n = struct.unpack("libs teardown double-free (see README device gotchas) if __name__ == "__main__": main()