model-inference-optimize

model-inference-optimize is a skill for Codex from majiayu000/spellbook. It costs 157 tokens per session (2,680 once invoked), scanned A, original, MIT.

A method for measuring and improving the speed, memory use, quality, and serving cost of machine-learning model inference. It covers workloads such as image, video, diffusion, and self-hosted language models while requiring experiments against a defined baseline.

In plain words
What is it for?
Use it to investigate low GPU utilisation, test TensorRT, ONNX, PyTorch, kernels, FP8, compilation, caching, or reduced sampling steps.
Why use it?
It replaces guesswork with profiling, quality checks, and service-level acceptance tests when inference is slow, expensive, or uses too much GPU memory.

Skill for Codex

Written for Codex: agents/openai.yaml present.

Good fit Use it to investigate low GPU utilisation, test TensorRT, ONNX, PyTorch, kernels, FP8, compilation, caching, or reduced sampling steps.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/majiayu000/spellbook/model-inference-optimize
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add majiayu000/spellbook --skill model-inference-optimize
Clone the repo
git clone --depth 1 https://github.com/majiayu000/spellbook

Made for: Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for model-inference-optimize

README.md
[![agentmods](https://agentmods.dev/badge/skills/majiayu000/spellbook/model-inference-optimize/github.svg)](https://agentmods.dev/skills/majiayu000/spellbook/model-inference-optimize)
Your own site
<a href="https://agentmods.dev/skills/majiayu000/spellbook/model-inference-optimize"><img src="https://agentmods.dev/badge/skills/majiayu000/spellbook/model-inference-optimize/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for model-inference-optimize

Your own site · 80×15
<a href="https://agentmods.dev/skills/majiayu000/spellbook/model-inference-optimize"><img src="https://agentmods.dev/badge/skills/majiayu000/spellbook/model-inference-optimize.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 157 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,680 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00157 $0.02680
Opus 5.5 $0.00063 $0.01072
Sonnet 5.5 $0.00031 $0.00536
Haiku 4.5 $0.00016 $0.00268

Measured 9d ago against content hash 6419c9a5bd8a, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

model-inference-optimize scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/model-inference-optimize/SKILL.md · 97 lines

How it starts

The opening of the file, as written. The whole thing — 97 lines — stays where its author put it; the contents beside it link to each section on GitHub.

模型推理优化系统

把明确的推理工作负载优化到可验证的结果。沿用同一任务定义、实验记录和验收标准,按瓶颈选择专项,不把所有优化技术轮流试一遍。

入口与资料

当前问题 从哪里开始 按需读取
模型尚未跑通、迁移后效果不对 任务 → 正确性对齐 专项方法 的「复现与后端迁移」
延迟高、GPU 利用率低、显存不足 任务 → 基线 → profile 专项方法的「测量」「显存与数据流」
换 attention/kernel、FP8 或 compile 先证明热点和实际运行路径 专项方法的「算子与编译」
减少 steps、换蒸馏模型或近似 decoder 先定义允许的质量变化 专项方法的「近似推理」
复用同类优化经验 按当前瓶颈选案例 脱敏案例,只读相关小节
已有优化要接入服务或证明真实收益 质量回归 → 完整请求 → 服务验收 专项方法的「质量评测」「服务与成本」

需要记录时复制 实验模板 到本轮产物目录,删去不适用的字段;普通 bug 修复可缩成一张对比表。

模型质量/性能对比沿用本技能。纯托管 API、Prompt、token/cache 命中或 agent 工具调用优化不进入下述 GPU 实验流程:先检查当前可用技能列表,仅在外部技能 llm-app-optimize 已安装时转交;未安装时,在当前对话中固定代表请求,记录端到端延迟、用量/费用和输出质量,一次修改一个因素,并复用应用已有的回归检查验收。

全产品竞品研究仅在外部技能 peerscope 已安装时转交;未安装时,在当前对话中明确产品对比问题,从官方资料收集功能、价格和使用限制,附来源与日期,并将未实测能力标为待验证。这两个外部技能均不是 Spellbook 安装前提,不要求为完成当前任务安装它们。

Operating Contract

  • Direct actions: 在请求范围内读代码、分析现有日志、修改本地实现并运行已授权的检查和实验。
  • Escalate before: 超出既有授权的收费运行、凭证修改、占用其他任务设备、生产变更或发布。已有授权覆盖时继续执行。
  • Evidence-backed pushback: profile 显示拟优化部分占比很低或任务规格被改变时,给出 trace/输出证据和更小的替代实验。
  • Feedback loop: 记录失败假设、质量回归和撤回原因;续跑先核对旧基线是否仍有效,再选择下一项实验。

1. 锁定任务和实际运行路径

  1. 核对目标仓库、cwd、worktree、commit、未提交改动和实际服务入口。不要把当前目录默认当成模型仓库。缺少目标模型或路径时只询问影响开工的缺口,同时整理已有证据。
  2. 从真实请求追到权重/adapter、scheduler、预处理、推理、后处理、编码和响应,记录实际加载的实现。核对参数是否被读取、provider/kernel 是否实际运行;import 成功或开关存在不算命中。
  3. 固定输入集合与哈希、输出尺寸/帧数/FPS/时长/音频、精度、seed、模型版本、GPU 型号与数量、软件栈、并发和计时边界。相同 seed 不保证跨后端或跨进程逐位一致。
  4. 写明主目标和质量约束,例如「同一 2K 视频热态请求更快,构图与颜色不退化」。区分允许数值误差、允许感知变化、允许更换模型/输出规格的范围。
  5. 使用已授权设备、时间和费用范围;不占用其他任务的 GPU、不重启现有服务或自动部署。已有授权不重复询问。没有 GPU 时完成静态定位和实验准备,性能结论留为未测。

2. 建立可信基线

  • 复用仓库 runner、数据集、profiler 和检查命令;没有可复现入口时只补当前任务需要的最小入口,不搭建通用平台。
  • 先保存真实输出并核验规格和基本质量。输入或参考未对齐时先修正确性,再优化性能。
  • 分列下载/加载、engine build/compile、首次推理、同一常驻进程热态请求和文件/API 返回。每次重启进程不算模型热态。
  • 保存逐次数据、失败/OOM、原始日志与同步方法。CUDA event 测 GPU 区间,同步后的 wall time 测实际完成时间;profiler 用于归因,无 profiler 运行用于最终成绩。
  • 资源允许时 warmup 后至少三次重复作为初步判断。收益接近波动时增加交错 A/B 或 ABBA,不挑最优一次。少量样本报原始值、中位数和范围,不称生产 p95。

Read the full file on GitHub · 97 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 97 lines · 157 tokens per session scan A 6419c9a5bd8a

Subscribe to this mod's changes

model-inference-optimize is a skill published in the GitHub repository majiayu000/spellbook (288 stars, last pushed 8d ago), licensed MIT. It adds 157 tokens to every session and 2,680 once invoked, about $0.0006 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-10-08.

Related

Other skills, from other repositories

dspy-parallel

Use when you have independent LM calls that can run concurrently — batch processing, fan-out patterns, or speeding up pipelines with no data dependencies between steps. Common scenarios - processing a batch of inputs through a DSPy module concurrently, fan-out patterns where multiple independent LM calls run at once…

lebsral/DSPy-Programming-not-prompting-LMs-skills · 171 tokens

arboreto

Infers candidate gene regulatory networks from bulk or single-cell expression data using AertsLab Arboreto GRNBoost2 and GENIE3. Use for transcription factor-target association ranking, compatible Dask execution, sparse expression inputs, and network stability checks.

K-Dense-AI/scientific-agent-skills · 55 tokens

deepspot-m

Generates transcriptome-wide virtual spatial transcriptomics from H&E histology with DeepSpot-M. Used for predicted log1p-CPM expression from 224x224 tiles at about 20x, querying the released protein-coding gene panel by symbol, and whole-slide prediction after resolution-aware tiling with histolab.

K-Dense-AI/scientific-agent-skills · 70 tokens

torchdrug

Builds and troubleshoots TorchDrug 0.2.1 workflows for molecular graphs, property prediction, self-supervised pretraining, molecule generation, retrosynthesis, protein representation learning, and knowledge graph reasoning. Use when code imports torchdrug or needs its datasets, models, tasks, or Engine.

K-Dense-AI/scientific-agent-skills · 64 tokens

pyhealth

Builds and validates PyHealth clinical machine-learning pipelines for EHR, signals, imaging, and medical codes. Use for PyHealth dataset loading, MIMIC-III/IV, eICU or OMOP prediction tasks, patient-level evaluation, mortality/readmission/length-of-stay modeling, medication recommendation, sleep staging, Trainer…

K-Dense-AI/scientific-agent-skills · 84 tokens

pick-a-pii-model

Select an on-device OpenMed PII model from the committed registry by language, runtime format, and size budget, then require recall validation before deployment. Use when an agent must choose a local PII detector for CPU, Apple Silicon, or a mobile export without relying on live model discovery.

maziyarpanahi/openmed · 64 tokens