Models · Stereo matching

S2M2

A transformer-based stereo family in four sizes (S, M, L, XL). Non-commercial licence.

stable Fork of junhong-3dv/s2m2@8f3bd78 · backends: portable, kernels

Checkpoint

Paper 2025 Added in 0.1.0 Evaluated with 0.2.0

Kernels, RTX 5060 Ti 16 GB 113 ms 994x1482, fp16
vs the faster original 3.1× original fp16: 350 ms
Peak memory 686 MiB original: 1,759 MiB
Accuracy vs original fp32 ±0.00 kernels bad px %, ETH3D two-view train (1.10 original)

Use it

pip install fastforks

Lean install with only what this model needs: pip install "fastforks-core[nc]"

from fastforks import stereo

model = stereo.load("s2m2-s")  # kernels on a supported GPU, else portable PyTorch
result = model(left, right)
result.disparity  # also: confidence, occlusion
result.backend  # what ran: mode, device, dtype, kernels

The weights are non-commercial: fastforks downloads them only with FASTFORKS_NONCOMMERCIAL=1 set.

fastforks bench s2m2-s

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 fp32fp32 5830.60×2,775 MiB/3,008 MiB––
Original fp16torch.autocast(fp16) around the forwardfp16 350–1,759 MiB/1,986 MiB––
Portable fp32fp32not measured ––––
Portablefp16 3481.0×1,733 MiB/1,930 MiB0.20.35
Kernelsfp16 1133.1×686 MiB/820 MiB0.20.11
Portable + torch.compile 1861.9×1,579 MiB/1,710 MiB96 (build)–
TensorRT fp16fp16 1372.6×980 MiBenginenot comparable363 (build)–

Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-01 to 2026-11-03. Median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls. 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-12Originalfp32cannot run here–994x1482
Portablefp161607 5,991 MiB processmatches994x1482
Portablefp321707 8,051 MiB processmatches994x1482
Kernelsfp16not implemented–994x1482
NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp16413 1,706 MiB/1,908 MiB–994x1482
Kernelsfp16163 660 MiB/882 MiB–994x1482
NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp16125 1,706 MiB/1,908 MiB–994x1482
Kernelsfp1656.8 660 MiB/882 MiB–994x1482
NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp16284 1,706 MiB/1,908 MiB–994x1482
Kernelsfp16137 655 MiB/942 MiB–994x1482
NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07Portablefp16124 1,706 MiB/1,908 MiB–994x1482
Kernelsfp1662.4 655 MiB/942 MiB–994x1482
NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08Portablefp1671.2 1,730 MiB/2,008 MiB–994x1482
Kernelsfp1629.0 683 MiB/902 MiB–994x1482

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

Non-commercial only

Code
CC-BY-NC-4.0 LICENSE.md
Weights
CC-BY-NC-4.0 source
Training data
README: extended training data incl. transparent objects
  • code: CC-BY-NC-4.0 (noncommercial)
  • weights: CC-BY-NC-4.0

Our reading of the licences, not legal advice.

Weights

CH128NTR1.pth 107 MB· hosted on Hugging Face

fastforks downloads and checks these files on first use (fastforks download s2m2-s). Non-commercial weights need FASTFORKS_NONCOMMERCIAL=1.

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.

ETH3D two-view train

bad > 1 px % / EPEtraining data not stated: possibly seen

Rundtypebad px % ↓EPE ↓Δ bad px % vs fp32 originalpairsms / pair
Original fp32fp321.100.193 reference 27 128
Original fp16fp161.070.198 +0.03 27 89.7
Portable fp32fp321.100.193 ±0.00 27 122
Portablefp161.120.193 −0.02 27 74.9
Kernelsfp161.100.193 ±0.00 27 38.3
Original .half()fp16fails: RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward)

Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, original .half(): RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-05; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 468fba10, 2026-11-05.

Middlebury 2014 trainingH

bad > 2 px % / EPEtraining data not stated: possibly seen

Rundtypebad px % ↓EPE ↓Δ bad px % vs fp32 originalpairsms / pair
Original fp32fp323.230.652 reference 15 492
Original fp16fp163.230.657 ±0.00 15 308
Portable fp32fp323.230.652 ±0.00 15 474
Portablefp163.240.652 −0.01 15 294
Kernelsfp163.240.652 −0.01 15 98.0
Original .half()fp16fails: RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward)

Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16, original .half(): RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-05; portable fp32, portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 468fba10, 2026-11-05.

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.02 px and p99 <= 0.25 px.

