Skip to content

new: add inference free splade#652

Merged
joein merged 1 commit into
mainfrom
inference-free-splade
Jul 22, 2026
Merged

new: add inference free splade#652
joein merged 1 commit into
mainfrom
inference-free-splade

Conversation

@joein

@joein joein commented Jul 20, 2026

Copy link
Copy Markdown
Member

the only thing remaining is to upload the model to qdrant hf

@joein
joein requested a review from KShivendu July 20, 2026 20:44
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an ONNX export experiment for the SPLADE document encoder with tokenizer metadata copying and Torch/ONNX parity validation. Introduces the IfSplade backend with lazy document-model loading, IDF-based query embeddings, ONNX output post-processing, and worker support. Registers the backend in sparse model discovery and adds canonical output and inference-free query tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding inference-free SPLADE support.
Description check ✅ Passed The description is related to the change set and mentions the model upload step.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch inference-free-splade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
experiments/if_splade_to_onnx.py (1)

45-51: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Pin a single revision across all downloads for reproducibility.

code_revision only pins the custom modeling code; the model weights (AutoModelForMaskedLM.from_pretrained), tokenizer, and idf.json (via hf_hub_download, lines 78-80) are all fetched from the default branch. If the upstream repo updates its vocab/idf files later, re-running this script could produce a model.onnx + idf.json + tokenizer combo that's inconsistent with what was validated by parity_check.

♻️ Suggested fix: pin one revision for everything
+MODEL_REVISION = "main"  # pin to a specific commit SHA once finalized
+
 def export(model_id: str, output_dir: Path, opset: int = 14) -> Path:
     output_dir.mkdir(parents=True, exist_ok=True)

     model = AutoModelForMaskedLM.from_pretrained(
-        model_id, trust_remote_code=True, code_revision=CODE_REVISION
+        model_id, revision=MODEL_REVISION, trust_remote_code=True, code_revision=CODE_REVISION
     )
     ...
-    tokenizer = AutoTokenizer.from_pretrained(model_id)
+    tokenizer = AutoTokenizer.from_pretrained(model_id, revision=MODEL_REVISION)
     ...
     for file_name in TOKENIZER_FILES:
-        local_path = hf_hub_download(repo_id=model_id, filename=file_name)
+        local_path = hf_hub_download(repo_id=model_id, filename=file_name, revision=MODEL_REVISION)

Also applies to: 78-83

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@experiments/if_splade_to_onnx.py` around lines 45 - 51, Pin a single revision
for every Hugging Face download in the script: pass the shared revision to both
AutoModelForMaskedLM.from_pretrained and AutoTokenizer.from_pretrained, and
reuse it in the hf_hub_download call that retrieves idf.json. Keep code_revision
separate for custom modeling code while ensuring the model, tokenizer, and IDF
data all resolve to the same validated repository revision.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fastembed/sparse/if_splade.py`:
- Around line 151-159: Update the eager initialization flow around
load_tokenizer and OnnxTextModel._load_onnx_model so the tokenizer loaded into
self.tokenizer and self.special_token_to_id is reused, or the second tokenizer
load is skipped. Preserve lazy_load behavior and ensure eager ONNX model
initialization still completes normally.

---

Nitpick comments:
In `@experiments/if_splade_to_onnx.py`:
- Around line 45-51: Pin a single revision for every Hugging Face download in
the script: pass the shared revision to both
AutoModelForMaskedLM.from_pretrained and AutoTokenizer.from_pretrained, and
reuse it in the hf_hub_download call that retrieves idf.json. Keep code_revision
separate for custom modeling code while ensuring the model, tokenizer, and IDF
data all resolve to the same validated repository revision.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2648919e-ba9d-4ec9-8748-e0d2f1ad6af8

📥 Commits

Reviewing files that changed from the base of the PR and between 8a8ea4f and 1d341bc.

📒 Files selected for processing (4)
  • experiments/if_splade_to_onnx.py
  • fastembed/sparse/if_splade.py
  • fastembed/sparse/sparse_text_embedding.py
  • tests/test_sparse_embeddings.py

Comment on lines +151 to +159
# The tokenizer and the idf table are lightweight and are required for query embedding,
# which does not involve any model inference, so they are loaded eagerly, while
# `lazy_load` only defers the initialization of the onnx model
self.tokenizer, self.special_token_to_id = load_tokenizer(model_dir=self._model_dir)
self.special_tokens_ids: set[int] = set(self.special_token_to_id.values())
self._token_id_to_idf = self._load_idf()

if not self.lazy_load:
self.load_onnx_model()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether OnnxTextModel._load_onnx_model itself (re)loads the tokenizer.
fd -e py onnx_text_model.py --exec cat -n {}

Repository: qdrant/fastembed

Length of output: 17592


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the Splade file and inspect the loader methods around the relevant lines.
ast-grep outline fastembed/sparse/if_splade.py --view expanded

echo "----"
cat -n fastembed/sparse/if_splade.py | sed -n '1,260p'

Repository: qdrant/fastembed

Length of output: 13466


Avoid loading the tokenizer twice on eager init. load_tokenizer(model_dir=...) runs here, then OnnxTextModel._load_onnx_model() loads it again on the default lazy_load=False path, so startup pays the same parse/I/O cost twice. Reuse the first load or skip the second one.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fastembed/sparse/if_splade.py` around lines 151 - 159, Update the eager
initialization flow around load_tokenizer and OnnxTextModel._load_onnx_model so
the tokenizer loaded into self.tokenizer and self.special_token_to_id is reused,
or the second tokenizer load is skipped. Preserve lazy_load behavior and ensure
eager ONNX model initialization still completes normally.

@KShivendu KShivendu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this :D

@joein
joein merged commit 0892291 into main Jul 22, 2026
18 of 25 checks passed
@joein
joein deleted the inference-free-splade branch July 22, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants