acceleration-and-selection
Use optional Numba retrieval and CSC acceleration, NumPy/JAX top-k selection, and diagnose dependency or backend fallbacks in bm25s.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- acceleration-and-selection
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use optional Numba retrieval and CSC acceleration, NumPy/JAX top-k selection, and diagnose dependency or backend fallbacks in bm25s.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md6.3 KB
- 参考文档references/numba-workflows.md5.7 KB
- 参考文档references/troubleshooting.md7.5 KB
- 脚本scripts/numba_smoke.py4.9 KB
03 SKILL.md 正文
Acceleration and selection
Use this route when a local bm25s index needs optional Numba scoring/retrieval,
Numba-assisted CSC construction, NumPy/JAX top-k selection, or a diagnosis of
backend and optional-dependency behavior. Keep the ordinary indexing/retrieval
recipe in the core route; this route supplies the acceleration choices that are
safe to add to it.
Make the backend decision explicit
- The required path is CPU NumPy:
BM25(backend="numpy", csc_backend="numpy"), followed byretrieve(..., backend_selection="numpy"). The base package requires NumPy; optional speed packages are not a runtime prerequisite. backendselects scoring/retrieval execution."numba"requires Numba;"auto"resolves to Numba when the import is available and otherwise to NumPy. The resolved value is stored inretriever.backendat construction.csc_backendselects index construction:"numpy"is the dependency-light default,"scipy"usesscipy.sparse.csc_matrix, and"auto"resolves to SciPy when SciPy imports successfully and otherwise to NumPy. This choice is made while constructing the index, not while selecting top-k results.backend_selectionis a separate top-k selector. For a NumPy BM25 backend,"numpy","jax", and"auto"are meaningful."auto"uses JAX whenbm25s.selection.JAX_IS_AVAILABLEis true and NumPy otherwise. JAX is a CPU option here; this skill makes no CUDA or GPU-performance promise.- For a Numba BM25 backend, retrieval internally maps
backend_selection="auto"to"numba"; the Numba retrieval path requiresbackend_selection="numba". Do not combinebackend="numba"withbackend_selection="jax"or"numpy".
The complete parameter and error table is in references/api-reference.md. Use the bounded local checker at scripts/numba_smoke.py before benchmarking or changing a production configuration.
Install only what the chosen path needs
pip install bm25s # NumPy base path
pip install "bm25s[core]" # project core extras, including Numba
pip install "bm25s[indexing]" # SciPy CSC option
pip install "bm25s[selection]" # CPU JAX top-k option
The package metadata also exposes numba, scipy, and jax[cpu] through the
corresponding extras. full combines extras, but is not required for this
route. Install into the same interpreter that imports bm25s; report the
actual availability flags rather than assuming that an extra was installed.
Baseline, Numba, and selector recipes
Start with a baseline when correctness or portability matters:
retriever = bm25s.BM25(backend="numpy", csc_backend="numpy")
retriever.index(corpus_tokens, show_progress=False)
results = retriever.retrieve(
query_tokens, k=10, backend_selection="numpy", show_progress=False
)
For CPU Numba retrieval and optional Numba CSC construction, make compilation an explicit decision:
retriever = bm25s.BM25(
backend="numba", csc_backend="numpy", auto_compile=False
)
retriever.compile(activate_numba=True, warmup=False)
retriever.index(corpus_tokens, show_progress=False)
results = retriever.retrieve(
query_tokens, k=10, backend_selection="numba", show_progress=False
)
Call compile before index when Numba CSC construction should be used; call
it after loading an existing index when only retrieval scoring needs activation.
warmup=True runs small dummy CSC and scorer calls to pay JIT compilation before
the first real request. The first call can still have signature/cache overhead,
and Numba is CPU-only in this operating contract. See
references/numba-workflows.md for the timing,
thread, and fallback decisions.
For NumPy scoring with optional JAX selection:
retriever = bm25s.BM25(backend="numpy", csc_backend="numpy")
retriever.index(corpus_tokens, show_progress=False)
results = retriever.retrieve(
query_tokens, k=10, backend_selection="jax", show_progress=False
)
Use backend_selection="auto" only when a JAX-versus-NumPy choice is
acceptable. bm25s.selection.topk accepts one-dimensional score arrays and
raises ValueError for an invalid selector; an explicit JAX request raises
ImportError when JAX is unavailable. The Numba selector is a separate
bm25s.numba.selection.topk API and accepts only backend="numba".
Compile and fallback rules
auto_compileis a constructor control and defaults toTrue, but explicitcompile(...)is the reproducible choice when relying on JIT activation. This revision's constructor guard is environment-sensitive; withNUMBA_DISABLE_JITunset, inspection observed no automatic compiled wrapper despite the default. Do not infer compilation from the constructor flag; inspect or run a smoke retrieval.- If
NUMBA_DISABLE_JITis set, the scorer activation/warmup path is skipped. Unset it when JIT execution is intended. Keepauto_compile=Falsefor predictable setup and compile deliberately. - Missing Numba with
backend="auto"is a normal fallback to NumPy. Missing Numba withbackend="numba"orcompile(...)is an actionableImportError. - Missing SciPy with
csc_backend="auto"falls back to NumPy. Explicitcsc_backend="scipy"raisesImportError. - Missing JAX with selector
"auto"falls back to NumPy. Explicit"jax"raisesImportError; an invalid selector raisesValueError. - Do not present optional backends as CUDA support. If a dependency emits a GPU-availability warning but imports its CPU implementation, record that as CPU execution rather than claiming accelerator coverage.
For install/import, data/configuration, API/CLI, and workflow-specific failures, use references/troubleshooting.md. Do not use Hub/BEIR network examples as acceleration tests; keep checks local and bounded.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).