跳到正文
DEV Community· InferenceKey·· 2 小時前AI 評分62

在 24 GB GPU 上部署 RelayVSR:模型運算約需 10 秒,MP4 編碼耗去其餘時間

Serving RelayVSR on a 24 GB GPU: the model took 10 seconds, the MP4 encode took the rest

AI 導讀

作者在單張 24 GB RTX 4090 上測試 RelayVSR,3 秒 480p 影片約需 10 秒 GPU 運算,但客戶端單次請求耗時 26 至 41 秒,主要差距來自 MP4 編碼。

正文

With RelayVSR on one RTX 4090, GPU time was the easy part. Three seconds of 480p film came back at 3416 x 1920, four times wider and taller, after roughly 10 seconds of GPU work. From the client's side, each call lasted 26 to 41 seconds. The difference was the processor packing frames into an MP4.

Below: one flag, one memory lever, one warm-up habit and one transport trap. Numbers and setup are in our RelayVSR test on one 24 GB card.

Two models, and why that shapes everything

RelayVSR comes from Xijun Wang, Xin Li, Zirui Lang, Suhang Yao, Haoran Li and Zhibo Chen at the University of Science and Technology of China. They published the paper, the code and Apache-2.0 weights.

Inside, two models share the job. The expensive one, 5 billion parameters adapted from Wan-AI's open Wan2.2 video model, only paints keyframes: a handful of frames redrawn in full detail. The cheap one, a 32-million-parameter network the authors designed, touches every frame. It reads the low-resolution input plus the keyframe before and after, and fills in the rest. Our 72-frame clip got 6 keyframes from the big model and 72 frames from the small one.

The flag that is off by one

The authors' --window-size defaults to 16, and they describe it as "Reference interval + 1". Both endpoints of a window are keyframes, so 16 gives you a gap of 15 frames and 32 gives you a gap of 31.

{"video_b64": "<base64 MP4>", "window_size": 16, "max_frames": 72, "seed": 42}

On the 4090, going from 16 to 32 took the 480p clip from 7.33 to 9.10 frames per second, about 10 seconds of GPU time down to 8. Motion pays for it. At frame 47, mid head turn, window 16 had a keyframe 2 frames back and the face stayed sharp. Window 32 had the nearest one 15 frames away, and the face went soft. Frame 38, 7 frames from a keyframe under either setting, looked the same in both. One clip, so treat the rule (default for faces and fast motion, 32 for slow scenes) as a starting guess.

Frame 47 of a Tears of Steel clip upscaled from 854 x 480 to 3416 x 1920 on an RTX 4090: sharp face with a keyframe every 15 frames on the left, softer face with a keyframe every 31 frames on the right

Memory: the only lever is the input size

Some model code can park layers in system RAM on a small card, slower but working. RelayVSR's code cannot, so the only way to save memory is smaller input frames.

At 480p in, peak memory was 20.4 GiB, so a 24 GB card is the floor, as the memory ladder in our RelayVSR benchmark shows rung by rung. For smaller budgets, the backend capped the 4090 with torch.cuda.set_per_process_memory_fraction. Under a 15.2 GiB cap (standing in for a 16 GB card), 480p and 360p input ran out of memory. A 270p input with 1080p output fit, and the file was byte-identical to the uncapped run. Under 11.2 GiB nothing fit: the generator weights alone take 9.62 GiB.

Caveats: the cap only limits what PyTorch may allocate, while a physical 16 GB card also loses memory to the driver. And 1440p peaked at 15.5 GiB, above our cap but below 16 GB, so a real 16 GB card is an open question.

Warm up at the size you serve

The first time the model sees a new frame size, Triton and FlexAttention compile kernels for it: small GPU programs tuned to that exact shape. The first (cold) call is slow; warm calls reuse the compiled code. On the 4090 the first 1920p call ran at 4.71 frames per second against 7.33 warm, and the first 1080p call at 8.88 against 23.85. If you accept several resolutions, warm each one at startup, or your first caller pays for the compile, and log cold and warm calls apart.

The trap: the answer is a video

One 1920p request, step by step: 2.1 seconds decoding, 15.0 seconds in the streaming loop (the pass that runs both models frame by frame; 9.8 of those seconds were GPU, the rest CPU H.264 encoding), then 22.0 seconds re-encoding. The second pass happened because the backend returns the video as base64 inside a single 8 MB message, and the first encode at CRF 18 (the encoder's quality setting) came out too large. It retried at CRF 22 and the clip came back at about 4.9 MB.

Drop the output to 1080p and one encode is enough: request to response took 6.4 to 7.2 seconds. Handing back a link to a stored file instead of the bytes would skip the retry. That is still open; meanwhile the example's README suggests splitting long footage into pieces of 2 to 3 seconds.

What to log per request:

  • model time and frames per second
  • encode time and how many encode passes it took
  • peak GPU memory
  • whether this frame size was the first one seen

What it does not prove

Quality was judged by eye, on one clip, against bicubic only. RelayVSR invents detail that looks right instead of recovering what the camera saw, so verify it where accuracy counts. We fed it a pristine film shrunk on purpose, which says nothing about old or damaged footage. All timings come from a single request on a card doing nothing else. The output has no audio track.

Credit where it is due: the RelayVSR authors, Wan-AI for Wan2.2, the FlashVSR project at OpenImagingLab, a baseline the authors acknowledge, Hugging Face Diffusers, the Blender Foundation for Tears of Steel (CC BY 3.0), and the AI Search channel, where we first saw the model. Our part was the serving backend, the timings and the memory tests.

Timing tables, backend settings and the SDK example for your own card are in the complete RelayVSR write-up on inferencekey.com.

來源:DEV Community · dev.to