CheckToleranceMeasured
CPU fp32, max |diff|≤ 0.002 pxnot recorded
GPU default dtypes, mean |diff|≤ 0.02 px0.00973 px
GPU default dtypes, p99 |diff|≤ 0.25 px0.03415 px

Recorded for s2m2-s on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-02, with these kernels: cudnn_haccs2m2s2m2_cutlass

Details

S2M2 (Min et al. 2025): multi-resolution transformer with optimal-transport matching; also outputs confidence and occlusion maps.

Input / output
Input: a rectified left / right image pair. Output: a disparity map (pixels, left view).
Input size
any H x W >= 32, padded to a multiple of 32; tested up to 1988x2880 (7,588 MiB allocated)
Outputs
disparity, confidence, occlusion(on request)
Checkpoint
feature_channels=128, num_transformer=1
CUDA kernels
  • s2m2S2M2: attention and optimal-transport kernels
  • s2m2_cutlassS2M2: CUTLASS convolutions
  • cudnn_haccconvolutions with fp16 accumulation (cuDNN)
Apple (MPS)
fp32, fp16

Limitations

  • At 994x1482 portable S2M2-S is about as fast as the original code and allocates slightly more memory; use kernels for speed and memory.
Full reference, generated from the repository

A transformer-based stereo family in four sizes (S, M, L, XL). Non-commercial licence.

Commercial use: no (code: CC-BY-NC-4.0 (noncommercial); weights: CC-BY-NC-4.0).

variantinputbackendtime (ms)peak memory (MiB, allocated / reserved)
s2m2-sMiddlebury 2014 half (994x1482)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
582
350
348
113
186
137
2775 / 3008
1759 / 1986
1733 / 1930
686 / 820
1579 / 1710
1186 / 1240
s2m2-mMiddlebury 2014 half (994x1482)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
1242
666
670
248
420
285
3399 / 3704
2371 / 2920
2289 / 2766
876 / 1162
2197 / 2572
1958 / 2002
s2m2-lMiddlebury 2014 half (994x1482)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
1934
1005
1017
376
650
497
4333 / 5252
3248 / 4090
3234 / 3816
1249 / 1568
3169 / 3514
2910 / 2982
s2m2-xlMiddlebury 2014 half (994x1482)original (fp32)
original
portable
kernels
portable + torch.compile
TensorRT fp16
3510
1796
1818
682
1298
753
6940 / 8254
5606 / 6080
5217 / 6014
2092 / 2274
5594 / 6014
5283 / 5338
Details
  • Original code: https://github.com/junhong-3dv/s2m2 at 8f3bd785df59
  • Code licence: CC-BY-NC-4.0 (noncommercial); files: LICENSE.md
  • Weights licence: CC-BY-NC-4.0
  • Licence evidence: https://github.com/junhong-3dv/s2m2/blob/8f3bd785df593619d955203c6f2c741bef6e31df/README.md#L24
  • Training data: README: extended training data incl. transparent objects
  • Kernel libraries: s2m2, s2m2_cutlass, cudnn_hacc
  • Variants: s2m2-s, s2m2-m, s2m2-l, s2m2-xl
  • Outputs: disparity, confidence, occlusion (in extras)
  • Input size: any H x W >= 32, padded to a multiple of 32
  • Tested up to (portable, fp16, RTX 5060 Ti 16 GB): s2m2-s 1988x2880 (7.4 GiB peak allocated, 10.6 reserved); s2m2-m 1988x2880 (8.9 GiB peak allocated, 11.5 reserved); s2m2-l 1988x2880 (11.4 GiB peak allocated, 14.2 reserved); s2m2-xl 1024x2048 (7.3 GiB peak allocated, 8.5 reserved)
  • s2m2-s 994x1482, first call: portable + torch.compile 96 s (cold Inductor cache), TensorRT fp16 363 s (ONNX + engine).
  • s2m2-m 994x1482, first call: portable + torch.compile 126 s (cold Inductor cache), TensorRT fp16 305 s (ONNX + engine).
  • s2m2-l 994x1482, first call: portable + torch.compile 144 s (cold Inductor cache), TensorRT fp16 374 s (ONNX + engine).
  • s2m2-xl 994x1482, first call: portable + torch.compile 153 s (cold Inductor cache), TensorRT fp16 408 s (ONNX + engine).
  • s2m2-s original 994x1482: torch.autocast(fp16) around the forward
  • s2m2-m original 994x1482: torch.autocast(fp16) around the forward
  • s2m2-l original 994x1482: torch.autocast(float16) around the call
  • s2m2-xl original 994x1482: torch.autocast(fp16) around the forward
  • s2m2-s load / first call: original 0.22 s / 0.143 s (375x1242), portable 0.22 s / 0.352† s, kernels 0.2† s / 0.114† s
  • s2m2-m load / first call: original 3.95 s / 0.268 s (375x1242), portable 1.21 s / 0.699 s (375x1242), kernels 0.31† s / 0.249† s
  • s2m2-l load / first call: original 1.38 s / 1.007 s, portable 2.61 s / 0.755 s (375x1242), kernels 0.58† s / 0.374† s
  • s2m2-xl load / first call: original 4.5 s / 0.529 s (375x1242), portable 2.64 s / 0.888 s (375x1242), kernels 0.9† s / 0.681† s
  • † measured in the speed sweep after the portable load (or an earlier size) in the same process: file cache and kernels are warm, so the time is lower than a fresh start.
  • Protocol, median of 5 after 3 warm-up, uint8 CUDA input (synthetic for bench_inputs sizes), card defaults; gc before each load; peak = max over the first call and the timed calls

