trainingsample 0.1.0__tar.gz → 0.2.1__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 (45) hide show
  1. trainingsample-0.2.1/.envrc +15 -0
  2. trainingsample-0.2.1/.github/workflows/ci.yml +234 -0
  3. {trainingsample-0.1.0 → trainingsample-0.2.1}/.github/workflows/publish.yml +27 -30
  4. {trainingsample-0.1.0 → trainingsample-0.2.1}/.pre-commit-config.yaml +15 -3
  5. trainingsample-0.2.1/BENCHMARKS.md +112 -0
  6. {trainingsample-0.1.0 → trainingsample-0.2.1}/Cargo.lock +569 -81
  7. {trainingsample-0.1.0 → trainingsample-0.2.1}/Cargo.toml +16 -4
  8. {trainingsample-0.1.0 → trainingsample-0.2.1}/PKG-INFO +2 -2
  9. trainingsample-0.2.1/README.md +291 -0
  10. trainingsample-0.2.1/docs/API_COMPAT_CV2.md +357 -0
  11. {trainingsample-0.1.0 → trainingsample-0.2.1}/pyproject.toml +4 -4
  12. trainingsample-0.2.1/scripts/run_competitive_benchmarks.sh +34 -0
  13. trainingsample-0.2.1/setup-env.sh +34 -0
  14. trainingsample-0.2.1/src/core.rs +187 -0
  15. trainingsample-0.2.1/src/cropping.rs +183 -0
  16. trainingsample-0.2.1/src/cv_batch_ops.rs +462 -0
  17. trainingsample-0.2.1/src/cv_batch_ops_optimized.rs +402 -0
  18. trainingsample-0.2.1/src/cv_compat.rs +625 -0
  19. trainingsample-0.2.1/src/format_conversion_simd.rs +278 -0
  20. trainingsample-0.2.1/src/lib.rs +148 -0
  21. trainingsample-0.2.1/src/luminance.rs +317 -0
  22. trainingsample-0.2.1/src/luminance_simd.rs +1041 -0
  23. trainingsample-0.2.1/src/opencv_ops.rs +326 -0
  24. trainingsample-0.2.1/src/python_bindings.rs +1889 -0
  25. {trainingsample-0.1.0 → trainingsample-0.2.1}/src/tests.rs +101 -0
  26. trainingsample-0.2.1/src/true_batch_ops.rs +415 -0
  27. trainingsample-0.2.1/tests/test_performance_benchmarks.py +1007 -0
  28. {trainingsample-0.1.0 → trainingsample-0.2.1}/tests/test_python_bindings.py +1 -1
  29. trainingsample-0.1.0/.github/workflows/ci.yml +0 -203
  30. trainingsample-0.1.0/README.md +0 -142
  31. trainingsample-0.1.0/src/core.rs +0 -80
  32. trainingsample-0.1.0/src/cropping.rs +0 -77
  33. trainingsample-0.1.0/src/lib.rs +0 -35
  34. trainingsample-0.1.0/src/luminance.rs +0 -28
  35. trainingsample-0.1.0/src/python_bindings.rs +0 -226
  36. trainingsample-0.1.0/src/resize.rs +0 -96
  37. trainingsample-0.1.0/tests/test_performance_benchmarks.py +0 -514
  38. {trainingsample-0.1.0 → trainingsample-0.2.1}/.gitignore +0 -0
  39. {trainingsample-0.1.0 → trainingsample-0.2.1}/.rustfmt.toml +0 -0
  40. {trainingsample-0.1.0 → trainingsample-0.2.1}/LICENSE +0 -0
  41. {trainingsample-0.1.0 → trainingsample-0.2.1}/clippy.toml +0 -0
  42. {trainingsample-0.1.0 → trainingsample-0.2.1}/src/loading.rs +0 -0
  43. {trainingsample-0.1.0 → trainingsample-0.2.1}/tests/__init__.py +0 -0
  44. {trainingsample-0.1.0 → trainingsample-0.2.1}/tests/comprehensive_tests.rs +0 -0
  45. {trainingsample-0.1.0 → trainingsample-0.2.1}/tests/test_comprehensive.py +0 -0
