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.
npx skills add mindspore-ai/akg --skill pypto-basicsgit clone --depth 1 https://github.com/mindspore-ai/akgWrote 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.
[](https://agentmods.dev/skills/mindspore-ai/akg/pypto-basics)<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-basics"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-basics/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.
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-basics"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-basics.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00014 | $0.02759 |
| Opus 5 | $0.00007 | $0.01380 |
| Sonnet 5 | $0.00003 | $0.00552 |
| Haiku 4.5 | $0.00001 | $0.00276 |
Grade A, and why
pypto-basics 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.
How it starts
The opening of the file, as written. The whole thing — 184 lines — stays where its author put it; the contents beside it link to each section on GitHub.
PyPTO 编程原则
原则 0:先抽取 Torch 基线的语义合同
写 PyPTO 前,先把 baseline forward 变成“可执行语义合同”,再做实现与优化。
最少做 5 件事:
- 写出数学式(谁参与计算、谁是被规约对象、输出定义是什么)。
- 核对 API 语义而不是变量名(
input/target/prediction这些名字经常误导)。 - 固化规约合同(
sum、batchmean、或mean语义=sum/count,并明确规约轴与keepdim)。 - 判断是否非对称(
A||B与B||A是否等价)。 - 做 1 组语义自检样例(优先用非对称输入,先验方向是否正确)。
注意:性能规则(tile/loop)只能在语义合同确定后应用,不能反向决定语义。
原则 1:静态 shape
kernel 一切在编译时确定。工厂函数封装 kernel,shape 和标量参数(eps、slope 等)作为闭包传入。forward 直接传 torch.Tensor。ModelNew.init 签名必须与原始 Model 一致,shape 在 forward 中获取。
补充(高优先级):
- benchmark 的
get_inputs/get_init_inputs在单次任务里是固定参数;把它当静态合同,不要过度通用化。 - 先做“固定参数抽取”:从题目文件读取本次
get_init_inputs的返回值,作为本次任务常量(例如dim=1)。 - 题目里的注释如
Example, change to desired ...视为数据集说明噪声,不是本次实现要求。 - 对固定
dim的任务,生成单一固定 dim kernel;不要在一个 kernel 里写if dim == 0/1/2分支。 - 若确实要支持多个 dim,使用多个工厂函数/多个 kernel 分别生成,不要把多语义揉进同一 kernel。
原则 2:forward 的职责
- Assert:
assert x.dim() == N、assert tuple(x.shape) == (...) - Reshape(如需):torch reshape 为 kernel 能处理的 shape
- 调用 kernel:传入 contiguous 张量,reshape 回原始 shape 返回
forward 内禁止 torch 计算。kernel 内不能 reshape。
输出语义(keepdim/是否 squeeze)要与 baseline 直接对齐;不要先改语义再靠额外 squeeze/unsqueeze 回补。
原则 3:选择维度
| 算子类型 | forward 策略 | kernel 维度 |
|---|---|---|
| Elementwise / 简单 Loss | reshape(-1) |
1D |
| GroupNorm / InstanceNorm | reshape(flat_batch, hidden) |
2D |
| BatchNorm / RMSNorm | reshape(B, C, -1) |
3D |
| Batched matmul(同 batch) | 保持 3D,不需要 loop | 3D |
| 2D Matmul | 保持 2D | 2D |
| 单轴归约 | 保持原始维度 | 原维 |
补充:
- Elementwise 算子无数据依赖,优先 flatten 为 1D;loop 仅由
auto_tiles > 2048触发,与维度无关。 - 保持高维的唯一理由是业务语义需要(如后续算子依赖布局),而非 tile 约束。
补充:
- 多轴规约若轴连续且中间结果不被其他算子使用,优先在 forward 合并为单轴后再规约(例如
H,W -> HW)。
原则 4:tile 双约束
prod(tile_shape)≤ 16384auto_tiles = prod(ceil(shape[i]/tile[i]))≤ 2048
tile 参数个数 = 被操作 tensor 的 rank。常用:
- 1D:
(8192)| 2D:(1, 16384)| 3D:(1, 1, 16384)或(1, 16, 256)(单轴 3D 归约常见起步) - matmul:
set_cube_tile_shapes([128, 128], [32, 128], [256, 256], True, False) - 核心红线:Skill/示例中的 shape、tile、BLOCK 常量(如 16384/8192/4096)只能作参考。必须按当前任务的输入维度重新计算,禁止直接照抄。
- 经验规则:优先避免明显
tile[i] > shape[i]的参数浪费;如确需使用,必须有明确理由(例如实测收益)。
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.
- 9d ago First seen · 184 lines · 14 tokens per session scan A cd17b09469a6
pypto-basics is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 29d ago), licensed Apache-2.0. It adds 14 tokens to every session and 2,759 once invoked, about $0.0001 per session on Opus 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-08-30.
Other skills, from other repositories
jupyter-notebook
Iterative Python via live Jupyter kernel (hamelnb).
bioservices
Unified Python interface to 40+ bioinformatics services. Use when querying multiple databases (UniProt, KEGG, ChEMBL, Reactome) in a single workflow with consistent API. Best for cross-database analysis, ID mapping across services. For quick single-database lookups use gget; for sequence/file manipulation use…
matlab
Build, review, migrate, and safely plan MATLAB or GNU Octave numerical workflows, including arrays, tabular/time data, tests, projects, graphics, MAT files, and explicit Python interoperability.
pennylane
Hardware-agnostic quantum ML framework with automatic differentiation. Use when training quantum circuits via gradients, building hybrid quantum-classical models, or needing device portability across IBM/Google/Rigetti/IonQ. Best for variational algorithms (VQE, QAOA), quantum neural networks, and integration with…
cuopt-numerical-optimization-api
LP, MILP, and QP (beta) with cuOpt — Python, C, and CLI. Use when the user is solving LP, MILP, or QP with any cuOpt interface.
rocm-kernels
Provides guidance for writing and benchmarking optimized Triton kernels for AMD GPUs (MI355X, R9700) on ROCm, targeting HuggingFace diffusers (LTX-Video, SD3, FLUX) and transformers. Core kernels: RMSNorm, RoPE 3D, GEGLU, AdaLN. Includes XCD swizzle, autotune, diffusers integration patterns, and LTX-Video pipeline…