Commit ·
53da322
0
Parent(s):
fastforks 0.1.0
Browse files- .gitattributes +35 -0
- README.md +104 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: "fastforks"
|
| 3 |
+
pipeline_tag: "image-classification"
|
| 4 |
+
license: "other"
|
| 5 |
+
license_name: "bsd-3-clause-code-weights-unstated"
|
| 6 |
+
license_link: "https://github.com/pytorch/vision/blob/1f1a920d685d46dfbe187934b785b7ecb7a182f2/LICENSE"
|
| 7 |
+
tags:
|
| 8 |
+
- "classification"
|
| 9 |
+
- "image-classification"
|
| 10 |
+
- "cuda"
|
| 11 |
+
- "pytorch"
|
| 12 |
+
- "fastforks"
|
| 13 |
+
---
|
| 14 |
+
# ResNet (fastforks)
|
| 15 |
+
|
| 16 |
+
ResNet (He et al. 2015): residual basic / bottleneck blocks.
|
| 17 |
+
|
| 18 |
+
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: <https://github.com/kleinicke/fastforks>. Kernels for the `kernels` backend: <https://huggingface.co/fastforks/kernels>. Original code: <https://github.com/pytorch/vision> at `1f1a920d685d`.
|
| 19 |
+
|
| 20 |
+
Task: classification. Tier: stable. Outputs: `logits`. Backends: `portable`, `kernels`.
|
| 21 |
+
|
| 22 |
+
Input: one RGB image. Output: ImageNet-1k class logits.
|
| 23 |
+
|
| 24 |
+
## Variants
|
| 25 |
+
|
| 26 |
+
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/classification/models/resnet/card.toml).
|
| 27 |
+
|
| 28 |
+
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|
| 29 |
+
|---|---|---|---|---|
|
| 30 |
+
| `resnet152.tv2_in1k@1` | [resnet152-f82ba261.pth](https://download.pytorch.org/models/resnet152-f82ba261.pth) | `f82ba2614b9f` | BSD-3-Clause (assumed from code) | yes |
|
| 31 |
+
| `resnet18.tv_in1k@1` | [resnet18-f37072fd.pth](https://download.pytorch.org/models/resnet18-f37072fd.pth) | `f37072fd47e8` | BSD-3-Clause (assumed from code) | yes |
|
| 32 |
+
| `resnet50.tv2_in1k@1` | [resnet50-11ad3fa6.pth](https://download.pytorch.org/models/resnet50-11ad3fa6.pth) | `11ad3fa62ca7` | BSD-3-Clause (assumed from code) | yes |
|
| 33 |
+
|
| 34 |
+
## Licence
|
| 35 |
+
|
| 36 |
+
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: BSD-3-Clause. Files: .
|
| 37 |
+
|
| 38 |
+
Code licence: BSD-3-Clause; the authors do not state a separate weights licence.
|
| 39 |
+
|
| 40 |
+
Training data: ImageNet-1k (ILSVRC 2012 classification).
|
| 41 |
+
|
| 42 |
+
Licence evidence: <https://github.com/pytorch/vision/blob/1f1a920d685d46dfbe187934b785b7ecb7a182f2/LICENSE>
|
| 43 |
+
|
| 44 |
+
## Input size
|
| 45 |
+
|
| 46 |
+
- `resnet152.tv2_in1k`, `resnet50.tv2_in1k`: fixed 224x224: the input is resized (short side 232) and centre-cropped to it
|
| 47 |
+
- `resnet18.tv_in1k`: fixed 224x224: the input is resized (short side 256) and centre-cropped to it
|
| 48 |
+
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `resnet152.tv2_in1k` 224x224 (0.2 GiB peak allocated, 0.2 reserved); `resnet18.tv_in1k` 224x224 (0.1 GiB peak allocated, 0.1 reserved); `resnet50.tv2_in1k` 224x224 (0.1 GiB peak allocated, 0.1 reserved)
|
| 49 |
+
|
| 50 |
+
## Speed and memory
|
| 51 |
+
|
| 52 |
+
### Classification, synthetic, 224x224
|
| 53 |
+
|
| 54 |
+
| model | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
|
| 55 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
| 56 |
+
| `resnet152.tv2_in1k` | 12.79 | 16.27 | 8.36 | 2.17 | 5.9x | 3.9x | 378 / 390 | 155 / 186 | 184 / 248 |
|
| 57 |
+
| `resnet18.tv_in1k` | 1.91 | 2.44 | 1.48 | 0.55 | 3.5x | 2.7x | 105 / 130 | 61 / 90 | 91 / 154 |
|
| 58 |
+
| `resnet50.tv2_in1k` | 4.74 | 5.84 | 3.15 | 0.99 | 4.8x | 3.2x | 180 / 192 | 89 / 142 | 118 / 204 |
|
| 59 |
+
|
| 60 |
+
### Startup and first call
|
| 61 |
+
|
| 62 |
+
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|
| 63 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 64 |
+
| `resnet152.tv2_in1k` | 2.34 | 0.43 | 0.49† | 0.24 | 0.02 | 0.00 |
|
| 65 |
+
| `resnet18.tv_in1k` | 0.27 | 0.07 | 0.08† | 0.00 | 0.00 | 0.00 |
|
| 66 |
+
| `resnet50.tv2_in1k` | 0.51 | 0.16 | 0.18† | 0.01 | 0.00 | 0.00 |
|
| 67 |
+
|
| 68 |
+
### Fixed-size speed and peak memory, all models
|
| 69 |
+
|
| 70 |
+
| model | mode | 224x224 |
|
| 71 |
+
| --- | --- | --- |
|
| 72 |
+
| `resnet152.tv2_in1k` | portable | 8.4 ms / 157 / 192 |
|
| 73 |
+
| `resnet152.tv2_in1k` | kernels | 2.2 ms / 188 / 270 |
|
| 74 |
+
| `resnet18.tv_in1k` | portable | 1.4 ms / 60 / 68 |
|
| 75 |
+
| `resnet18.tv_in1k` | kernels | 0.6 ms / 91 / 144 |
|
| 76 |
+
| `resnet50.tv2_in1k` | portable | 3.1 ms / 91 / 110 |
|
| 77 |
+
| `resnet50.tv2_in1k` | kernels | 1.0 ms / 121 / 190 |
|
| 78 |
+
|
| 79 |
+
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
|
| 80 |
+
|
| 81 |
+
Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the authors' code at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
|
| 82 |
+
|
| 83 |
+
## Accuracy
|
| 84 |
+
|
| 85 |
+
### Parity with the original code
|
| 86 |
+
|
| 87 |
+
Every variant is checked against golden outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 px and p99 <= 0.08 px.
|
| 88 |
+
|
| 89 |
+
## Usage
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
from fastforks import classification
|
| 93 |
+
|
| 94 |
+
model = classification.load("resnet152.tv2_in1k") # portable PyTorch on the GPU if there is one, else the CPU
|
| 95 |
+
result = model("photo.jpg")
|
| 96 |
+
result.top(5) # top-5 classes
|
| 97 |
+
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `resnet152.tv2_in1k`, `resnet18.tv_in1k`, `resnet50.tv2_in1k`.
|
| 101 |
+
|
| 102 |
+
## Kernels backend
|
| 103 |
+
|
| 104 |
+
`classification.load("resnet152.tv2_in1k", mode="kernels")` runs our CUDA kernels (`cudnn_hacc`, `fvm_conv`, `fvm_extra`, `fvm_mb`, `fvm_r3`). It needs a prebuilt kernel for your GPU architecture (downloaded from <https://huggingface.co/fastforks/kernels> on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice.
|