@@ -0,0 +1,15 @@
1
+ # Environment variables for OpenCV Rust bindings
2
+ export DYLD_LIBRARY_PATH="/opt/homebrew/Cellar/llvm/21.1.1/lib:$DYLD_LIBRARY_PATH"
3
+ export LIBCLANG_PATH="/opt/homebrew/Cellar/llvm/21.1.1/lib"
4
+ export LLVM_CONFIG_PATH="/opt/homebrew/Cellar/llvm/21.1.1/bin/llvm-config"
5
+
6
+ # OpenCV environment variables
7
+ export OPENCV_LINK_LIBS="opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_highgui,opencv_imgcodecs,opencv_imgproc,opencv_ml,opencv_objdetect,opencv_photo,opencv_stitching,opencv_video,opencv_videoio"
8
+ export OPENCV_LINK_PATHS="/opt/homebrew/lib"
9
+ export OPENCV_INCLUDE_PATHS="/opt/homebrew/include/opencv4"
10
+
11
+ # Rust build optimization
12
+ export RUSTFLAGS="-C target-cpu=native"
13
+
14
+ # macOS deployment target - match current system
15
+ export MACOSX_DEPLOYMENT_TARGET="$(sw_vers -productVersion | cut -d. -f1,2)"
@@ -0,0 +1,234 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, develop ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ env:
10
+ CARGO_TERM_COLOR: always
11
+
12
+ jobs:
13
+ rust-tests:
14
+ name: Rust Tests
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ rust: [stable, beta]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Install OpenCV and LLVM dependencies
24
+ run: |
25
+ sudo apt-get update
26
+ sudo apt-get install -y pkg-config libopencv-dev clang libclang-dev llvm-dev
27
+ # Install LLVM 18 which has the proper libclang.so symlink
28
+ sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools libclang1-18 libclang-cpp18
29
+ # Set environment variables for LLVM 18
30
+ echo "LIBCLANG_PATH=/usr/lib/llvm-18/lib" >> $GITHUB_ENV
31
+ echo "LLVM_CONFIG_PATH=/usr/bin/llvm-config-18" >> $GITHUB_ENV
32
+ echo "LD_LIBRARY_PATH=/usr/lib/llvm-18/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
33
+ # Verify the key files exist
34
+ ls -la /usr/lib/llvm-18/lib/libclang.so
35
+ which llvm-config-18
36
+
37
+ - name: Install Rust toolchain
38
+ uses: dtolnay/rust-toolchain@master
39
+ with:
40
+ toolchain: ${{ matrix.rust }}
41
+ components: rustfmt, clippy
42
+
43
+ - name: Cache cargo registry
44
+ uses: actions/cache@v4
45
+ with:
46
+ path: ~/.cargo/registry
47
+ key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
48
+
49
+ - name: Cache cargo index
50
+ uses: actions/cache@v4
51
+ with:
52
+ path: ~/.cargo/git
53
+ key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
54
+
55
+ - name: Cache cargo target
56
+ uses: actions/cache@v4
57
+ with:
58
+ path: target
59
+ key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
60
+
61
+ - name: Check formatting
62
+ run: cargo fmt --all -- --check
63
+
64
+ - name: Run clippy
65
+ run: cargo clippy --all-targets --no-default-features --features python-bindings,simd,opencv -- -D warnings
66
+
67
+ - name: Run tests (no Python bindings)
68
+ run: cargo test --no-default-features --features simd,opencv
69
+
70
+ - name: Compile tests (Linux compatible features)
71
+ run: cargo test --no-default-features --features python-bindings,simd,opencv --no-run
72
+
73
+ python-tests:
74
+ name: Python Tests
75
+ runs-on: ubuntu-latest
76
+ strategy:
77
+ matrix:
78
+ python-version: ["3.11", "3.12"]
79
+
80
+ steps:
81
+ - uses: actions/checkout@v4
82
+
83
+ - name: Install OpenCV and LLVM dependencies
84
+ run: |
85
+ sudo apt-get update
86
+ sudo apt-get install -y pkg-config libopencv-dev clang libclang-dev llvm-dev
87
+ # Install LLVM 18 which has the proper libclang.so symlink
88
+ sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools libclang1-18 libclang-cpp18
89
+ # Set environment variables for LLVM 18
90
+ echo "LIBCLANG_PATH=/usr/lib/llvm-18/lib" >> $GITHUB_ENV
91
+ echo "LLVM_CONFIG_PATH=/usr/bin/llvm-config-18" >> $GITHUB_ENV
92
+ echo "LD_LIBRARY_PATH=/usr/lib/llvm-18/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
93
+ # Verify the key files exist
94
+ ls -la /usr/lib/llvm-18/lib/libclang.so
95
+ which llvm-config-18
96
+
97
+ - name: Set up Python ${{ matrix.python-version }}
98
+ uses: actions/setup-python@v4
99
+ with:
100
+ python-version: ${{ matrix.python-version }}
101
+
102
+ - name: Install Rust toolchain
103
+ uses: dtolnay/rust-toolchain@stable
104
+
105
+ - name: Install maturin (Linux/macOS)
106
+ run: pip install maturin[patchelf]
107
+
108
+ - name: Build Python package (Linux)
109
+ if: runner.os == 'Linux'
110
+ run: |
111
+ mkdir -p dist
112
+ maturin build --release --out dist --no-default-features --features python-bindings,simd,opencv
113
+
114
+ - name: Build Python package (macOS)
115
+ if: runner.os == 'macOS'
116
+ run: |
117
+ mkdir -p dist
118
+ maturin build --release --out dist --no-default-features --features python-bindings,simd,metal
119
+
120
+ - name: Install built package (Linux/macOS)
121
+ run: pip install dist/*.whl
122
+
123
+ - name: Install test dependencies
124
+ run: pip install pytest pytest-benchmark numpy pillow opencv-python
125
+
126
+ - name: Run Python tests
127
+ run: pytest tests/ -v
128
+
129
+ pre-commit:
130
+ name: Pre-commit hooks
131
+ runs-on: ubuntu-latest
132
+
133
+ steps:
134
+ - uses: actions/checkout@v4
135
+
136
+ - name: Install OpenCV and LLVM dependencies
137
+ run: |
138
+ sudo apt-get update
139
+ sudo apt-get install -y pkg-config libopencv-dev clang libclang-dev llvm-dev
140
+ # Install LLVM 18 which has the proper libclang.so symlink
141
+ sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools libclang1-18 libclang-cpp18
142
+ # Set environment variables for LLVM 18
143
+ echo "LIBCLANG_PATH=/usr/lib/llvm-18/lib" >> $GITHUB_ENV
144
+ echo "LLVM_CONFIG_PATH=/usr/bin/llvm-config-18" >> $GITHUB_ENV
145
+ echo "LD_LIBRARY_PATH=/usr/lib/llvm-18/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
146
+ # Verify the key files exist
147
+ ls -la /usr/lib/llvm-18/lib/libclang.so
148
+ which llvm-config-18
149
+
150
+ - name: Set up Python
151
+ uses: actions/setup-python@v4
152
+ with:
153
+ python-version: 3.11
154
+
155
+ - name: Install Rust toolchain
156
+ uses: dtolnay/rust-toolchain@stable
157
+ with:
158
+ components: rustfmt, clippy
159
+
160
+ - name: Install cargo-audit
161
+ run: cargo install cargo-audit
162
+
163
+ - name: Install pre-commit
164
+ run: pip install pre-commit
165
+
166
+ - name: Run pre-commit
167
+ run: pre-commit run --all-files
168
+
169
+ build-wheels:
170
+ name: Build wheels
171
+ runs-on: ${{ matrix.os }}
172
+ strategy:
173
+ matrix:
174
+ os: [ubuntu-latest, macos-latest]
175
+
176
+ steps:
177
+ - uses: actions/checkout@v4
178
+
179
+ - name: Install OpenCV and LLVM dependencies (Ubuntu)
180
+ if: runner.os == 'Linux'
181
+ run: |
182
+ sudo apt-get update
183
+ sudo apt-get install -y pkg-config libopencv-dev clang libclang-dev llvm-dev
184
+ # Install LLVM 18 which has the proper libclang.so symlink
185
+ sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools libclang1-18 libclang-cpp18
186
+ # Set environment variables for LLVM 18
187
+ echo "LIBCLANG_PATH=/usr/lib/llvm-18/lib" >> $GITHUB_ENV
188
+ echo "LLVM_CONFIG_PATH=/usr/bin/llvm-config-18" >> $GITHUB_ENV
189
+ echo "LD_LIBRARY_PATH=/usr/lib/llvm-18/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
190
+ # Verify the key files exist
191
+ ls -la /usr/lib/llvm-18/lib/libclang.so
192
+ which llvm-config-18
193
+
194
+
195
+
196
+ - name: Set up Python
197
+ uses: actions/setup-python@v4
198
+ with:
199
+ python-version: 3.11
200
+
201
+ - name: Install Rust toolchain
202
+ uses: dtolnay/rust-toolchain@stable
203
+
204
+ - name: Install maturin (Linux/macOS)
205
+ run: pip install maturin[patchelf]
206
+
207
+ - name: Install OpenCV (macOS)
208
+ if: runner.os == 'macOS'
209
+ run: |
210
+ # Install OpenCV and LLVM via Homebrew
211
+ brew install opencv llvm
212
+ # Set up LLVM environment for opencv-rust bindings (keg-only installation)
213
+ echo "LIBCLANG_PATH=/opt/homebrew/opt/llvm/lib" >> $GITHUB_ENV
214
+ echo "LLVM_CONFIG_PATH=/opt/homebrew/opt/llvm/bin/llvm-config" >> $GITHUB_ENV
215
+ echo "DYLD_LIBRARY_PATH=/opt/homebrew/opt/llvm/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
216
+ # Set up OpenCV environment
217
+ echo "OPENCV_LINK_LIBS=opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_highgui,opencv_imgcodecs,opencv_imgproc,opencv_ml,opencv_objdetect,opencv_photo,opencv_stitching,opencv_video,opencv_videoio" >> $GITHUB_ENV
218
+ echo "OPENCV_LINK_PATHS=/opt/homebrew/lib" >> $GITHUB_ENV
219
+ echo "OPENCV_INCLUDE_PATHS=/opt/homebrew/include/opencv4" >> $GITHUB_ENV
220
+
221
+ - name: Build wheels (Linux)
222
+ if: runner.os == 'Linux'
223
+ run: maturin build --release --out dist --no-default-features --features python-bindings,simd,opencv
224
+
225
+ - name: Build wheels (macOS)
226
+ if: runner.os == 'macOS'
227
+ run: maturin build --release --out dist --no-default-features --features python-bindings,simd,opencv,metal
228
+
229
+
230
+ - name: Upload wheels
231
+ uses: actions/upload-artifact@v4
232
+ with:
233
+ name: wheels-${{ matrix.os }}
234
+ path: dist/
@@ -17,16 +17,25 @@ jobs:
17
17
  with:
18
18
  python-version: '3.11'
19
19
 
20
- - name: Install FFmpeg dependencies
20
+ - name: Install OpenCV and LLVM dependencies
21
21
  run: |
22
22
  sudo apt-get update
23
- sudo apt-get install -y pkg-config libavutil-dev libavformat-dev libavcodec-dev libavdevice-dev libavfilter-dev libswscale-dev libswresample-dev
23
+ sudo apt-get install -y pkg-config libopencv-dev clang libclang-dev llvm-dev
24
+ # Install LLVM 18 which has the proper libclang.so symlink
25
+ sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools libclang1-18 libclang-cpp18
26
+ # Set environment variables for LLVM 18
27
+ echo "LIBCLANG_PATH=/usr/lib/llvm-18/lib" >> $GITHUB_ENV
28
+ echo "LLVM_CONFIG_PATH=/usr/bin/llvm-config-18" >> $GITHUB_ENV
29
+ echo "LD_LIBRARY_PATH=/usr/lib/llvm-18/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
30
+ # Verify the key files exist
31
+ ls -la /usr/lib/llvm-18/lib/libclang.so
32
+ which llvm-config-18
24
33
 
25
34
  - name: Build wheels
26
35
  uses: PyO3/maturin-action@v1
27
36
  with:
28
37
  target: ${{ matrix.target }}
29
- args: --release --out dist --find-interpreter --zig
38
+ args: --release --out dist --find-interpreter --zig --no-default-features --features python-bindings,simd,opencv
30
39
  sccache: 'true'
31
40
  manylinux: auto
32
41
  env:
@@ -39,31 +48,6 @@ jobs:
39
48
  name: wheels-linux-${{ matrix.target }}
40
49
  path: dist
41
50
 
42
- windows:
43
- runs-on: windows-latest
44
- strategy:
45
- matrix:
46
- target: [x64]
47
- steps:
48
- - uses: actions/checkout@v4
49
- - uses: actions/setup-python@v5
50
- with:
51
- python-version: '3.11'
52
- architecture: ${{ matrix.target }}
53
- - name: Build wheels
54
- uses: PyO3/maturin-action@v1
55
- with:
56
- target: ${{ matrix.target }}
57
- args: --release --out dist --find-interpreter --no-default-features --features python-bindings
58
- sccache: 'true'
59
- env:
60
- # Use stable ABI for forward compatibility
61
- PYO3_USE_ABI3_FORWARD_COMPATIBILITY: '1'
62
- - name: Upload wheels
63
- uses: actions/upload-artifact@v4
64
- with:
65
- name: wheels-windows-${{ matrix.target }}
66
- path: dist
67
51
 
68
52
  macos:
69
53
  runs-on: macos-latest
@@ -76,11 +60,24 @@ jobs:
76
60
  with:
77
61
  python-version: '3.11'
78
62
 
63
+ - name: Install OpenCV (macOS)
64
+ run: |
65
+ # Install OpenCV and LLVM via Homebrew
66
+ brew install opencv llvm
67
+ # Set up LLVM environment for opencv-rust bindings (keg-only installation)
68
+ echo "LIBCLANG_PATH=/opt/homebrew/opt/llvm/lib" >> $GITHUB_ENV
69
+ echo "LLVM_CONFIG_PATH=/opt/homebrew/opt/llvm/bin/llvm-config" >> $GITHUB_ENV
70
+ echo "DYLD_LIBRARY_PATH=/opt/homebrew/opt/llvm/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
71
+ # Set up OpenCV environment
72
+ echo "OPENCV_LINK_LIBS=opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_highgui,opencv_imgcodecs,opencv_imgproc,opencv_ml,opencv_objdetect,opencv_photo,opencv_stitching,opencv_video,opencv_videoio" >> $GITHUB_ENV
73
+ echo "OPENCV_LINK_PATHS=/opt/homebrew/lib" >> $GITHUB_ENV
74
+ echo "OPENCV_INCLUDE_PATHS=/opt/homebrew/include/opencv4" >> $GITHUB_ENV
75
+
79
76
  - name: Build wheels
80
77
  uses: PyO3/maturin-action@v1
81
78
  with:
82
79
  target: ${{ matrix.target }}
83
- args: --release --out dist --find-interpreter --no-default-features --features python-bindings
80
+ args: --release --out dist --find-interpreter --no-default-features --features python-bindings,simd,opencv,metal
84
81
  sccache: 'true'
85
82
  env:
86
83
  # Use stable ABI for forward compatibility
@@ -109,7 +106,7 @@ jobs:
109
106
  release:
110
107
  name: Release
111
108
  runs-on: ubuntu-latest
112
- needs: [linux, windows, macos, sdist]
109
+ needs: [linux, macos, sdist]
113
110
  steps:
114
111
  - uses: actions/download-artifact@v4
115
112
  with:
@@ -13,14 +13,14 @@ repos:
13
13
  - id: cargo-check
14
14
  name: Rust check
15
15
  description: Check Rust code with cargo check
16
- entry: cargo check --all-targets --all-features
16
+ entry: bash -c 'if [[ "$OSTYPE" == "darwin"* ]]; then cargo check --all-targets --features simd,opencv,python-bindings,metal; else cargo check --all-targets --features simd,opencv,python-bindings; fi'
17
17
  language: system
18
18
  files: \.rs$
19
19
  pass_filenames: false
20
20
  - id: clippy
21
21
  name: Rust clippy
22
22
  description: Lint Rust code with clippy
23
- entry: cargo clippy --all-targets --all-features
23
+ entry: bash -c 'if [[ "$OSTYPE" == "darwin"* ]]; then cargo clippy --all-targets --features simd,opencv,python-bindings,metal; else cargo clippy --all-targets --features simd,opencv,python-bindings; fi'
24
24
  language: system
25
25
  files: \.rs$
26
26
  pass_filenames: false
@@ -72,7 +72,7 @@ repos:
72
72
  - id: rust-test
73
73
  name: Rust tests
74
74
  description: Run Rust tests
75
- entry: cargo test --features video
75
+ entry: bash -c 'if [[ "$OSTYPE" == "darwin"* ]]; then cargo test --features simd,opencv,metal -- --test-threads=1; else cargo test --features simd,opencv -- --test-threads=1; fi'
76
76
  language: system
77
77
  files: \.rs$
78
78
  pass_filenames: false
@@ -89,3 +89,15 @@ repos:
89
89
  files: \.(py|rs)$
90
90
  pass_filenames: false
91
91
  stages: [pre-commit]
92
+
93
+ # Competitive benchmarks (CI only - too heavy for local precommit)
94
+ - repo: local
95
+ hooks:
96
+ - id: competitive-benchmarks
97
+ name: Competitive performance benchmarks
98
+ description: Run competitive benchmarks against OpenCV/NumPy
99
+ entry: bash -c 'if [[ "$CI" == "true" ]] && ([ -d "target/wheels" ] || python -c "import trainingsample" 2>/dev/null); then pytest tests/test_competitive_benchmarks.py -v --tb=short; else echo "Skipping competitive benchmarks (not in CI or bindings not available)"; fi'
100
+ language: system
101
+ files: \.(py|rs)$
102
+ pass_filenames: false
103
+ stages: [pre-commit]
@@ -0,0 +1,112 @@
1
+ # Competitive Performance Benchmarks
2
+
3
+ This library includes comprehensive benchmarks against industry-standard libraries (OpenCV, NumPy) to ensure competitive performance for real-world SFT (Supervised Fine-Tuning) workloads.
4
+
5
+ ## Benchmark Categories
6
+
7
+ ### 🖼️ High-Resolution Image Processing
8
+
9
+ **Target Workload**: 5120×5120 → 1024×1024 image processing pipeline
10
+ - **Input**: 5120×5120×3 images (26.2M pixels, ~78MB each)
11
+ - **Pipeline**: Center crop → Resize → Luminance calculation
12
+ - **Batch sizes**: 2-4 images (memory constrained)
13
+
14
+ ### 📊 Performance Targets
15
+
16
+ | Operation | Input Size | Target Performance | Baseline |
17
+ |-----------|------------|-------------------|----------|
18
+ | **Resize** | 5120×5120 → 1024×1024 | Match OpenCV bilinear | `cv2.resize()` |
19
+ | **Center Crop** | 5120×5120 → 2048×2048 | Match/exceed NumPy | Array slicing |
20
+ | **Luminance** | 1024×1024 | 1.5x+ faster than NumPy | Vectorized math |
21
+ | **Full Pipeline** | 5120×5120 → 1024×1024 | >0.5 images/sec | Combined ops |
22
+
23
+ ### 🎯 Quality Targets
24
+
25
+ - **Resize Quality**: PSNR >30dB vs OpenCV (excellent similarity)
26
+ - **Crop Accuracy**: Bit-exact match with NumPy center crop
27
+ - **Luminance Precision**: <0.1 difference vs NumPy reference
28
+
29
+ ## Running Benchmarks
30
+
31
+ ### Local Development
32
+ ```bash
33
+ # Install dependencies
34
+ pip install opencv-python pytest-benchmark psutil
35
+
36
+ # Build with optimizations
37
+ maturin develop --release --features "python-bindings,simd"
38
+
39
+ # Run competitive benchmarks
40
+ ./scripts/run_competitive_benchmarks.sh
41
+ ```
42
+
43
+ ### CI/CD Integration
44
+
45
+ Benchmarks run automatically in CI for:
46
+ - **Pull requests**: Performance regression detection
47
+ - **Main branch**: Performance tracking over time
48
+ - **Weekly schedule**: Long-term performance monitoring
49
+
50
+ ## Benchmark Architecture
51
+
52
+ ### Memory Efficiency
53
+ - Monitors RSS memory usage vs OpenCV
54
+ - Tests batch processing memory scaling
55
+ - Validates no memory leaks in pipelines
56
+
57
+ ### SIMD Optimization Validation
58
+ - Compares SIMD-enabled vs scalar fallback performance
59
+ - Tests x86-64 AVX2/AVX-512 and ARM64 NEON paths
60
+ - Validates CPU feature detection accuracy
61
+
62
+ ### Real-World Scenarios
63
+ - **SFT Data Processing**: High-res → training resolution pipeline
64
+ - **Batch Processing**: Multiple images with different operations
65
+ - **Memory Constraints**: Large images with limited RAM
66
+
67
+ ## Performance Philosophy
68
+
69
+ ### Why These Benchmarks Matter
70
+
71
+ 1. **Real-World Relevance**: SFT workloads use 5120×5120+ images, not toy 224×224
72
+ 2. **Competitive Pressure**: OpenCV and NumPy are highly optimized incumbents
73
+ 3. **User Experience**: Poor performance = adoption barriers
74
+ 4. **Resource Efficiency**: Training infrastructure costs scale with throughput
75
+
76
+ ### Performance vs Quality Tradeoffs
77
+
78
+ - **Resize**: Bilinear interpolation for speed, good quality balance
79
+ - **SIMD**: Aggressive optimization while maintaining numerical accuracy
80
+ - **Memory**: Batch processing for throughput vs memory pressure balance
81
+
82
+ ## Interpreting Results
83
+
84
+ ### Good Performance Indicators
85
+ - ✅ Resize: 1-2 images/sec for 5120×5120 → 1024×1024
86
+ - ✅ Crop: 10+ images/sec for 5120×5120 → 2048×2048
87
+ - ✅ Luminance: 1.5x+ faster than NumPy with SIMD
88
+ - ✅ Pipeline: >0.5 complete transformations/sec
89
+
90
+ ### Red Flags
91
+ - ❌ Slower than OpenCV resize (indicates poor SIMD utilization)
92
+ - ❌ Slower than NumPy crop (indicates unnecessary overhead)
93
+ - ❌ Memory usage >2x OpenCV (indicates memory leaks/inefficiency)
94
+ - ❌ Quality degradation (PSNR <30dB vs reference)
95
+
96
+ ## Future Enhancements
97
+
98
+ ### Planned Improvements
99
+ - GPU acceleration benchmarks (Metal/CUDA)
100
+ - More interpolation methods (bicubic, lanczos)
101
+ - Video processing pipeline benchmarks
102
+ - Multi-threaded batch processing optimization
103
+
104
+ ### Performance Tracking
105
+ - Historical performance database
106
+ - Regression detection and alerting
107
+ - Performance comparison across different hardware configurations
108
+ - Automated performance optimization recommendations
109
+
110
+ ---
111
+
112
+ **Goal**: Be the fastest, highest-quality image processing library for ML/SFT workloads while maintaining competitive memory usage and numerical accuracy.