visers 1.1.0__tar.gz

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.
Files changed (51) hide show
  1. visers-1.1.0/.github/workflows/ci.yml +139 -0
  2. visers-1.1.0/.github/workflows/python-packages.yml +79 -0
  3. visers-1.1.0/.gitignore +9 -0
  4. visers-1.1.0/ARCHITECTURE.md +73 -0
  5. visers-1.1.0/BENCHMARKS.md +145 -0
  6. visers-1.1.0/Cargo.lock +664 -0
  7. visers-1.1.0/Cargo.toml +44 -0
  8. visers-1.1.0/LICENSE +203 -0
  9. visers-1.1.0/PKG-INFO +83 -0
  10. visers-1.1.0/README.md +228 -0
  11. visers-1.1.0/assets/banner.webp +0 -0
  12. visers-1.1.0/assets/domain-comparison.png +0 -0
  13. visers-1.1.0/assets/nano-throughput-profile.png +0 -0
  14. visers-1.1.0/assets/pareto-speed-quality.png +0 -0
  15. visers-1.1.0/bindings/python/Cargo.toml +25 -0
  16. visers-1.1.0/bindings/python/README.md +70 -0
  17. visers-1.1.0/bindings/python/src/lib.rs +100 -0
  18. visers-1.1.0/bindings/python/tests/test_api.py +119 -0
  19. visers-1.1.0/bindings/python/visers/__init__.py +73 -0
  20. visers-1.1.0/bindings/python/visers/_native.pyi +8 -0
  21. visers-1.1.0/bindings/python/visers/py.typed +0 -0
  22. visers-1.1.0/bindings/python/visers_nano/__init__.py +14 -0
  23. visers-1.1.0/bindings/python/visers_nano/py.typed +0 -0
  24. visers-1.1.0/build.rs +110 -0
  25. visers-1.1.0/examples/nano_rgb.rs +186 -0
  26. visers-1.1.0/forge/README.md +15 -0
  27. visers-1.1.0/forge/export_vsn1.py +129 -0
  28. visers-1.1.0/forge/model.py +57 -0
  29. visers-1.1.0/pyproject.toml +23 -0
  30. visers-1.1.0/src/avx2/mod.rs +246 -0
  31. visers-1.1.0/src/avx2/pointwise.rs +241 -0
  32. visers-1.1.0/src/avx2/spatial.rs +315 -0
  33. visers-1.1.0/src/avx2/stem.rs +407 -0
  34. visers-1.1.0/src/bin/nano_image.rs +183 -0
  35. visers-1.1.0/src/image_io/api.rs +204 -0
  36. visers-1.1.0/src/image_io/batch.rs +65 -0
  37. visers-1.1.0/src/image_io/box_resize.rs +159 -0
  38. visers-1.1.0/src/image_io/decode.rs +190 -0
  39. visers-1.1.0/src/image_io/mod.rs +149 -0
  40. visers-1.1.0/src/image_io/orientation.rs +85 -0
  41. visers-1.1.0/src/image_io/resize.rs +84 -0
  42. visers-1.1.0/src/image_io/webp.rs +60 -0
  43. visers-1.1.0/src/lib.rs +526 -0
  44. visers-1.1.0/src/metrics.rs +69 -0
  45. visers-1.1.0/src/pool.rs +200 -0
  46. visers-1.1.0/src/scalar.rs +354 -0
  47. visers-1.1.0/tests/fixtures/oriented-animation.webp +0 -0
  48. visers-1.1.0/tests/fixtures/rgb-pattern.jpg +0 -0
  49. visers-1.1.0/tests/image_pipeline.rs +306 -0
  50. visers-1.1.0/tests/nano_parity.rs +269 -0
  51. visers-1.1.0/weights/nano_v1.bin +0 -0
