fix: correct Vec::with_capacity over-allocation in post_process_splade - #283
Conversation
Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com>
|
@copilot Rename PR title as per semantic conventions. |
The commit message has been updated to |
|
@copilot Fix all workflow failures. |
…nks is nightly-only) Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com>
Fixed in the latest commit. The CI failures were all caused by the same pre-existing clippy lint ( |
There was a problem hiding this comment.
🟢 Approval recommended
The capacity fix is correct, and the additional refactor preserves existing behavior.
Pull request overview
Fixes excessive per-row vector allocation in SPLADE post-processing.
Changes:
- Sizes SPLADE vector capacities using each row’s length.
- Refactors BGE-M3 weight-byte conversion and suppresses its Clippy lint.
File summaries
| File | Description |
|---|---|
src/sparse_text_embedding/impl.rs |
Corrects SPLADE allocation capacity. |
src/sparse_text_embedding/bgem3_weights.rs |
Refactors byte-chunk conversion. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@copilot fix the CI failure. |
Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com>
Fixed in commit |
|
@copilot Fix the CI failure. |
Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com>
Fixed in commit |
|
@copilot Fix the CI failure. |
Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com>
Fixed in commit |
#283) * Fix Vec::with_capacity over-allocation in post_process_splade Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com> * fix: suppress chunks_exact_to_as_chunks lint in bgem3_weights (as_chunks is nightly-only) Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com> * fix: remove unsupported clippy allow attribute Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com> * fix: replace chunks_exact with as_chunks in bgem3 weight parsing Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com> * test: stabilize hf-hub embedding assertions across CI environments Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Anush008 <46051506+Anush008@users.noreply.github.com>
Summary
Fixed a bug in
post_process_spladewhereVec::with_capacity(scores.len())was used to pre-allocate per-row vectors, butscores.len()returns the total element count of the 2D array (batch_size × vocab_size) rather than the per-row length (vocab_size).Changes
src/sparse_text_embedding/impl.rs: Changed bothVec::with_capacity(scores.len())calls toVec::with_capacity(row_scores.len())inside thepost_process_spladefunction.Impact
With a batch size of N and a vocabulary size of V, each row was pre-allocating N×V slots instead of V. For a typical SPLADE model (vocab ≈ 30 000) and a batch of 8, this wasted ~30 MB of heap per batch call. The over-allocated memory was immediately dropped after each
SparseEmbeddingwas returned, but it caused unnecessary allocator pressure and degraded performance under load.