fastforks 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,186 @@
1
+ Metadata-Version: 2.5
2
+ Name: fastforks
3
+ Version: 0.1.0
4
+ Summary: Fast, typed inference for published vision models: portable PyTorch and custom-kernel backends.
5
+ Author-email: Florian Kleinicke <coding@f-kleinicke.de>
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.11
19
+ Requires-Dist: fastforks-core[libs,nc]==0.1.0
20
+ Provides-Extra: tensorrt
21
+ Requires-Dist: fastforks-core[tensorrt]==0.1.0; extra == 'tensorrt'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # fastforks
25
+
26
+ Faster versions of published vision models behind one API: stereo matching, monocular and multi-view depth, image
27
+ classification, semantic and promptable segmentation (SAM), object detection and feature backbones (DINOv2, DINOv3).
28
+ You load a model by its id and get the original network's output, faster.
29
+
30
+ Every model has two backends; kernels run only where the GPU and driver fit (otherwise `auto` uses portable):
31
+
32
+ - **portable**: the original network in plain PyTorch, checked against the authors' code. Validated on CPU, NVIDIA
33
+ CUDA and Apple MPS; other PyTorch devices are untested.
34
+ - **kernels**: the same network with our CUDA kernels (NVIDIA sm_80 or newer, Linux x86-64) and, for 19 families, Metal
35
+ kernels on Apple silicon. Across the models and sizes we measured, the median is 1.9x faster than portable, with a
36
+ quarter at 2.5x or more and the best at 10x (small classifiers at batch 1). A few plain ViT classifiers gain nothing
37
+ ([benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md)).
38
+
39
+ By default (`mode="auto"`) fastforks uses kernels where they can run and the recorded measurements prefer them, and portable everywhere else.
40
+
41
+ | task | package | call → result | example models |
42
+ |---|---|---|---|
43
+ | [stereo matching](https://github.com/kleinicke/fastforks/blob/main/docs/models/stereo.md) | `fastforks.stereo` | `model(left, right)` → disparity | `igev-stereo-sceneflow`, `raft-stereo-middlebury`, `las2-s` |
44
+ | [monocular depth](https://github.com/kleinicke/fastforks/blob/main/docs/models/depth.md) | `fastforks.depth` | `model(image)` → depth or inverse depth | `depth-anything-v2-s`, `moge-2-vitl-normal`, `depth-pro` |
45
+ | [multi-view depth](https://github.com/kleinicke/fastforks/blob/main/docs/models/multiview.md) | `fastforks.multiview` | `model(images)` → depth, points, cameras per view; calibrated MVS (mvsanywhere, patchmatchnet) also take `intrinsics=`, `cam_to_world=` (patchmatchnet also needs `depth_range=(near, far)` and returns the reference view only); VGGT / MapAnything: images only | `mvsanywhere`, `vggt-1b`, `mapanything-apache` |
46
+ | [image classification](https://github.com/kleinicke/fastforks/blob/main/docs/models/classification.md) | `fastforks.classification` | `model(image)` → logits, `top(k)` | `resnet50.tv2_in1k`, `efficientnet_b0.tv_in1k`, `vit_base_patch16_224.augreg2_in21k_ft_in1k` |
47
+ | [semantic segmentation](https://github.com/kleinicke/fastforks/blob/main/docs/models/segmentation.md) | `fastforks.segmentation` | `model(image)` → label map | `segformer-b0-ade20k`, `mask2former-swinl-ade20k`, `eomt-l-dinov2-ade20k` |
48
+ | [promptable segmentation: SAM / SAM 2](https://github.com/kleinicke/fastforks/blob/main/docs/models/promptable_segmentation.md) | `fastforks.promptable_segmentation` | `model(image, input_points=[[x, y]], input_labels=[1])` or `input_boxes=` → `masks [3, H, W]` bool + `iou_scores [3]` (one point) | `sam-vit-b`, `sam2.1-hiera-large` |
49
+ | promptable segmentation: SAM 3 concepts | `fastforks.promptable_segmentation` | `model(image, text="cat")` and / or exemplar boxes `input_boxes=` → every instance of the concept | `sam3` |
50
+ | [object detection](https://github.com/kleinicke/fastforks/blob/main/docs/models/detection.md) | `fastforks.detection` | `model(image)` → boxes, labels, scores | `faster-rcnn-r50-fpn-3x-coco`, `mask-rcnn-r50-fpn-3x-coco` |
51
+ | [feature backbones](https://github.com/kleinicke/fastforks/blob/main/docs/models/features.md) | `fastforks.features` | `model(image)` → token features, image embedding | `dinov2-vitb14`, `dinov3-vitl16`, `dinov3-convnext-small` |
52
+
53
+ The task links go to the model pages, which list every model of the task with its licences, accuracy, speed and
54
+ memory. Not sure which model to use? The
55
+ [overview](https://github.com/kleinicke/fastforks/blob/main/docs/overview.md) compares them per task and names the
56
+ fastest, the most accurate and the best commercially usable ones.
57
+
58
+ ```python
59
+ from fastforks import stereo
60
+
61
+ model = stereo.load("igev-stereo-sceneflow") # kernels on a supported NVIDIA GPU or Apple silicon, else portable
62
+ result = model("left.png", "right.png")
63
+ result.disparity # [H, W] float32 tensor, pixels
64
+ result.backend # which backend ran, on which device
65
+
66
+ cpu_model = stereo.load("igev-stereo-sceneflow", device="cpu") # also with a CUDA build of PyTorch
67
+ ```
68
+
69
+ One line per task (families built on timm, torchvision or transformers need that extra; see the install table below):
70
+
71
+ ```python
72
+ # needs: pip install "fastforks-core[torchvision]"
73
+ from fastforks import classification, depth, detection, segmentation
74
+
75
+ depth.load("depth-anything-v2-s")("room.jpg").inverse_depth # [H, W] float32 relative inverse depth
76
+ detection.load("rtdetrv2-s-coco")("street.jpg", score_threshold=0.5).to_list() # dicts: box, class_name, score
77
+ classification.load("resnet50.tv2_in1k")("cat.jpg").top(3) # [(class name, probability), ...]
78
+ segmentation.load("dinov2-s-linear-ade20k")("street.jpg").labels # [H, W] class index per pixel
79
+ ```
80
+
81
+ `mode="kernels"` or `mode="portable"` forces a backend; kernels raises with the reason if it cannot run here instead of
82
+ silently falling back. `fastforks bench igev-stereo-sceneflow` times both on your machine. For deployment, TensorRT can
83
+ be faster than kernels for a few models (see [export](https://github.com/kleinicke/fastforks/blob/main/docs/export.md)).
84
+ The [usage guide](https://github.com/kleinicke/fastforks/blob/main/docs/usage.md) has a quickstart per task and covers
85
+ precision, batches, video, several GPUs, `torch.compile`, ONNX and TensorRT export, and loading your own weights.
86
+
87
+ ## Install
88
+
89
+ Install PyTorch for your platform first ([pytorch.org](https://pytorch.org/get-started/locally/)); fastforks uses the
90
+ build you have, CUDA or CPU-only. Then:
91
+
92
+ ```
93
+ pip install fastforks # everything: all models + timm, torchvision, transformers, ONNX
94
+ pip install "fastforks[tensorrt]" # everything + TensorRT export
95
+
96
+ pip install fastforks-core # lean: every model whose code licence is permissive, no extra libraries
97
+ pip install "fastforks-core[nc]" # + models with non-commercial or GPL code (S2M2, FoundationStereo, MonSter, CoEx, ...)
98
+ pip install "fastforks-core[timm]" # libraries some model families are built on
99
+ pip install "fastforks-core[torchvision]"
100
+ pip install "fastforks-core[transformers]"
101
+ pip install "fastforks-core[onnx]" # ONNX export
102
+ pip install "fastforks-core[tensorrt]" # TensorRT export
103
+ pip install "fastforks-core[libs]" # timm, torchvision, transformers and ONNX at once
104
+ ```
105
+
106
+ Without an extra, every task works except these (`MissingDependencyError` names the extra when one is missing):
107
+
108
+ | Task | Needs |
109
+ | --- | --- |
110
+ | classification | `[timm]` (11 models) or `[torchvision]` (15 models) |
111
+ | segmentation | `[transformers]` (SegFormer, Mask2Former, ...); the other 10 models need none |
112
+ | detection | `[torchvision]` for the R-CNN models |
113
+ | stereo, depth, features, promptable segmentation, multi-view | none |
114
+ | ONNX / TensorRT export | `[onnx]` / `[tensorrt]` |
115
+
116
+ `pip install fastforks` pulls a default torch build, which may be CPU-only on your platform. For a CUDA build install torch
117
+ first from [pytorch.org](https://pytorch.org/get-started/locally/) (e.g. `pip install torch --index-url
118
+ https://download.pytorch.org/whl/cu130`); `python -c "import torch; print(torch.cuda.is_available())"` should print `True`.
119
+
120
+ From a git checkout (every model, like `fastforks`):
121
+
122
+ ```
123
+ uv pip install -e '.[libs]' # or pip install -e '.[libs]'; `pip install .` (no -e) works too
124
+ ```
125
+
126
+ `fastforks` is `fastforks-core[nc,libs]`; both install the same `import fastforks`. For commercial products start from
127
+ `fastforks-core`. Weights with a non-commercial licence (S2M2, FoundationStereo, but also `bridgedepth-sf` with
128
+ permissive code) are never downloaded unless you set `FASTFORKS_NONCOMMERCIAL=1`; `weights=PATH` uses a copy you have.
129
+ A model whose library is missing fails in `load` with the extra to install. Weights and kernels are downloaded on first use
130
+ into `~/.cache/fastforks` and checked against a recorded SHA-256; `fastforks download MODEL` fetches them ahead of
131
+ time, and [docs/docker.md](https://github.com/kleinicke/fastforks/blob/main/docs/docker.md) covers offline machines
132
+ and Docker images. Weights you already have are used in place: files in the Hugging Face hub cache (e.g. from
133
+ `hf download`) or in a directory on `FASTFORKS_WEIGHTS_PATH`, or one file passed as `load(..., weights=PATH)`.
134
+ Gated weights (e.g. DINOv3): accept the licence on the model's Hugging Face page, log in (`hf auth login`, or
135
+ `huggingface_hub.login()` in Python), and load the model; the download goes through `huggingface_hub`. fastforks never
136
+ handles your Hugging Face token.
137
+
138
+ Requirements: Python >= 3.11 and PyTorch >= 2.8. Metal kernels run on Apple silicon (see the usage guide). The CUDA kernels need Linux on x86-64, an NVIDIA GPU of compute
139
+ capability 8.0 or newer (RTX 30 series, A100 and later) and a driver >= 570. So far it is tested only on an
140
+ RTX 5060 Ti: `fastforks env` shows what your GPU would use, and
141
+ [Other GPUs](https://github.com/kleinicke/fastforks/blob/main/docs/OTHER_GPUS.md) explains how to measure it and send
142
+ us the numbers.
143
+
144
+ ## Models and licences
145
+
146
+ Many models are licensed for non-commercial use only. Each model page lists the code licence, the weights licence,
147
+ the training data and a commercial-use flag, which is `yes` only if both the code and the weights licence allow
148
+ commercial use. Each model directory keeps the original licence file, and weights are downloaded from the authors'
149
+ own hosts (a few from a mirror of the same files).
150
+
151
+ ```python
152
+ import fastforks
153
+ from fastforks import stereo
154
+
155
+ stereo.list_models(commercial="yes") # stereo models whose code and weights licences allow commercial use
156
+ print(fastforks.describe_models(stereo.list_models("igev*"))) # licences, and what blocks a "yes"
157
+ ```
158
+
159
+ Training-data terms (SceneFlow, KITTI, ImageNet, ...) are shown as a note next to the flag; the
160
+ [usage guide](https://github.com/kleinicke/fastforks/blob/main/docs/usage.md#licences-and-commercial-use) explains how
161
+ the flag is set. None of this is legal advice.
162
+
163
+ ## Command line
164
+
165
+ ```
166
+ fastforks list [PATTERN] [--task TASK] [--commercial yes|no|unclear] [--tier stable|experimental|deprecated] [--format text|json|csv]
167
+ fastforks info depth-anything-v2-s # one model in detail
168
+ fastforks download [MODEL ...] [--kernels] # fetch weights and kernels ahead of time
169
+ fastforks stereo run LEFT RIGHT --model MODEL --out DIR # a stereo model over many pairs (folders or globs)
170
+ fastforks bench igev-stereo-sceneflow [--mode auto|portable|kernels] [--size HxW] # portable and kernels side by side
171
+ fastforks export MODEL --format onnx|trt [--size HxW] [--fp16] [-o FILE]
172
+ fastforks doctor # which models can run here, and what blocks the others
173
+ fastforks env # versions, GPU, kernel binaries (for bug reports)
174
+ ```
175
+
176
+ `fastforks COMMAND --help` lists all options.
177
+
178
+ ## Licence
179
+
180
+ The fastforks core, the wrappers and our kernels are Apache-2.0 (LICENSE). Vendored model code keeps its original
181
+ licence (the `LICENSE*` file in each model directory), and so do our modifications of it.
182
+
183
+ ## Contributing
184
+
185
+ See [CONTRIBUTING.md](https://github.com/kleinicke/fastforks/blob/main/CONTRIBUTING.md); the checklist for adding a model
186
+ is there. What changed between releases: [CHANGELOG.md](https://github.com/kleinicke/fastforks/blob/main/CHANGELOG.md).
@@ -0,0 +1,4 @@
1
+ fastforks-0.1.0.dist-info/METADATA,sha256=I_4ccHYptxNtIZcJWDVg373Hgs4ZW6aEjexmxh_aKj0,12732
2
+ fastforks-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
3
+ fastforks-0.1.0.dist-info/licenses/LICENSE,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
4
+ fastforks-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS