Models · Optical flow

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

Checkpoint megaflow

Paper 2026 Added in 0.2.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 734 ms 1080x1920, fp16
vs the faster original 2.2× original bf16: 1588 ms
Peak memory 2,866 MiB original: 8,230 MiB
Accuracy vs original fp32 −0.000 kernels EPE, KITTI 2015 train (1.714 original)

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.

BackenddtypeTime per call (ms)vs original fp16Peak memory
allocated / reserved
Load (s)First call (s)
Original fp32fp32not measured ––––
Original (own default)the authors' mixed-precision option (bfloat16); upstream MegaFlow, num_reg_refine=8, README recipe: bf16 autocastbf16 1588–8,230 MiB/8,786 MiB8.31.76
Portable fp32fp32not measured ––––
Portablefp16 11091.4×3,035 MiB/3,246 MiB2.01.11
Kernelsfp16 7342.2×2,866 MiB/3,066 MiB7.10.73
Portable + torch.compile 9171.7×2,611 MiB/2,886 MiB102 (build)–
TensorRT fp16fp16 6772.3×7,336 MiBenginenot comparable214 (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

DeviceBackenddtypems / callPeak memoryOutput vs referenceInput
Apple M1 Pro 16 GB MPS, torch 2.14.1, 2026-11-14Originalfp32out of memory–1080x1920
Portablefp1611196 8,969 MiB processmatches1080x1920
Portablefp32out of memory–1080x1920
Kernelsfp16not 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

Our reading of the licences, not legal advice.

Weights

megaflow-flow.safetensors 3.7 GB· hosted on Hugging Face

fastforks 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

RundtypeEPE ↓Fl-all % ↓Δ EPE vs fp32 originalpairsms / pair
Original fp32fp321.7146.68 reference 200 1057
Original fp16bf161.7276.75 −0.013 200 432
Portable fp32fp321.7146.68 ±0.000 200 1055
Portablefp161.7156.69 −0.001 200 330
Kernelsfp161.7146.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).

CheckToleranceMeasured
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 backbones
  • cudnn_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.

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
megaflowsynthetic (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): megaflow 1080x1920 (3.0 GiB peak allocated, 3.2 reserved)
  • megaflow 1080x1920, first call: portable + torch.compile 102 s (cold Inductor cache), TensorRT fp16 214 s (ONNX + engine).
  • megaflow original 1080x1920: the authors' mixed-precision option (bfloat16); upstream MegaFlow, num_reg_refine=8, README recipe: bf16 autocast
  • megaflow load / 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.

variantdatasetoriginal fp32original fp16portableportable fp32kernelsnote
megaflowKITTI 2015 train, EPE / Fl-all %1.714 / 6.681.727 / 6.751.715 / 6.691.714 / 6.681.714 / 6.69trained 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).

variantkernels error vs original, mean / p99GPU, torchkernels used
megaflow0.00199 / 0.00579RTX 5060 Ti, torch 2.14.1+cu130cudnn_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.