Metadata-Version: 2.4
Name: flashim
Version: 0.1.1
Summary: FlashIM: fast, quantized, multi-platform inference for image matching
Keywords: image matching,feature matching,quantization,fp8,int8,triton,pytorch
Author: lnexenl
License-Expression: Apache-2.0 AND MIT AND LicenseRef-DINOv3
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
License-File: licenses/DINOv3-License.md
License-File: licenses/RoMaV2-MIT.txt
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Requires-Dist: torch>=2.11,<2.12
Requires-Dist: torchvision>=0.26,<0.27
Requires-Dist: triton>=3.6,<3.7 ; sys_platform == 'linux'
Requires-Dist: einops>=0.8.1
Requires-Dist: numpy>=2.0
Requires-Dist: pillow>=12.0.0
Requires-Dist: safetensors>=0.5
Requires-Dist: tomli>=2.0 ; python_full_version < '3.11'
Requires-Dist: opencv-python>=4.12.0.88 ; extra == 'cv'
Requires-Dist: hardmatch>=1.0.0 ; extra == 'eval'
Requires-Dist: opencv-python>=4.12.0.88 ; extra == 'eval'
Requires-Dist: poselib>=2.0.4 ; extra == 'eval'
Requires-Dist: tqdm>=4.67.1 ; extra == 'eval'
Requires-Dist: tilelang==0.1.14 ; sys_platform == 'linux' and extra == 'tilelang'
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/lnexenl/FlashIM
Project-URL: Documentation, https://github.com/lnexenl/FlashIM/tree/main/docs
Project-URL: Source, https://github.com/lnexenl/FlashIM
Project-URL: Issues, https://github.com/lnexenl/FlashIM/issues
Project-URL: Changelog, https://github.com/lnexenl/FlashIM/blob/main/CHANGELOG.md
Provides-Extra: cv
Provides-Extra: eval
Provides-Extra: tilelang
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/lnexenl/FlashIM/main/assets/brand/lockup-dark@8x.png">
    <img alt="FlashIM" src="https://raw.githubusercontent.com/lnexenl/FlashIM/main/assets/brand/lockup-light@8x.png" width="560">
  </picture>
</p>

<p align="center">
  <b>Fast, quantized, multi-platform inference for image matching.</b><br>
  Dense and sparse matchers as native PyTorch ports, with FP8 / INT8 quantization and custom kernels.
</p>

<p align="center">
  <a href="https://github.com/lnexenl/FlashIM/blob/main/LICENSE">Apache-2.0</a> ·
  <a href="https://github.com/lnexenl/FlashIM/blob/main/docs/models.md">Models</a> ·
  <a href="https://github.com/lnexenl/FlashIM/blob/main/docs/benchmarks.md">Inference benchmark</a> ·
  <a href="https://github.com/lnexenl/FlashIM/blob/main/docs/configuration.md">Configuration</a> ·
  <a href="https://github.com/lnexenl/FlashIM/blob/main/docs/platforms.md">Platforms</a> ·
  <a href="https://github.com/lnexenl/FlashIM/blob/main/docs/architecture.md">Architecture</a>
</p>

FlashIM runs image-matching models faster than their reference implementations, without giving up measured accuracy.
Every model is a native PyTorch port checked against the upstream code. The speedups come from quantization (MXFP8,
INT8), fused kernels (Triton, TileLang, CUDA C++) and `torch.compile`.

- **Custom kernels are first-class.** Every op has a torch reference (the correctness oracle and universal fallback) and
  optional optimized implementations that are picked by platform and shape.
- **Quantization with evidence.** FP8 / INT8 presets are accepted by task-level pose AUC (MegaDepth-1500, ScanNet-1500,
  HardMatch), not by tensor `allclose`.
- **Multi-platform by design.** Device detection separates vendor, dispatch key and ISA features. NVIDIA from Ampere to
  Blackwell today; ROCm, NPU and XPU are planned.
- **One interface.** Every model loads with `flashim.load(name, preset)`, where the preset is `fp32`, `bf16`, `int8` or
  `fp8`, and matches with `model.match(a, b)`, which returns the same `Matches` for dense, detector-free and sparse models.

## Quick start

FlashIM is not on PyPI yet; install from source (Linux, Python 3.10 or newer, an NVIDIA GPU is recommended):

```bash
pip install "flashim[cv] @ git+https://github.com/lnexenl/FlashIM"   # or, in a checkout: uv sync --extra eval
```

