backend-export-optimization
Use when selecting Sentence Transformers inference backends or exporting/optimizing models for PyTorch, ONNX, or OpenVINO. Covers backend="onnx"/"openvino", optional extras, model_kwargs, optimized and quantized artifacts, and export troubleshooting.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- backend-export-optimization
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use when selecting Sentence Transformers inference backends or exporting/optimizing models for PyTorch, ONNX, or OpenVINO. Covers backend="onnx"/"openvino", optional extras, model_kwargs, optimized and quantized artifacts, and export troubleshooting.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/backend-reference.md8.0 KB
- 参考文档references/troubleshooting.md5.6 KB
- 脚本scripts/backend_export_check.py7.3 KB
03 SKILL.md 正文
Backend Export Optimization
Use this sub-skill when a user asks how to speed up inference with backend-level model formats, diagnose ONNX/OpenVINO installation or loading failures, or prepare optimized/quantized model artifacts for local use or Hugging Face Hub pull requests.
Route Requests
- Choose
backend="torch"for the default PyTorch path, GPU dtype tweaks such asmodel_kwargs={"torch_dtype": "float16"}, or simplest compatibility. - Choose
backend="onnx"when the user installed theonnxoronnx-gpuextra and wants ONNX Runtime inference, optimized ONNX files, or dynamic int8 ONNX quantization. - Choose
backend="openvino"when the user installed theopenvinoextra and targets Intel/CPU OpenVINO inference or static OpenVINO quantization. - Use
model_kwargs={"provider": ...}for ONNX Runtime execution providers andmodel_kwargs={"file_name": ...}to load a specific exported, optimized, or quantized artifact. - Use
model.save_pretrained(...)after exporting a local model andmodel.push_to_hub(..., create_pr=True)for Hub models so future loads do not re-export.
Core References
- Backend workflow and API details:
references/backend-reference.md - Failure diagnosis and fixes:
references/troubleshooting.md - Environment/API check script:
scripts/backend_export_check.py
Quick Patterns
from sentence_transformers import SentenceTransformer
model = SentenceTransformer(
"sentence-transformers/all-MiniLM-L6-v2",
backend="onnx",
model_kwargs={"provider": "CPUExecutionProvider"},
)
embeddings = model.encode(["backend export smoke test"])
model.push_to_hub("sentence-transformers/all-MiniLM-L6-v2", create_pr=True)
from sentence_transformers import SentenceTransformer, export_optimized_onnx_model
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2", backend="onnx")
export_optimized_onnx_model(
model=model,
optimization_config="O3",
model_name_or_path="sentence-transformers/all-MiniLM-L6-v2",
push_to_hub=True,
create_pr=True,
)
Important Boundaries
- Backend export quantizes or optimizes the model runtime artifact; output-vector quantization for retrieval storage/search is a separate workflow owned by retrieval utilities.
- ONNX/OpenVINO exports convert the Transformer component. If using exported files outside Sentence Transformers, reproduce pooling, normalization, SPLADE pooling, or CrossEncoder activation yourself.
- Do not use this sub-skill for training, evaluator routing, or generic semantic-search recipes except to validate that an exported backend still produces expected inference outputs.
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).