Measured

Original = the original code named under Details, same checkpoint and protocol.

variantdatasetoriginal fp32original fp16original halfportableportable fp32kernelsnote
s2m2-sETH3D two-view train, bad > 1 px % / EPE1.10 / 0.1931.07 / 0.198fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))1.12 / 0.1931.10 / 0.1931.10 / 0.193possibly in the training data
s2m2-sMiddlebury 2014 trainingH, bad > 2 px % / EPE3.23 / 0.6523.23 / 0.657fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))3.24 / 0.6523.23 / 0.6523.24 / 0.652possibly in the training data
s2m2-mETH3D two-view train, bad > 1 px % / EPE0.94 / 0.1780.94 / 0.188fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))0.95 / 0.1780.94 / 0.1780.95 / 0.178possibly in the training data
s2m2-mMiddlebury 2014 trainingH, bad > 2 px % / EPE3.28 / 0.6513.28 / 0.656fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))3.29 / 0.6513.28 / 0.6513.28 / 0.651possibly in the training data
s2m2-lETH3D two-view train, bad > 1 px % / EPE0.84 / 0.1690.85 / 0.182fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))0.84 / 0.1690.83 / 0.1690.82 / 0.169possibly in the training data
s2m2-lMiddlebury 2014 trainingH, bad > 2 px % / EPE2.88 / 0.5422.84 / 0.551fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))2.84 / 0.5422.88 / 0.5422.85 / 0.542possibly in the training data
s2m2-xlETH3D two-view train, bad > 1 px % / EPE0.53 / 0.1470.52 / 0.157fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))0.53 / 0.1470.53 / 0.1470.52 / 0.149possibly in the training data
s2m2-xlMiddlebury 2014 trainingH, bad > 2 px % / EPE2.34 / 0.4982.33 / 0.504fails (RuntimeError: Expected tensor for argument #1 'input' to have the same type as tensor for argument #2 'grid'; but type torch.cuda.HalfTensor does not equal torch.cuda.FloatTensor (while checking arguments for cudnn_grid_sampler_forward))2.33 / 0.4982.34 / 0.4982.33 / 0.499possibly in the training data

Measured on NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 468fba10, 2026-11-05.

Parity

CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 px and p99 <= 0.25 px.

variantkernels error vs original, mean / p99GPU, torchkernels used
s2m2-s0.00973 / 0.03415RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, s2m2@73d0d3fa70d2:sm_120, s2m2_cutlass@3aec99821257:sm_120
s2m2-m0.00618 / 0.02223RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, s2m2@73d0d3fa70d2:sm_120, s2m2_cutlass@3aec99821257:sm_120
s2m2-l0.01523 / 0.05073RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, s2m2@73d0d3fa70d2:sm_120, s2m2_cutlass@3aec99821257:sm_120
s2m2-xl0.01853 / 0.0624RTX 5060 Ti, torch 2.14.1+cu130cudnn_hacc@cudnn92400, s2m2@73d0d3fa70d2:sm_120, s2m2_cutlass@3aec99821257:sm_120

Limitations

  • At 994x1482 portable S2M2-S is about as fast as the original code and allocates slightly more memory; use kernels for speed and memory.

Example output

One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).

Left view
Right view
Output
Motorcycle, Middlebury 2014 stereo (left and right view, downscaled 4x), left view
Left view · 100%

Input: Motorcycle, Middlebury 2014 stereo (left and right view, downscaled 4x), Scharstein et al., Middlebury College (research dataset, no licence stated).