The `cv` extra adds OpenCV (SIFT, ORB), `eval` the accuracy benchmarks' dependencies. Jetson (JetPack 6) installs from
[`requirements-jetson.txt`](https://github.com/lnexenl/FlashIM/blob/main/requirements-jetson.txt) (NVIDIA's torch build).

```python
import flashim

flashim.available_models()                                   # every registered name

model = flashim.load("romav2", "fp8", engine="compile-full", overrides={"arch.setting": "mega1500"})
m = model.match("a.jpg", "b.jpg", max_matches=5000)          # Matches: 5000 balanced samples of the dense warp
m.keypoints_A, m.keypoints_B, m.confidence                   # [N, 2] pixels of each original image, [N]
m.dense.warp_AB                                              # the full dense prediction (DenseMatchResult)

pipeline = flashim.load("raco-aliked-lightglue", "bf16", engine="compile")
m = pipeline.match("a.jpg", "b.jpg", resize=1024, max_matches=1024)   # Matches: 1024 keypoints per image
m.indices_A, m.features_A                                    # match indices into each image's keypoints

loma = flashim.load("loma-g")                                # DaD + LoMa descriptors + matcher
m = loma.match("a.jpg", "b.jpg", max_matches=4096)           # 4096 keypoints per image (default 2048)
```

`match(a, b, *, resize, max_matches, threshold)` is the same for every model: `resize` is the long side of the working
resolution, `max_matches` bounds the matches the model's own way (keypoints per image, the most confident matches, or
samples of a dense warp) and `threshold` is the model's match threshold. A model without the preset asked for builds the
nearest one it has (`fp8` -> `int8` -> `bf16` -> `fp32`), and a pipeline's preset applies to each of its components.
A usage example for every model is in [docs/models.md](https://github.com/lnexenl/FlashIM/blob/main/docs/models.md#usage-examples).
Image paths given to a model on CUDA are decoded on the GPU when they are JPEGs (nvJPEG);
`FLASHIM_IMAGE_DECODER=pil` decodes with PIL.

Weights download on first use into the torch hub checkpoint folder (`$TORCH_HOME/hub/checkpoints`) and are checked
against SHA-256 hashes pinned in `flashim/models/<model>/weights.py`; `checkpoint` or `FLASHIM_<MODEL>_CHECKPOINT` points to
a local file. See [docs/checkpoints.md](https://github.com/lnexenl/FlashIM/blob/main/docs/checkpoints.md).

## Models

[docs/models.md](https://github.com/lnexenl/FlashIM/blob/main/docs/models.md) lists every model with its presets and
default; the licenses are in [THIRD_PARTY_NOTICES.md](https://github.com/lnexenl/FlashIM/blob/main/THIRD_PARTY_NOTICES.md).

| category | models |
|---|---|
| Dense | `romav2`, `roma`, `roma-indoor`, `minima-roma`, `tiny-roma`, `ufm` |
| Dense 3D | `mast3r`, `dust3r` (FP16 compute under `bf16` / `int8` / `fp8`) |
| Detector-free | `loftr`, `minima-loftr`, `eloftr`, `xoftr` |
| Sparse extractors | `rdd`, `aliked`, `raco`, `raco-aliked`, `superpoint`, `disk`, `alike`, `xfeat`, `dedode`, `dedode-g`, `dad`, `ripe`, `ripepp`, `ripepp-aachen`, `ripepp-scared`, `sift`, `orb` |
| Sparse matchers and pipelines | `lightglue`, `<extractor>-lightglue`, `loma`, `superglue`, `superpoint-superglue`, `omniglue` |
| Sparse-to-dense | `flexglue` |

**Weight licenses.** Code is Apache-2.0, but weights keep their publishers' licenses and some are not open: `ufm`,
`mast3r`, `dust3r` (CC BY-NC-SA 4.0), `superpoint` (Magic Leap), `superglue` and `superpoint-superglue` (Magic Leap,
academic / non-profit research only), and `ripe`, `ripepp`, `ripepp-aachen`, `ripepp-scared`, `ripepp-lightglue`
(Fraunhofer academic-use license v2.0) are **non-commercial**; `romav2` and `flexglue` contain
DINOv3 weights under the DINOv3 License. Check [THIRD_PARTY_NOTICES.md](https://github.com/lnexenl/FlashIM/blob/main/THIRD_PARTY_NOTICES.md) before commercial use.

## Results

All numbers are from an **NVIDIA GeForce RTX 5070 Ti (`sm_120`)**. Latencies of every model under one protocol and the
MegaDepth-1500 / ScanNet-1500 accuracy gate (AUC@5 drop < 0.005 vs `bf16`) are in the
[inference benchmark](https://github.com/lnexenl/FlashIM/blob/main/docs/benchmarks.md).

**RoMaV2** (dense; `mega1500` 800² + 1024², both directions, forward only, RTX 5070 Ti `sm_120`):

| preset | `eager` | `compile-full` | vs `bf16` (`compile-full`) |
|---|---:|---:|---:|
| `bf16` | 348.5 ms | 194.3 ms | 1.00x |
| `fp8` | 110.7 ms | 106.5 ms | 1.82x |
| `int8` | 107.1 ms | 93.4 ms | 2.08x |

Pose AUC@5 vs the unoptimized `bf16` (3 seeds, MegaDepth-1500 / ScanNet-1500, `engine="compile"`): `fp8` -0.0044 / -0.0027,
`int8` -0.0032 / +0.0010 (0 FAIL under the paired-bootstrap gate). On the 900 deliberately hard HardMatch pairs `fp8` costs
0.0074 mAA@10px, the same as RoMaV2's own FP8 recipe.

**Other families** (`eager / compile`, same GPU, one image or one pair; sizes and every model in the benchmark):

| stage | `bf16` | `int8` | `fp8` |
|---|---:|---:|---:|
| `rdd` extract (1200 px, 4096 keypoints) | 31.8 / 25.3 ms | | 26.5 / 22.8 ms |
| `loma-g` pair (2 x extract + match, 1024 px) | 185.2 / 175.9 ms | 81.8 ms (eager) | 95.4 ms (eager) |
| `flexglue` `match_keypoints` (512x512) | 35.1 / 33.7 ms | 22.3 / 22.2 ms | 18.0 / 17.9 ms |

The reference RDD implementation without its CUDA extension runs out of memory on 16 GB.

## Configuring a run

The four presets are named partial configs; config files, dicts, dotted overrides and `load`'s keyword arguments
(`device`, `engine`, `strict`, `calibration`) layer on top.

```python
model = flashim.load("romav2", "fp8", overrides=["engine.kind=compile-full"])
model = flashim.load("raco-aliked-lightglue", "int8", config="run.toml")
flashim.resolve("rdd-lightglue", "fp8").to_dict()      # the config a build would use, without building
model.run_config.digest(), model.build_report          # what was asked for / what was actually applied
```

Unknown keys, passes and engines are errors; a pass the platform cannot run is skipped with a warning
(`optimize.strict=true` raises instead). See [docs/configuration.md](https://github.com/lnexenl/FlashIM/blob/main/docs/configuration.md).

## Platforms

`sm_120` (RTX 5070 Ti) is the primary target. `sm_90` (H20), `sm_89` (L20) and `sm_87` (Jetson AGX Orin) are tuned;
`sm_100` is compile-checked only; `sm_80` / `sm_86` are not tuned. A GPU without FP8 builds the nearest other preset
instead and says so in a warning and in `model.build_report.fallbacks`. Which model was tested on which GPU is in
[docs/platforms.md](https://github.com/lnexenl/FlashIM/blob/main/docs/platforms.md).

## Development

```bash
uv sync --extra eval                     # Python 3.12, torch 2.11 (cu130), triton 3.6
uv run pytest -m "not slow"              # unit / ops / quant
uv run pytest tests/parity               # bit-exactness vs the vendored upstream code (needs weights + GPU)
uv run python benchmarks/speed/forward.py --preset fp8 --engine compile
uv run python benchmarks/accuracy/run.py --dataset mega1500 --preset fp8 --seed 17
```

Agents and contributors: start with [AGENTS.md](https://github.com/lnexenl/FlashIM/blob/main/AGENTS.md) (layering rules,
how to add an op, backend, model or platform, and how changes are verified). The layout and op dispatch are described in
[docs/architecture.md](https://github.com/lnexenl/FlashIM/blob/main/docs/architecture.md).

## License

FlashIM is released under the Apache License 2.0 ([LICENSE](https://github.com/lnexenl/FlashIM/blob/main/LICENSE)), with two
exceptions inside the package: code ported from [RoMaV2](https://github.com/Parskatt/RoMaV2) (the RoMaV2 model and several
Triton kernels) is under RoMaV2's MIT license ([`licenses/RoMaV2-MIT.txt`](https://github.com/lnexenl/FlashIM/blob/main/licenses/RoMaV2-MIT.txt)),
and `flashim/models/romav2/dinov3.py` and `dpt.py` follow DINOv3 / DPT code by Meta under the DINOv3 License Agreement
([`licenses/DINOv3-License.md`](https://github.com/lnexenl/FlashIM/blob/main/licenses/DINOv3-License.md)). The package's
license expression is `Apache-2.0 AND MIT AND LicenseRef-DINOv3`. Model weights are downloaded from their publishers,
never shipped, and keep their upstream licenses (see the warning under [Models](#models)); the full list, including the
licenses of vendored test code and assets, is in [THIRD_PARTY_NOTICES.md](https://github.com/lnexenl/FlashIM/blob/main/THIRD_PARTY_NOTICES.md).

<p align="center">
  <img alt="" src="https://raw.githubusercontent.com/lnexenl/FlashIM/main/assets/brand/mark-pair.svg" width="64" height="64">&nbsp;&nbsp;
  <img alt="" src="https://raw.githubusercontent.com/lnexenl/FlashIM/main/assets/brand/mark-match-bolt.svg" width="64" height="64">&nbsp;&nbsp;
  <img alt="" src="https://raw.githubusercontent.com/lnexenl/FlashIM/main/assets/brand/mark-monogram.svg" width="64" height="64">
</p>
