ResNet
ResNet (He et al. 2015): the standard residual classifier.
stable Fork of pytorch/vision@1f1a920 · backends: portable, kernels
- Paper Deep Residual Learning for Image Recognition CVPR 2016 · first released 10 Dec 2015
- Authors’ code KaimingHe/deep-residual-networks (Caffe), not the code forked here: The authors' code and weights are Caffe; torchvision's PyTorch implementation is used, and the tv/tv2 weights are torchvision's own trainings.
Paper 2015 Added in 0.1.0 Evaluated with 0.2.0
Use it
pip install fastforks Lean install with only what this model needs: pip install "fastforks-core[torchvision]"
from fastforks import classification
model = classification.load("resnet18.tv_in1k") # kernels on a supported GPU, else portable PyTorch
result = model(image)
result.logits
result.backend # what ran: mode, device, dtype, kernels fastforks bench resnet18.tv_in1k 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.
Input: synthetic, 224x224 (the task’s standard size)
| Backend | dtype | Time per call (ms) | vs original fp32 | Peak memory allocated / reserved | Load (s) | First call (s) |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 1.91 | – | 94 MiB/130 MiB | 0.1 | 0.00 |
| Original fp16torch.autocast(fp16) around the forward | fp16 | 2.44 | 0.78× | 105 MiB/130 MiB | 0.3 | 0.00 |
| Portable fp32 | fp32 | not measured | – | – | – | – |
| Portable | fp16 | 1.44 | 1.3× | 59 MiB/88 MiB | 1.3 | 0.06 |
| Kernels | fp16 | 0.472 | 4.0× | 58 MiB/110 MiB | 1.4 | 0.04 |
| Portable + torch.compile | 1.04 | 1.8× | 91 MiB/108 MiB | 4 (build) | – | |
| TensorRT fp16 | fp16 | 0.220 | 8.7× | 34 MiBenginenot comparable | 14 (build) | – |
Measured on RTX 5060 Ti 16 GB, torch 2.14.1+cu130, 2026-11-03 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 | 7.25 | 466 MiB process | matches | 224x224 |
| Portable | fp16 | 5.37 | 481 MiB process | matches | 224x224 | |
| Portable | fp32 | 4.67 | 454 MiB process | matches | 224x224 | |
| Kernels | fp16 | not implemented | – | 224x224 | ||
| NVIDIA L4 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 2.24 | 35 MiB/68 MiB | – | 224x224 |
| Kernels | fp16 | 0.718 | 42 MiB/110 MiB | – | 224x224 | |
| NVIDIA L40S CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 1.65 | 35 MiB/68 MiB | – | 224x224 |
| Kernels | fp16 | 0.519 | 42 MiB/110 MiB | – | 224x224 | |
| NVIDIA A10 CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 1.40 | 35 MiB/68 MiB | – | 224x224 |
| Kernels | fp16 | 0.609 | 42 MiB/110 MiB | – | 224x224 | |
| NVIDIA A100-SXM4-40GB CUDA, torch 2.14.1+cu130, 2026-11-07 | Portable | fp16 | 1.71 | 35 MiB/68 MiB | – | 224x224 |
| Kernels | fp16 | 0.797 | 42 MiB/110 MiB | – | 224x224 | |
| NVIDIA RTX PRO 6000 CUDA, torch 2.14.1+cu130, 2026-11-08 | Portable | fp16 | 0.550 | 59 MiB/88 MiB | – | 224x224 |
| Kernels | fp16 | 0.370 | 89 MiB/150 MiB | – | 224x224 | |
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
- Weights
- BSD-3-Clause (assumed from code)(not stated by the authors; assumed to follow the code) source
- Training data
-
- ImageNet-1k (ILSVRC 2012 classification) noncommercial, non-commercial
- weights licence not stated by the original authors; assumed to be the code licence
Our reading of the licences, not legal advice.
Weights
resnet18-f37072fd.pth 46.8 MB· hosted on PyTorchfastforks downloads and checks these files on first use (fastforks download resnet18.tv_in1k).
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.
ImageNet-1k val
5000 random images, top-1 / top-5 %
| Run | dtype | top-1 % ↑ | top-5 % ↑ | Δ top-1 % vs fp32 original | images | ms / image |
|---|---|---|---|---|---|---|
| Original fp32 | fp32 | 70.80 | 89.18 | reference | 5000 | 0.524 |
| Original fp16 | fp16 | 70.80 | 89.18 | ±0.00 | 5000 | 0.348 |
| Portable fp32 | fp32 | 70.72 | 89.12 | −0.08 | 5000 | 0.728 |
| Portable | fp16 | 70.82 | 89.12 | +0.02 | 5000 | 0.389 |
| Kernels | fp16 | 70.74 | 89.10 | −0.06 | 5000 | 0.293 |
fastforks: the model's own resize / crop on the GPU; original: the library's pretrained loader and its PIL eval transform. Original = the authors’ code, same checkpoint and protocol. Measured on original fp32, original fp16: RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-06; portable fp32: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7c91993, 2026-10-31; portable, kernels: RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
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 and p99 <= 0.08 (absolute error of the output logits).
| Check | Tolerance | Measured |
|---|---|---|
| CPU fp32, max |diff| | ≤ 0.002 | not recorded |
| GPU default dtypes, mean |diff| | ≤ 0.02 | 0.00193 |
| GPU default dtypes, p99 |diff| | ≤ 0.08 | 0.0071 |
Recorded for resnet18.tv_in1k on RTX 5060 Ti, torch 2.14.1+cu130, 2026-11-04, with these kernels: cudnn_haccfvm_convfvm_extrafvm_mbfvm_r3
Details
ResNet (He et al. 2015): residual basic / bottleneck blocks.
- Input / output
- Input: one RGB image. Output: ImageNet-1k class logits.
- Input size
- fixed 224x224: the input is resized (short side 256) and centre-cropped to it; tested up to 224x224 (80 MiB allocated)
- Outputs
logits- Checkpoint
arch="resnet18"- CUDA kernels
cudnn_haccconvolutions with fp16 accumulation (cuDNN)fvm_convfused convolutions for image classifiersfvm_extrafused transformer row operations (rotary split, SwiGLU with LayerNorm)fvm_mbfused MBConv blocks (MobileNet and EfficientNet families)fvm_r3further fused classifier blocks
- Apple (MPS)
- fp32, fp16
Full reference, generated from the repository
ResNet (He et al. 2015): the standard residual classifier.
Commercial use: yes.
| variant | input | backend | time (ms) | peak memory (MiB, allocated / reserved) |
|---|---|---|---|---|
resnet18.tv_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 1.91 2.44 1.44 0.472 1.04 0.220 | 94 / 130 105 / 130 59 / 88 58 / 110 91 / 108 89 / 120 |
resnet50.tv2_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 4.74 5.84 3.15 0.826 2.10 0.466 | 148 / 162 180 / 192 89 / 142 116 / 162 119 / 138 152 / 166 |
resnet152.tv2_in1k | synthetic (224x224) | original (fp32) original portable kernels portable + torch.compile TensorRT fp16 | 12.8 16.3 8.51 1.85 4.55 1.09 | 280 / 288 378 / 390 153 / 200 152 / 224 185 / 240 282 / 334 |
Details
- Original code: https://github.com/pytorch/vision at
1f1a920d685d - Code licence: BSD-3-Clause (permissive); files:
- Weights licence: BSD-3-Clause (assumed from code)
- Licence evidence: https://github.com/pytorch/vision/blob/1f1a920d685d46dfbe187934b785b7ecb7a182f2/LICENSE
- Training data: ImageNet-1k (ILSVRC 2012 classification)
- Kernel libraries:
cudnn_hacc,fvm_conv,fvm_extra,fvm_mb,fvm_r3 - Variants:
resnet18.tv_in1k(default ofresnet18),resnet50.tv2_in1k(default ofresnet50),resnet152.tv2_in1k(default ofresnet152) - Outputs: logits; label_set:
imagenet-1k - Input size:
resnet18.tv_in1k: fixed 224x224: the input is resized (short side 256) and centre-cropped to itresnet50.tv2_in1k,resnet152.tv2_in1k: fixed 224x224: the input is resized (short side 232) and centre-cropped to it
- Tested up to (portable, fp16, RTX 5060 Ti 16 GB):
resnet18.tv_in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);resnet50.tv2_in1k224x224 (0.1 GiB peak allocated, 0.1 reserved);resnet152.tv2_in1k224x224 (0.2 GiB peak allocated, 0.2 reserved) resnet18.tv_in1k224x224, first call: portable + torch.compile 4 s (cold Inductor cache), TensorRT fp16 14 s (ONNX + engine).resnet50.tv2_in1k224x224, first call: portable + torch.compile 8 s (cold Inductor cache), TensorRT fp16 24 s (ONNX + engine).resnet152.tv2_in1k224x224, first call: portable + torch.compile 9 s (cold Inductor cache), TensorRT fp16 23 s (ONNX + engine).resnet18.tv_in1koriginal 224x224: torch.autocast(fp16) around the forwardresnet50.tv2_in1koriginal 224x224: torch.autocast(fp16) around the forwardresnet152.tv2_in1koriginal 224x224: torch.autocast(fp16) around the forwardresnet18.tv_in1kload / first call: original 0.27 s / 0.004 s, portable 1.25 s / 0.059 s, kernels 1.4 s / 0.042 sresnet50.tv2_in1kload / first call: original 0.51 s / 0.007 s, portable 0.16 s / 0.003 s, kernels 1.48 s / 0.041 sresnet152.tv2_in1kload / first call: original 2.34 s / 0.243 s, portable 2.01 s / 0.089 s, kernels 2.33 s / 0.039 s- Protocol,
resnet18.tv_in1k,resnet152.tv2_in1k: first call, 3 warm-up, peak reset, median of 3 rounds x median of 5 - Protocol,
resnet50.tv2_in1k: median of 9 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
fastforks: the model's own resize / crop on the GPU; original: the library's pretrained loader and its PIL eval transform. Original = the original code named under Details, same checkpoint and protocol.
| variant | dataset | original fp32 | original fp16 | portable | portable fp32 | kernels | note |
|---|---|---|---|---|---|---|---|
resnet18.tv_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 70.80 / 89.18 | 70.80 / 89.18 | 70.82 / 89.12 | 70.72 / 89.12 | 70.74 / 89.10 | |
resnet50.tv2_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 82.02 / 95.32 | 82.00 / 95.30 | 81.94 / 95.30 | 81.98 / 95.32 | 81.96 / 95.34 | |
resnet152.tv2_in1k | ImageNet-1k val, 5000 random images, top-1 / top-5 % | 82.90 / 96.22 | 82.90 / 96.20 | 82.90 / 96.24 | 82.94 / 96.24 | 82.90 / 96.24 |
Measured on portable: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06; portable32: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 7c91993, 2026-10-31; kernels: NVIDIA GeForce RTX 5060 Ti, torch 2.14.1+cu130, fastforks 939adfe8, 2026-11-06.
Parity
CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.08 (absolute error of the output logits).
| variant | kernels error vs original, mean / p99 | GPU, torch | kernels used |
|---|---|---|---|
resnet18.tv_in1k | 0.00193 / 0.0071 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
resnet50.tv2_in1k | 0.00202 / 0.00827 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
resnet152.tv2_in1k | 0.00122 / 0.00834 | RTX 5060 Ti, torch 2.14.1+cu130 | cudnn_hacc@cudnn92400, fvm_conv@f1d064e539e1:sm_120, fvm_extra@3208ce525a91:sm_120, fvm_mb@720dd3f29bf7:sm_120, fvm_r3@f54eb890e23c:sm_120 |
Example output
One fixed input through this checkpoint, the same for every model of the task (kernels · float16 · NVIDIA GeForce RTX 5060 Ti).
Top 5
Input: Chelsea the cat, Stéfan van der Walt (CC0).