MegaFlow
MegaFlow (ETH Zurich, 2025): large-displacement optical flow on a frozen DINOv2 backbone with global matching and refinement; one large model. Apache-2.0 code and weights.
experimental Fork of cvg/megaflow@2328f8b · backends: portable, kernels
- Paper MegaFlow: Zero-Shot Large Displacement Optical Flow ECCV 2026 · first released 26 Mar 2026
Checkpoint megaflow
Paper 2026 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("megaflow") # kernels on a supported GPU, else portable PyTorch
result = model(frame1, frame2)
result.flow
result.backend # what ran: mode, device, dtype, kernels fastforks bench megaflow 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 fp16 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | not measured | – | – | – | – |
| Original (own default)the authors' mixed-precision option (bfloat16); upstream MegaFlow, num_reg_refine=8, README recipe: bf16 autocast | bf16 | 1588 | – | 8,230 MiB/8,786 MiB | 8.3 | 1.76 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 1109 | 1.4× | 3,035 MiB/3,246 MiB | 2.0 | 1.11 |
| Kernels | fp16 | 734 | 2.2× | 2,866 MiB/3,066 MiB | 7.1 | 0.73 |
| Portable + torch.compile | 917 | 1.7× | 2,611 MiB/2,886 MiB | 102 (build) | – | |
| TensorRT fp16 | fp16 | 677 | 2.3× | 7,336 MiBenginenot comparable | 214 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-13 to 2026-11-14. 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 | 11196 | 8,969 MiB process | matches | 1080x1920 | |
| Portable | fp32 | out of memory | – | 1080x1920 | ||
| Kernels | fp16 | not implemented | – | 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
- Apache-2.0 LICENSE
- Weights
- Apache-2.0 source
- Training data
-
- FlyingChairs (Freiburg) research-only, non-commercial
- TartanAir CC-BY-4.0
- 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
Our reading of the licences, not legal advice.
Weights
megaflow-flow.safetensors 3.7 GB· hosted on Hugging Facefastforks downloads and checks these files on first use (fastforks download megaflow).
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.714 | 6.68 | reference | 200 | 1057 |
| Original fp16 | bf16 | 1.727 | 6.75 | −0.013 | 200 | 432 |
| Portable fp32 | fp32 | 1.714 | 6.68 | ±0.000 | 200 | 1055 |
| Portable | fp16 | 1.715 | 6.69 | −0.001 | 200 | 330 |
| Kernels | fp16 | 1.714 | 6.69 | −0.000 | 200 | 216 |
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-14; 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 790d5f2f, 2026-11-14.
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.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.003 and p99 <= 0.008 (absolute error of the output flow).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.003 | 0.00199 |
| GPU default dtypes, p99 |diff| | ≤ 0.008 | 0.00579 |
Recorded for megaflow on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-13, with these kernels: cudnn_haccfastbbraft_flow
Details
MegaFlow (Zhang, Wang, Pollefeys, Xu, ECCV 2026): zero-shot large-displacement optical flow from a video transformer. The frames are resized to width 952 for a DINOv2 ViT-L/14 + 24 alternating frame / global attention blocks (VGGT's aggregator); a DPT head fuses four of its layers with a ResNet34 CNN into 128-channel features, a global softmax correlation gives the initial flow, and RAFT-style updates on 9 x 9 local correlations of the CNN's 1/4 features refine it (convex 4x upsampling). The authors' released megaflow-flow weights; the network is ported from cvg/megaflow. A pair runs as upstream's two-frame clip. Paper: state-of-the-art zero-shot results on Sintel, KITTI and Spring.
- 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 >= 64, padded to a multiple of 8; tested up to 1080x1920 (3,035 MiB allocated)
- Options
iters=8>= 1· changes the output
- Outputs
flow- CUDA kernels
fastbbfast backbone kernels: flash attention, window attention, instance norm and rotary embeddings for ViT and similar backbonescudnn_haccconvolutions with fp16 accumulation (cuDNN)raft_flowRAFT optical flow kernels
- Apple (MPS)
- fp32, fp16
Limitations
- Pairs only: upstream's multi-frame clips (temporal attention across more than two frames) and its point-tracking and chairs-things checkpoints are not exposed.
Full reference, generated from the repository
MegaFlow (ETH Zurich, 2025): large-displacement optical flow on a frozen DINOv2 backbone with global matching and refinement; one large model. Apache-2.0 code and weights.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
megaflow | synthetic (1080x1920) | original portable kernels portable + torch.compile TensorRT fp16 | 1588 1109 734 917 677 | 8230 / 8786 3035 / 3246 2866 / 3066 2611 / 2886 9265 / 9300 |
Details
- Original code: https://github.com/cvg/megaflow at
2328f8bb2690 - Code licence: Apache-2.0 (permissive); files:
LICENSE - Weights licence: Apache-2.0
- Licence evidence: https://huggingface.co/Kristen-Z/MegaFlow/blob/b4c5c33800b8fa88e047d2eb70ae74b0feca606d/README.md
- Training data: FlyingChairs (Freiburg), TartanAir, Freiburg SceneFlow (FlyingThings3D, Driving, Monkaa), MPI Sintel optical flow, KITTI stereo / optical flow 2012 / 2015, HCI HD1K optical flow benchmark (FlyingChairs, FlyingThings3D (part of SceneFlow), TartanAir, then a mix with Sintel, KITTI 2015 and HD1K, as upstream's README lists the training datasets)
- Options:
iters= 8 (>= 1) - Kernel libraries:
fastbb,cudnn_hacc,raft_flow - Variants:
megaflow - Outputs: flow
- Input size: any H x W >= 64, padded to a multiple of 8
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
megaflow1080x1920 (3.0 GiB peak allocated, 3.2 reserved) megaflow1080x1920, first call: portable + torch.compile 102 s (cold Inductor cache), TensorRT fp16 214 s (ONNX + engine).megafloworiginal 1080x1920: the authors' mixed-precision option (bfloat16); upstream MegaFlow, num_reg_refine=8, README recipe: bf16 autocastmegaflowload / first call: original 9.56 s / 6.769 s, portable 1.96 s / 0.758 s (375x1242), kernels 7.1 s / 0.668 s (375x1242)- 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 |
|---|---|---|---|---|---|---|---|
megaflow | KITTI 2015 train, EPE / Fl-all % | 1.714 / 6.68 | 1.727 / 6.75 | 1.715 / 6.69 | 1.714 / 6.68 | 1.714 / 6.69 | trained on this dataset's public images; not a zero-shot result |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 790d5f2f, 2026-11-14; 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 790d5f2f, 2026-11-14.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.003 and p99 <= 0.008 (absolute error of the output flow).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
megaflow | 0.00199 / 0.00579 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fastbb@7d058322634d:sm_120, raft_flow@a101a33607b6:sm_120 |
Limitations
- Pairs only: upstream's multi-frame clips (temporal attention across more than two frames) and its point-tracking and chairs-things checkpoints are not exposed.
Example output
No example rendered for this checkpoint yet.