-
Notifications
You must be signed in to change notification settings - Fork 0
β‘ Bolt: Replace array squared sum with einsum for performance #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stffns
wants to merge
2
commits into
main
Choose a base branch
from
bolt-einsum-optimization-15190560324862376738
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint (ruff + mypy) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.12" | ||
| cache: pip | ||
|
|
||
| - name: Install dev dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e ".[dev]" | ||
|
|
||
| - name: ruff check | ||
| run: ruff check snapvec/ tests/ | ||
|
|
||
| - name: mypy --strict | ||
| run: mypy --strict snapvec/ | ||
|
|
||
| test: | ||
| name: Test ${{ matrix.os }} / py${{ matrix.python-version }} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, macos-14, windows-latest] | ||
| python-version: ["3.10", "3.12"] | ||
| include: | ||
| - os: ubuntu-latest | ||
| python-version: "3.13" | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| cache: pip | ||
|
|
||
| - name: Install libomp (macOS) | ||
| if: runner.os == 'macOS' | ||
| run: brew install libomp | ||
|
|
||
| - name: Install package | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -e ".[dev]" | ||
|
|
||
| - name: Run tests | ||
| run: pytest -q --cov=snapvec --cov-report=term-missing | ||
|
|
||
| - name: Run examples smoke test | ||
| shell: bash | ||
| run: | | ||
| set -e | ||
| for ex in examples/quickstart.py \ | ||
| examples/pq_index.py \ | ||
| examples/ivf_pq.py \ | ||
| examples/filter_search.py \ | ||
| examples/save_load.py \ | ||
| examples/streaming_ingest.py; do | ||
| echo "=== $ex ===" | ||
| python "$ex" | ||
| done | ||
|
|
||
| - name: Upload coverage (ubuntu + py3.12 only) | ||
| if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: coverage-report | ||
| path: .coverage | ||
| if-no-files-found: ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- .github/workflows/ci.yml | ||
| +++ .github/workflows/ci.yml | ||
| @@ -19,6 +19,7 @@ | ||
| - name: Install dev dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| + pip install "numpy<2.5.0" | ||
| pip install -e ".[dev]" | ||
|
|
||
| - name: ruff check | ||
| @@ -47,6 +48,7 @@ | ||
| - name: Install package | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| + pip install "numpy<2.5.0" | ||
| pip install -e ".[dev]" | ||
|
|
||
| - name: Run tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of computing
c_squsingnp.einsuminside the loop for each subspacej, you can precompute the centroid norms for all subspaces at once outside the loop using a single 3Dnp.einsumcall. This is much more efficient and aligns with the optimization pattern already used insnapvec/_ivfpq.py(line 433).