@@ -0,0 +1,139 @@
1
+ name: CI and Release
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [main]
7
+ tags: ['v*']
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ defaults:
13
+ run:
14
+ shell: bash
15
+
16
+ jobs:
17
+ test:
18
+ name: Test Rust and CLI
19
+ runs-on: ubuntu-24.04
20
+ timeout-minutes: 10
21
+ steps:
22
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23
+ with:
24
+ persist-credentials: false
25
+
26
+ - name: Fetch locked dependencies
27
+ run: cargo +stable fetch --locked
28
+
29
+ - name: Run release tests
30
+ run: |
31
+ cargo +stable test --release --offline --all-targets
32
+ cargo +stable test --release --offline --all-targets --features image-files
33
+ cargo +stable test --release --offline --doc --features image-files
34
+ cargo +stable test --release --offline --all-targets --no-default-features --features dim-128,simd
35
+ cargo +stable test --release --offline --all-targets --no-default-features --features dim-64
36
+
37
+ - name: Encode an RGB frame with the CLI
38
+ run: |
39
+ dd if=/dev/zero of="$RUNNER_TEMP/frame.rgb" bs=49152 count=1 status=none
40
+ cargo +stable run --release --offline --example nano_rgb -- "$RUNNER_TEMP/frame.rgb" "$RUNNER_TEMP/embedding.f32"
41
+ test "$(wc -c < "$RUNNER_TEMP/embedding.f32")" -eq 1024
42
+
43
+ - name: Verify the installed Python wheel against the Rust CLI
44
+ run: |
45
+ cargo +stable build --release --locked --offline --features image-files --bin nano_image
46
+ python3 -m venv "$RUNNER_TEMP/python-api"
47
+ py="$RUNNER_TEMP/python-api/bin/python"
48
+ "$py" -m pip wheel --no-deps . --wheel-dir "$RUNNER_TEMP/wheels"
49
+ "$py" -m pip install "$RUNNER_TEMP"/wheels/visers-*.whl
50
+ VISERS_NANO_CLI="$PWD/target/release/nano_image" "$py" -m unittest discover -s bindings/python/tests -v
51
+
52
+ python-packages:
53
+ if: github.event_name == 'push'
54
+ uses: ./.github/workflows/python-packages.yml
55
+
56
+ release:
57
+ name: Publish GitHub release
58
+ if: startsWith(github.ref, 'refs/tags/v')
59
+ needs: [test, python-packages]
60
+ runs-on: ubuntu-24.04
61
+ timeout-minutes: 5
62
+ permissions:
63
+ contents: write
64
+ env:
65
+ TAG: ${{ github.ref_name }}
66
+ steps:
67
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
68
+ with:
69
+ persist-credentials: false
70
+
71
+ - name: Fetch locked dependencies
72
+ run: cargo +stable fetch --locked
73
+
74
+ - name: Package the Linux x86-64 CLI
75
+ run: |
76
+ version=$(cargo +stable metadata --offline --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "visers-nano") | .version')
77
+ if [[ "$TAG" != "v$version" ]]; then
78
+ echo "Tag $TAG must match Cargo version v$version" >&2
79
+ exit 1
80
+ fi
81
+
82
+ cargo +stable build --release --offline --example nano_rgb
83
+ package="$RUNNER_TEMP/package"
84
+ archive="$RUNNER_TEMP/visers-nano-$TAG-linux-x86_64.tar.gz"
85
+ mkdir -p "$package"
86
+ install -m 755 target/release/examples/nano_rgb "$package/nano_rgb"
87
+ install -m 644 LICENSE "$package/LICENSE"
88
+ tar -czf "$archive" -C "$package" nano_rgb LICENSE
89
+ echo "RELEASE_ARCHIVE=$archive" >> "$GITHUB_ENV"
90
+
91
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
92
+ with:
93
+ pattern: python-dist-*
94
+ path: ${{ runner.temp }}/python-dist
95
+ merge-multiple: true
96
+
97
+ - name: Publish the GitHub release
98
+ env:
99
+ GH_TOKEN: ${{ github.token }}
100
+ GH_REPO: ${{ github.repository }}
101
+ run: |
102
+ files=(
103
+ "$RELEASE_ARCHIVE"
104
+ assets/pareto-speed-quality.png
105
+ assets/domain-comparison.png
106
+ assets/nano-throughput-profile.png
107
+ "$RUNNER_TEMP"/python-dist/*.whl
108
+ "$RUNNER_TEMP"/python-dist/*.tar.gz
109
+ )
110
+ if published_assets=$(gh release view "$TAG" --json assets --jq '.assets[].name'); then
111
+ for file in "${files[@]}"; do
112
+ if ! grep -Fxq "$(basename "$file")" <<< "$published_assets"; then
113
+ gh release upload "$TAG" "$file"
114
+ fi
115
+ done
116
+ else
117
+ gh release create "$TAG" "${files[@]}" --verify-tag --notes-from-tag --title "Visers $TAG"
118
+ fi
119
+
120
+ pypi:
121
+ name: Publish visers to PyPI
122
+ if: startsWith(github.ref, 'refs/tags/v')
123
+ needs: release
124
+ runs-on: ubuntu-24.04
125
+ timeout-minutes: 10
126
+ environment:
127
+ name: pypi
128
+ url: https://pypi.org/project/visers/
129
+ permissions:
130
+ id-token: write
131
+ steps:
132
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
133
+ with:
134
+ pattern: python-dist-*
135
+ path: dist
136
+ merge-multiple: true
137
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
138
+ with:
139
+ skip-existing: true
@@ -0,0 +1,79 @@
1
+ name: Python distributions
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ permissions:
7
+ contents: read
8
+
9
+ defaults:
10
+ run:
11
+ shell: bash
12
+
13
+ jobs:
14
+ wheel:
15
+ name: Wheel on ${{ matrix.runner }}
16
+ runs-on: ${{ matrix.runner }}
17
+ timeout-minutes: 30
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ include:
22
+ - runner: ubuntu-24.04
23
+ target: x86_64
24
+ manylinux: '2_28'
25
+ - runner: ubuntu-24.04-arm
26
+ target: aarch64
27
+ manylinux: '2_28'
28
+ - runner: macos-15
29
+ target: aarch64
30
+ - runner: macos-15-intel
31
+ target: x86_64
32
+ - runner: windows-2025
33
+ target: x64
34
+ steps:
35
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
36
+ with:
37
+ persist-credentials: false
38
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
39
+ with:
40
+ python-version: '3.12'
41
+ - uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
42
+ with:
43
+ maturin-version: v1.16.0
44
+ target: ${{ matrix.target }}
45
+ manylinux: ${{ matrix.manylinux || 'auto' }}
46
+ args: --release --locked --out dist
47
+ - name: Test the installed wheel
48
+ run: |
49
+ python -m pip install dist/*.whl
50
+ python -m unittest discover -s bindings/python/tests -v
51
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
52
+ with:
53
+ name: python-dist-${{ matrix.runner }}
54
+ path: dist/*.whl
55
+ if-no-files-found: error
56
+
57
+ sdist:
58
+ name: Source distribution
59
+ runs-on: ubuntu-24.04
60
+ timeout-minutes: 15
61
+ steps:
62
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
63
+ with:
64
+ persist-credentials: false
65
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
66
+ with:
67
+ python-version: '3.12'
68
+ - name: Build and test the source distribution
69
+ run: |
70
+ python -m pip install maturin==1.16.0 twine
71
+ maturin sdist --out dist
72
+ python -m twine check --strict dist/*
73
+ python -m pip install dist/*.tar.gz
74
+ python -m unittest discover -s bindings/python/tests -v
75
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
76
+ with:
77
+ name: python-dist-sdist
78
+ path: dist/*.tar.gz
79
+ if-no-files-found: error
@@ -0,0 +1,9 @@
1
+ target/
2
+ *.f32
3
+ *.rgb
4
+ *.pt
5
+ *.onnx
6
+ __pycache__/
7
+ *.pyc
8
+ .venv/
9
+ /scripts/
@@ -0,0 +1,73 @@
1
+ # Visers Nano Architecture
2
+
3
+ Visers Nano takes 49,152 interleaved RGB bytes for a `128×128` image and returns an L2-normalized `f32` embedding. The model uses a MobileNetV4-Conv-Small-0.50 trunk, global average pooling, and a Matryoshka projection from 480 channels to 256, 128, or 64 dimensions.
4
+
5
+ ## Build and initialization
6
+
7
+ [Python Forge](forge/README.md) exports a folded W8 checkpoint to `VSN1`. The [build script](build.rs) reads `weights/nano_v1.bin` or the file specified by `VISERS_NANO_WEIGHTS`. It keeps the first `dim` projection rows with their scales and biases and embeds the resulting model in `.rodata`. The runtime normalizes the projected vector after this dimensionality reduction.
8
+
9
+ The default Cargo features are `dim-256` and `simd`. The build script selects the largest dimension if several dimension features are enabled. It also selects 256 when no dimension feature is enabled.
10
+
11
+ `NanoEncoder::baked()` loads the embedded model through `NanoEncoder::from_bytes()`. The loader checks the channel chain, convolution geometry, activation and residual sizes, and the connection between the final activation and the projection. Each stored weight expands to `f32` as `weight_i8 * scale`. The model uses one scale per output channel and executes in `f32`. For the bundled 256D model, the decoded weights and biases occupy about 1.75 MiB and the embedded model occupies about 489 KiB.
12
+
13
+ ## Inference path
14
+
15
+ The [Rust encoder](src/lib.rs) uses a lookup table for `(byte / 255 - mean) / std` for each RGB channel. The bundled model uses `mean = std = 0.5`. The following shapes describe the main stages of the bundled model. Activations use `height × width × channels` order.
16
+
17
+ | Stage | Output shape |
18
+ |---|---|
19
+ | `3×3` stride-2 stem and fused first block | `32×32×16` |
20
+ | Pointwise and `3×3` stride-2 convolutions | `16×16×48` |
21
+ | Inverted residual blocks | `8×8×48`, then `4×4×64` |
22
+ | Final `1×1` convolution | `4×4×480` |
23
+ | Global average pooling | `480` |
24
+ | Linear projection and L2 normalization | `dim` |
25
+
26
+ The fused stem keeps three rows of its `64×64×32` activation in a 24 KiB ring buffer. Later convolutions alternate between two activation buffers. The workspace also holds the saved residual, normalized RGB rows, and global pooling scratch. The bundled model's 64-byte-aligned workspace occupies about 271 KiB per caller or worker.
27
+
28
+ With the `simd` feature on x86-64, the encoder selects AVX2/FMA kernels when the CPU supports both features. The main pointwise kernel processes six pixels by 16 output channels, and the depthwise kernels clip padded taps once per output pixel and accumulate up to 64 channels in registers. The fused stem uses vector RGB normalization for the baked mean and standard deviation. Custom normalization uses the model's lookup table. The scalar path runs on other supported targets and provides a reference for [parity tests](tests/nano_parity.rs). The [benchmarks](BENCHMARKS.md) include timings for each stage.
29
+
30
+ The AVX2 implementation groups the [fused stem](src/avx2/stem.rs), [pointwise](src/avx2/pointwise.rs) and [spatial/depthwise convolutions](src/avx2/spatial.rs) by stage. The [scalar implementation](src/scalar.rs) uses the same model and workspace layout.
31
+
32
+ ## Image file pipeline
33
+
34
+ The optional [image pipeline](src/image_io/mod.rs) runs one file or encoded byte slice through format detection, decoding, EXIF orientation, BOX resizing and RGB inference. Fast mode applies EXIF transforms to the final thumbnail. Full mode applies them to the source raster before either resize pass. A worker reuses the compressed file buffer, decoded pixel allocation, resize scratch and Nano workspace across calls. At 128×128 the encoder can directly borrow the decoder's RGB buffer. Other pixel layouts can drop alpha or expand gray after the per-channel BOX filter. The low-level RGB path accepts its original packed input directly.
35
+
36
+ - **Fast** uses the largest JPEG IDCT reduction among 1/8, 1/4 and 1/2 that leaves at least 256 samples on the shorter axis. Opaque still WebP with both sides at least 256 decodes directly into a 128×128 RGB buffer. PNG requires full raster decompression. Remaining resize work uses a SIMD BOX filter for typical inputs.
37
+ - **Full** uses full-resolution decoding and the BOX pass order and fixed-point rounding used by Forge. See the [Rust implementation](src/image_io/box_resize.rs) and [Pillow 13 resampler](https://github.com/python-pillow/Pillow/blob/13.0.0/src/libImaging/Resample.c). Both modes fit the whole image to the square, retain the stored RGB under alpha, and take the first frame of animated GIF and WebP.
38
+
39
+ The [file batch runner](src/image_io/batch.rs) shares immutable model weights across scoped workers. Each worker reads, decodes and encodes one image at a time, and the caller participates. `encode_files` returns a result for each path. The higher-level `encode` and `encode_with_options` fill contiguous embedding rows and report the lowest failing input index. Decoder-side scaling counts toward decode time, while EXIF and the software filter count toward resize time.
40
+
41
+ The Python extension keeps immutable input bytes alive, releases the GIL and calls the same Rust batch API. When inference completes, NumPy takes ownership of the Rust output buffer and exposes it as a C-contiguous `(N, D)` matrix. The single-image helper returns a one-dimensional view. See the [Python API guide](bindings/python/README.md).
42
+
43
+ ## Allocation and batch execution
44
+
45
+ `encode_single_rgb()` initializes the embedded encoder once per process and the workspace once per calling thread. `NanoEncoder::encode_rgb()` accepts a reusable workspace and output buffer from the caller. Both paths avoid heap allocations in steady-state inference. `encode_batch_rgb()` collects the outputs into a `Vec` on the caller's thread.
46
+
47
+ `NanoSpinPool::new(encoder, threads)` counts the calling thread as one of the participants and gives each background worker its own workspace. The caller and workers claim image indexes from an atomic counter. Image `i` writes to `out[i * dim..(i + 1) * dim]`, so completion order has no effect on output order. The pool validates input and output buffers before dispatch. With background workers it serializes batches and waits for every worker before releasing access to the caller's buffers.
48
+
49
+ ## VSN1 binary format
50
+
51
+ Multi-byte fields are little-endian. The file starts with a 44-byte header followed by convolution records and the linear projection.
52
+
53
+ | Header offset | Type | Field |
54
+ |---:|---|---|
55
+ | 0 | `[u8; 4]` | Magic `VSN1` |
56
+ | 4 | `u32` | Version `1` |
57
+ | 8 | `u32` | Convolution record count |
58
+ | 12 | `u32` | Projection input channels |
59
+ | 16 | `u32` | Projection output dimensions |
60
+ | 20 | `[f32; 3]` | RGB normalization means |
61
+ | 32 | `[f32; 3]` | RGB normalization standard deviations |
62
+
63
+ Each convolution record starts with a 16-byte descriptor. The fields are stored in the following order.
64
+
65
+ | Type | Fields |
66
+ |---|---|
67
+ | `u16 × 2` | Input channels, output channels |
68
+ | `u8 × 8` | Kernel size, stride, padding, depthwise flag, ReLU flag, save-residual flag, add-residual flag, reserved byte |
69
+ | `u32` | Weight payload length in bytes |
70
+
71
+ The descriptor is followed by one `f32` scale and one `f32` bias per output channel, with the full scale array preceding the bias array. The signed `int8` weights follow in `[kernel_y][kernel_x][input_channel][output_channel]` order for regular convolutions and `[kernel_y][kernel_x][channel]` order for depthwise convolutions.
72
+
73
+ The projection record contains `head_out` scales, `head_out` biases, and `head_out × head_in` signed `int8` weights. Each weight row stores all input channels for one output dimension. The exporter is in [forge/export_vsn1.py](forge/export_vsn1.py).
@@ -0,0 +1,145 @@
1
+ # Visers Nano — Benchmarks & Verification
2
+
3
+ The RGB inference timings were measured on **Intel Core i7-8700K @ 3.70 GHz** (Coffee Lake, AVX2/FMA, 32 KiB L1d / 256 KiB L2 per core, 12 MiB L3), pinned with `taskset`, excluding disk I/O and JPEG/PNG decoding.
4
+
5
+ ![Speed vs quality, per task](assets/pareto-speed-quality.png)
6
+
7
+ ---
8
+
9
+ ## 1. Retrieval Quality
10
+
11
+ ![Per-task quality and throughput vs larger models](assets/domain-comparison.png)
12
+
13
+ ### A. `abstract-v2` Held-Out Test (`5,940` images: `1,686` art + `4,254` photo)
14
+
15
+ | Model | Backend | CPU P50 (ms) | Art Style | Art Genre | Cross-Genre Style | Photo (COCO) |
16
+ |---|---|---:|---:|---:|---:|---:|
17
+ | **Visers Nano (`W8`, `256D`)** | **Rust AVX2/FMA · 128px** | **0.431** | **0.7686** | **0.5291** | **0.6776** | **0.4126** |
18
+ | Visers v0.2 | Rust · 128px | 1.279 | 0.6451 | 0.3724 | — | 0.2082 |
19
+ | Visers v3 (`v0.3`) | Rust AVX2/FMA · 128px | 1.916 | 0.6688 | 0.4107 | 0.5888 | 0.2269 |
20
+ | CPUBone Nano (zero-shot) | ORT FP32 · 128px | 2.222 | 0.7160 | 0.4675 | 0.6081 | 0.3982 |
21
+ | CPUBone Nano (zero-shot) | ORT FP32 · 224px | 5.727 | 0.7332 | 0.4883 | 0.6203 | 0.4560 |
22
+ | CPUBone B0 (zero-shot) | ORT FP32 · 224px | 11.475 | 0.7304 | 0.4843 | — | 0.4903 |
23
+ | TinyCLIP 8M | ORT FP32 · 224px | 37.405 | 0.7741 | 0.5363 | — | 0.5152 |
24
+ | MobileCLIP2-S0 | ORT FP32 · 256px | 65.803 | 0.7718 | 0.5707 | — | 0.5953 |
25
+ | MobileCLIP2-S2 | ORT FP32 · 256px | 184.226 | 0.8019 | 0.5916 | — | 0.6274 |
26
+ | SigLIP2 Base (teacher) | ViT-B/16 · 224px | — | 0.8380 | 0.5907 | — | 0.6084 |
27
+
28
+ ### B. Strict Artist-Disjoint `visers-v6` Held-Out Test (`12,075` images: `9,576` art + `2,499` photo)
29
+
30
+ | Model | Dim | Precision | Art Style | Art Genre | Photo (COCO) | Selection Score |
31
+ |---|---:|---|---:|---:|---:|---:|
32
+ | Visers v6 (`both-s20261115`) | 256 | FP32 | 0.2575 | 0.4323 | 0.2444 | 0.2946 |
33
+ | **Visers Nano** | **256** | **W8** | **0.3587** | **0.6096** | **0.4181** | **0.4511** |
34
+ | **Visers Nano** | **128** | **W8** | — | — | — | **0.4501** |
35
+ | **Visers Nano** | **64** | **W8** | — | — | — | **0.4435** |
36
+
37
+ ### C. Out-of-Distribution Generalization (`Flowers102`: `1,020` train / `6,149` test)
38
+
39
+ | Model | Dim | kNN-5 | Ridge Top-1 |
40
+ |---|---:|---:|---:|
41
+ | Previous `spatial-bottleneck` (trained from scratch) | 128 | 0.1807 | 0.2683 |
42
+ | **Visers Nano (`W8`)** | **256** | **0.3706** | **0.5269** |
43
+
44
+ ---
45
+
46
+ ## 2. CPU Latency, Throughput & Memory
47
+
48
+ The runtime comparison uses the same 128 `128×128` RGB images (`validation.rgb` from the upstream training workspace, SHA-256 `ff37815083df93039770d149fd36e91e2b2f7cb9228393edf6b985cd5e934514`). Single-thread runs use `taskset -c 4`. Six-core runs use `taskset -c 0-5`, which selects six distinct physical cores on this CPU. Timings cover preprocessing and inference from in-memory RGB frames. Throughput uses the number of images divided by elapsed time. Reported figures are medians of three warmed runs. Retrieval scores and timing use separate splits.
49
+
50
+ ### Visers Nano (release, AVX2/FMA)
51
+
52
+ `--bench` times 640 warmed images per run (`128 × 5`). `--bench-batch 6` times 20 batches of 128 images through `NanoSpinPool`. Its P50 is the median batch time divided by the batch size. The 64D row is from the earlier single-thread run on the same corpus.
53
+
54
+ | Variant | Threads | Baked `.rodata` | P50 (ms) | P90 (ms) | P99 (ms) | Mean (ms) | Throughput (img/s) | Heap Allocs |
55
+ |---|---:|---:|---:|---:|---:|---:|---:|---:|
56
+ | `dim-256` | 1 | 500,572 B | **0.431** | 0.460 | 0.516 | 0.441 | **2,268.3** | **0** |
57
+ | `dim-64` | 1 | 406,876 B | **0.441** | 0.733 | 1.219 | 0.526 | **1,900.5** | **0** |
58
+ | `NanoSpinPool` (`dim-256`) | 6 | 500,572 B | **0.0752** | — | — | — | **13,224.2** | **0** |
59
+
60
+ ### Single-core RGB inference
61
+
62
+ The current 256D encoder measured **0.399 ms P50** on the i7-8700K. The same run set measured **0.438 ms** for the original engine at `3427657` and **0.383 ms** for an experimental build with additional pointwise and 3×3 kernels. The Rust and Python APIs use the 0.399 ms implementation.
63
+
64
+ Seven interleaved runs per build used `taskset -c 4` and `nano_rgb validation.rgb --bench`. Each run warmed the 128 RGB frames twice and timed five passes from RGB24 in memory through the normalized embedding. Values are medians of the seven per-run P50s. All three builds returned byte-identical embeddings for all 128 frames.
65
+
66
+ ### CPUBone Nano (ONNX Runtime FP32)
67
+
68
+ The `cpubone-native/encoder-128.onnx` and `fast-baselines/cpubone-nano/encoder.onnx` exports from `visers/artifacts/abstract-v2/` ran with ONNX Runtime 1.31.1 `CPUExecutionProvider`, full graph optimization and one inter-op thread. Each inference used batch size 1. Preprocessing applied ImageNet normalization and, for the 224px model, bicubic resize and center crop.
69
+
70
+ | Model input | 1 core P50 (ms) | 1 core (img/s) | 6 cores, 6 single-thread sessions (img/s) | 6 cores, 1 six-thread session (img/s) |
71
+ |---|---:|---:|---:|---:|
72
+ | `128×128` | 2.222 | 445.1 | **1,230.9** | 757.5 |
73
+ | `224×224` | 5.727 | 173.6 | **727.0** | 335.2 |
74
+
75
+ The single-session runs timed 640 images each. The six-session runs timed eight batches of 128 images, distributing each batch across six concurrent workers with one ORT session per worker. The throughput chart uses the six-session results for the 224px model.
76
+
77
+ ### Visers Nano and MobileCLIP2-S0 (ONNX Runtime FP32)
78
+
79
+ `visers/artifacts/nano-v1/nano-v1-mrl256.onnx` uses the trained W8 weights stored as FP32 and runs in FP32. Its timed preprocessing converts interleaved RGB to a normalized FP32 tensor using a reusable buffer. MobileCLIP2-S0 uses `fast-baselines/mobileclip2-s0/encoder.onnx` from `visers/artifacts/abstract-v2/` with its 256px bilinear preprocessing. It is the closest Art Style baseline in this comparison at `0.7718` nDCG@10 versus `0.7686` for Visers Nano.
80
+
81
+ | Model | 1 core (img/s) | 6 cores, 6 single-thread sessions (img/s) |
82
+ |---|---:|---:|
83
+ | Visers Nano 256D · 128px | 1,752.1 | 8,518.2 |
84
+ | MobileCLIP2-S0 · 256px | 16.1 | 78.0 |
85
+
86
+ Both models used the same ONNX Runtime settings as CPUBone Nano. For Visers Nano, each run timed 640 images on one core and 20 batches of 128 images on six cores. For MobileCLIP2-S0, each run timed 384 images on one core and eight batches of 128 images on six cores.
87
+
88
+ In the domain comparison, TinyCLIP 8M and MobileCLIP2-S2 use the earlier measured single-core throughput from `visers/reports/abstract-v2/fast-baselines.json` on the same RGB corpus.
89
+
90
+ ### Per-Stage Breakdown (`dim-256`, `--profile`, 640 runs)
91
+
92
+ Mean stage times from the run with the median total profile time of `444.6 µs`. MAC counts describe the nominal convolution shapes, including padding.
93
+
94
+ | Stage | MACs | Time (µs) | Share |
95
+ |---|---:|---:|---:|
96
+ | Fused `conv_stem` (`3→32`) + `blocks.0.0` (`32→16`) + `u8→f32` LUT | 8.26M | 147.72 | 33.2% |
97
+ | Pointwise `1×1` (27 layers) | 9.44M | 171.11 | 38.5% |
98
+ | Depthwise `3×3` / `5×5` (15 layers) | 1.06M | 73.63 | 16.6% |
99
+ | `conv3x3` (`blocks.1.0`, `16→48`) | 1.77M | 44.50 | 10.0% |
100
+ | Global Avg Pool + `Linear(480→256)` + L2 norm | 0.12M | 7.60 | 1.7% |
101
+
102
+ ---
103
+
104
+ ## 3. PyTorch `W8` ↔ Native Rust Numerical Parity
105
+
106
+ Measured across all 128 canonical `128×128` RGB images in `validation.rgb` (with `FTZ | DAZ` enabled in Rust):
107
+
108
+ | Matryoshka Dim | Max Abs Error | Min Cosine Similarity |
109
+ |---:|---:|---:|
110
+ | `256` | `8.34e-7` | `0.99999946` |
111
+ | `128` | `8.94e-7` | `0.99999952` |
112
+ | `64` | `8.94e-7` | `0.99999970` |
113
+
114
+ ---
115
+
116
+ ## 4. Image file to 256D embedding
117
+
118
+ The file benchmark starts with a file path and ends with an embedding in memory. The model is loaded once. File open/read, decode, EXIF orientation, resize and inference are timed. The OS file cache is warm. Process startup and output serialization are outside these timings.
119
+
120
+ | Input | Pillow + ORT P50, ms | Rust Full P50, ms | Rust Fast P50, ms | Rust Fast decode P50, ms |
121
+ |---|---:|---:|---:|---:|
122
+ | JPEG, 1920×1080 | 10.82 | 7.66 | 4.41 | 3.82 |
123
+ | PNG, 1920×1080 | 48.99 | 20.59 | 19.36 | 18.13 |
124
+ | WebP, 1920×1080 | 24.88 | 18.87 | 16.38 | 15.87 |
125
+ | 128 original art JPEGs, 512 px on the long side | 2.36 | 1.78 | 1.57 | 0.99 |
126
+
127
+ The 1080p set contains 12 images from the upstream `abstract-v1/images` directory, resized with Pillow BICUBIC and encoded as JPEG quality 88, RGB PNG compression level 4 and lossy WebP quality 84. The 12 are the first entries from `random.Random(47).sample(sorted(paths), 128)` over the JPEG paths. The original-size row uses all 128 files directly. The Rust and Python paths read the same files. Dimensions, file compressibility and storage latency affect these results.
128
+
129
+ The single-worker Rust runs used `taskset -c 4` on the i7-8700K with the release profile, AVX2/FMA, system libturbojpeg 3.2.0 and bundled libwebp. After warming the files, each of three measured batches traversed its input three times. Per-file medians use the last two traversals. Stage medians are independent. Pillow 13.0.0 used in-place EXIF transpose, RGB conversion as needed, BOX128 and lookup-table normalization to contiguous FP32 NCHW. ONNX Runtime 1.31.1 used the matching Nano W8-folded FP32 graph, one CPU thread, full graph optimization and prebound input/output. The Python comparison used one warm traversal and three measured traversals.
130
+
131
+ **Ready RGB and fresh CLI processes.** On the canonical 128-frame RGB corpus, the median of five interleaved single-core P50 measurements was 0.434 ms for the original Rust encoder (commit `3427657`), 0.404 ms for the updated RGB/depthwise kernels, and 0.469 ms for the native ORT C API with SIMD input preparation. All three used warmed models. Launching a fresh `nano_image` process and reading its JSON vector on stdout took 4.59 ms P50 for one original JPEG and 7.14 ms for one 1080p JPEG (30 launches each, warm file cache).
132
+
133
+ **Python API latency.** On the 128 original JPEGs, `visers_nano.encode_single(path)` returned a NumPy vector in **1.69 ms P50** (2.17 ms P90). Launching `nano_image --jobs 1` for each path and converting its JSON output to a NumPy vector took **4.75 ms P50** (5.48 ms P90). Both used fast mode, 256 dimensions, release builds with the same bundled codecs, and one pinned core on the i7-8700K. After a warm-up pass, three traversals alternated call order for each file, giving 384 measurements per interface. The Python process reused its model and decoder. The CLI timings include process startup, model initialization and the JSON round trip.
134
+
135
+ **Batch throughput.** The 36 mixed 1080p files in fast mode reached 73.0 images/s on one physical core and 394.2 images/s on six (`taskset -c 0-5`, `--jobs 6`). The original JPEGs reached 617.4 and 3,483.7 images/s respectively. Throughput uses whole batch wall time, including worker startup. Each worker decodes and infers a different image.
136
+
137
+ **Preprocessing fidelity.** On 200 files, Full produced the same embedding bytes as applying Pillow 13's EXIF transpose, RGB conversion and BOX128 followed by `nano_rgb`. The check includes all eight EXIF orientations, CMYK JPEG, transparency, grayscale/16-bit PNG, animated GIF/WebP and narrow sources. For the 12 large files per format, Fast cosine similarity against that reference was 0.99725 median / 0.98926 minimum for JPEG, 0.99994 / 0.99989 for PNG and 0.99881 / 0.99557 for WebP. These are per-image embedding comparisons.
138
+
139
+ To profile a local collection with the same stage boundaries, run the CLI on the source files directly.
140
+
141
+ ```bash
142
+ TURBOJPEG_SOURCE=pkg-config TURBOJPEG_DYNAMIC=1 cargo build --release --locked --features image-files --bin nano_image
143
+ taskset -c 4 target/release/nano_image --jobs 1 --profile -o fast.f32 images/*
144
+ taskset -c 4 target/release/nano_image --jobs 1 --full --profile -o full.f32 images/*
145
+ ```