RAFT
RAFT (Teed and Deng, Princeton) with torchvision's weights: dense optical flow refined step by step over an all-pairs correlation volume. BSD-3-Clause code; some training sets (FlyingChairs, Sintel) are research-only.
stable Fork of pytorch/vision@1f1a920 · backends: portable, kernels
- Paper RAFT: Recurrent All-Pairs Field Transforms for Optical Flow ECCV 2020 · first released 26 Mar 2020
- Authors’ code princeton-vl/RAFT (PyTorch), not the code forked here: torchvision's port ships newer V2 weights trained from scratch, which are the ones used.
Paper 2020 Added in 0.2.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install fastforks-core
from fastforks import flow
model = flow.load("raft-large") # kernels on a supported GPU, else portable PyTorch
result = model(frame1, frame2)
result.flow
result.backend # what ran: mode, device, dtype, kernels fastforks bench raft-large Times the model on this machine. load(…, mode="portable") or mode="kernels" picks a backend; usage guide.
Speed and memory
Every backend on one GPU (RTX 5060 Ti 16 GB) and the same input, the authors’ code included. Kernels runs fp16. Portable runs fp16 on CUDA.
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the call | fp32 | 480 | – | 13.2 GiB/13.5 GiB | 1.1 | 0.84 |
| Original fp16torch.autocast(fp16) around the call; torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the call | fp16 | 567 | 0.85× | 7,164 MiB/10.7 GiB | 0.1 | 0.76 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 291 | 1.6× | 5,930 MiB/6,058 MiB | 0.2 | 0.30 |
| Kernels | fp16 | 83.4 | 5.7× | 332 MiB/352 MiB | 0.3 | 0.08 |
| Portable + torch.compile | 195 | 2.5× | 5,886 MiB/5,924 MiB | 41 (build) | – | |
| TensorRTTensorRT engine build failed | fails | – | – | – | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-10 to 2026-11-16. First call, 3 warm-up, peak reset, median of 3 rounds x median of 5. Ratios divide two
times of this table (same GPU, same input). Original fp16 is the authors’ own precision option, else torch.autocast. torch.compile and TensorRT: build time instead of load time. TensorRT memory (engine, not comparable) is the GPU memory the engine took, read from the driver because TensorRT allocates outside PyTorch, so it can't be compared with the PyTorch peaks of the other rows.
Other devices
| Device | Backend | dtype | ms / call | Peak memory | Output vs reference | Input |
|---|---|---|---|---|---|---|
| Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14 | Original | fp32 | out of memory | – | 1080x1920 | |
| Portable | fp16 | 2710 | 11.4 GiB process | matches | 1080x1920 | |
| Portable | fp32 | 2522 | 12.6 GiB process | matches | 1080x1920 | |
| Kernels | fp16 | 1351 | 3,647 MiB process | matches | 1080x1920 | |
CUDA memory is torch’s peak allocated / reserved; Apple has no such counter, so the Mac rows show the process footprint (weights, Python and torch included). “Output vs reference” compares the device’s output with the stored golden output under the card’s tolerance; – = not checked on that device. Kernels “not implemented” = no kernels for this model on that backend yet: it runs portable there.
Licence and weights
Commercial use allowed
- Code
- BSD-3-Clause LICENSE
- Weights
- BSD-3-Clause (assumed from code)(not stated by the authors; assumed to follow the code) source
- Training data
-
- FlyingChairs (Freiburg) research-only, non-commercial
- Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa) research-only, non-commercial
- MPI Sintel optical flow noncommercial, non-commercial
- KITTI stereo / optical flow 2012 / 2015 CC-BY-NC-SA-3.0, non-commercial
- HCI HD1K optical flow benchmark not stated
- weights licence not stated by the original authors; assumed to be the code licence
Our reading of the licences, not legal advice.
Weights
raft_large_C_T_SKHT_V2-ff5fadd5.pth 21.1 MB· hosted on PyTorchfastforks downloads and checks these files on first use (fastforks download raft-large).
Accuracy
The test set through the authors’ code and through ours: same checkpoint, same protocol. The distance between the original’s fp32 and fp16 runs is what half precision alone costs; our runs should stay within it.
KITTI 2015 train
EPE / Fl-all %trained on this dataset’s public images: not zero-shot
| Run | dtype | EPE ↓ | Fl-all % ↓ | Δ EPE vs fp32 original | pairs | ms / pair |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 1.528 | 5.60 | reference | 200 | 86.2 |
| Original fp16 | fp16 | 1.528 | 5.60 | −0.001 | 200 | 66.0 |
| Portable fp32 | fp32 | 1.528 | 5.60 | ±0.000 | 200 | 74.2 |
| Portable | fp16 | 1.529 | 5.61 | −0.001 | 200 | 46.4 |
| Kernels | fp16 | 1.526 | 5.60 | +0.001 | 200 | 21.7 |
Frames _10 -> _11 at full size against the flow_occ ground truth; EPE = mean of the per-pair mean end-point error, Fl-all = share of all valid pixels with an error > 3 px and > 5 % of the GT magnitude. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-11; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1, 2026-11-17; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks f2992269+unc, 2026-11-09.
Closeness to the original
Beyond the test-set scores: the raw output of ours against the original’s fp32 output on the same input, pixel by pixel. CPU, float32: max |diff| <= 0.00012 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0019 and p99 <= 0.0091 (absolute error of the output flow).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.00012 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.0019 | 0.00098 |
| GPU default dtypes, p99 |diff| | ≤ 0.0091 | 0.00459 |
Recorded for raft-large on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-12, with these kernels: cudnn_hacccutlass_convraft_flow
Details
RAFT (Teed & Deng 2020): all-pairs correlation pyramid at 1/8 resolution and a ConvGRU that refines the flow in 12 iterations, upsampled with a learned convex mask (raft-small: bilinear). torchvision's V2 weights (trained from scratch with its optical-flow reference recipe); the network is ported from torchvision (no torchvision dependency).
- Input / output
- Input: two RGB images (consecutive frames). Output: per-pixel motion from the first to the second (dx, dy in pixels).
- Input size
- any H x W >= 128, padded to a multiple of 8; tested up to 1024x2048 (8,452 MiB allocated)
- Options
iters=12>= 1· changes the output
- Outputs
flow- CUDA kernels
raft_flowRAFT optical flow kernelscutlass_convCUTLASS convolutions with the recurrent update (GRU) fused incudnn_haccconvolutions with fp16 accumulation (cuDNN)
- Apple (MPS)
flow_metalMetal: RAFT correlation lookup without a volume. fp32, fp16
Full reference, generated from the repository
RAFT (Teed and Deng, Princeton) with torchvision's weights: dense optical flow refined step by step over an all-pairs correlation volume. BSD-3-Clause code; some training sets (FlyingChairs, Sintel) are research-only.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
raft-large | synthetic (1080x1920) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 480 567 291 83.4 195 fails: TensorRT engine build failed | 13489 / 13798 7164 / 10928 5930 / 6058 332 / 352 5886 / 5924 – |
raft-large-things | synthetic (1080x1920) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 481 566 291 83.5 195 fails: TensorRT engine build failed | 13489 / 13798 7164 / 10928 5930 / 6058 332 / 352 5886 / 5924 – |
raft-large-kitti | synthetic (1080x1920) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 480 567 291 84.2 195 fails: TensorRT engine build failed | 13489 / 13818 7164 / 10928 5930 / 6058 332 / 352 5886 / 5924 – |
raft-small | synthetic (1080x1920) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 196 395 144 36.5 110 fails: unsupported: engine build needs more than the 16 GB of this | 13441 / 13686 7032 / 10888 5669 / 5706 196 / 204 5704 / 5728 – |
Details
- Original code: https://github.com/pytorch/vision at
1f1a920d685d - Code licence: BSD-3-Clause (permissive); files:
LICENSE - Weights licence: BSD-3-Clause (assumed from code)
- Licence evidence: https://github.com/pytorch/vision/blob/1f1a920d685d46dfbe187934b785b7ecb7a182f2/torchvision/models/optical_flow/raft.py#L576
- Training data: FlyingChairs (Freiburg), Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa) (FlyingChairs, then FlyingThings3D (part of SceneFlow))
raft-large: FlyingChairs (Freiburg), Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa), MPI Sintel optical flow, KITTI stereo / optical flow 2012 / 2015, HCI HD1K optical flow benchmark (FlyingChairs, FlyingThings3D, then fine-tuned on a mix of Sintel, KITTI 2015, HD1K and FlyingThings3D (clean pass))raft-large-kitti: FlyingChairs (Freiburg), Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa), MPI Sintel optical flow, KITTI stereo / optical flow 2012 / 2015, HCI HD1K optical flow benchmark (as raft-large, then fine-tuned on KITTI 2015)
- Options:
iters= 12 (>= 1) - Kernel libraries:
raft_flow,cutlass_conv,cudnn_hacc - Variants:
raft-large,raft-large-things,raft-large-kitti,raft-small - Outputs: flow
- Input size: any H x W >= 128, padded to a multiple of 8
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
raft-large1024x2048 (8.3 GiB peak allocated, 9.0 reserved);raft-large-things1024x2048 (8.3 GiB peak allocated, 9.0 reserved);raft-large-kitti1024x2048 (8.3 GiB peak allocated, 9.0 reserved);raft-small1024x2048 (8.2 GiB peak allocated, 8.7 reserved) raft-large1080x1920, first call: portable + torch.compile 41 s (cold Inductor cache).raft-large-things1080x1920, first call: portable + torch.compile 39 s (cold Inductor cache).raft-large-kitti1080x1920, first call: portable + torch.compile 39 s (cold Inductor cache).raft-small1080x1920, first call: portable + torch.compile 37 s (cold Inductor cache).raft-largeoriginal (fp32) 1080x1920: torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the callraft-largeoriginal 1080x1920: torch.autocast(fp16) around the call; torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the callraft-large-thingsoriginal (fp32) 1080x1920: torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the callraft-large-thingsoriginal 1080x1920: torch.autocast(fp16) around the call; torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the callraft-large-kittioriginal (fp32) 1080x1920: torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the callraft-large-kittioriginal 1080x1920: torch.autocast(fp16) around the call; torchvision 0.29.1+cu130 raft_large, num_flow_updates=12, [-1, 1] conversion in the callraft-smalloriginal (fp32) 1080x1920: torchvision 0.29.1+cu130 raft_small, num_flow_updates=12, [-1, 1] conversion in the callraft-smalloriginal 1080x1920: torch.autocast(fp16) around the call; torchvision 0.29.1+cu130 raft_small, num_flow_updates=12, [-1, 1] conversion in the callraft-largeload / first call: original 0.14 s / 0.762 s, portable 0.17 s / 0.304 s, kernels 1.07 s / 0.107 sraft-large-thingsload / first call: original 0.13 s / 0.58 s, portable 0.25 s / 0.303 s, kernels 1.07 s / 0.108 sraft-large-kittiload / first call: original 0.14 s / 0.58 s, portable 0.17 s / 0.304 s, kernels 1.06 s / 0.107 sraft-smallload / first call: original 0.09 s / 0.433 s, portable 0.16 s / 0.173 s, kernels 1.06 s / 0.068 s- Protocol, first call, 3 warm-up, peak reset, median of 3 rounds x median of 5
Measured
Frames _10 -> _11 at full size against the flow_occ ground truth; EPE = mean of the per-pair mean end-point error, Fl-all = share of all valid pixels with an error > 3 px and > 5 % of the GT magnitude. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
raft-large | KITTI 2015 train, EPE / Fl-all % | 1.528 / 5.60 | 1.528 / 5.60 | 1.529 / 5.61 | 1.528 / 5.60 | 1.526 / 5.60 | trained on this dataset's public images; not a zero-shot result |
raft-large-things | KITTI 2015 train, EPE / Fl-all % | 4.838 / 16.55 | 4.831 / 16.54 | 4.828 / 16.51 | 4.838 / 16.55 | 4.834 / 16.53 | |
raft-large-kitti | KITTI 2015 train, EPE / Fl-all % | 0.614 / 1.44 | 0.614 / 1.44 | 0.614 / 1.44 | 0.614 / 1.44 | 0.614 / 1.44 | trained on this dataset's public images; not a zero-shot result |
raft-small | KITTI 2015 train, EPE / Fl-all % | 7.854 / 25.91 | 7.838 / 25.92 | 7.846 / 25.92 | 7.854 / 25.91 | 7.834 / 25.92 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f2992269+uncommitted, 2026-11-09; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 6f0a70e1, 2026-11-17; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks f2992269+uncommitted, 2026-11-09.
Parity
CPU, float32: max |diff| <= 0.00012 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.0019 and p99 <= 0.0091 (absolute error of the output flow).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
raft-large | 0.00098 / 0.00459 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, raft_flow@a101a33607b6:sm_120 |
raft-large-things | 0.00105 / 0.00459 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, raft_flow@a101a33607b6:sm_120 |
raft-large-kitti | 0.00096 / 0.00441 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, raft_flow@a101a33607b6:sm_120 |
raft-small | 0.00228 / 0.00957 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, cutlass_conv@988138e042cb:sm_120, raft_flow@a101a33607b6:sm_120 |
Example output
One fixed input through this checkpoint, the same for every model of the task (portable · float16 · NVIDIA GeForce RTX 5060 Ti).
Input: Motorcycle, Middlebury 2014 stereo (left and right view, downscaled 4x), Scharstein et al., Middlebury College (research dataset, no licence stated).