pypto-pitfalls

pypto-pitfalls is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 18 tokens per session (2,862 once invoked), scanned A, original, Apache-2.0.

A list of PyPTO coding pitfalls and corrected patterns for tensor arithmetic, clamping, loss functions, factory parameters, and large matrix multiplications. PyPTO is a tensor-programming system with rules that differ from ordinary Python arithmetic.

In plain words
What is it for?
Use it to avoid common errors in PyPTO kernels, implement Huber loss and minimum-like operations, pass scalar settings correctly, and handle matrix multiplications where the inner dimension is larger than 65,535.
Why use it?
It highlights expressions that look valid but can fail because of PyPTO's operand-order and compile-time rules.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to avoid common errors in PyPTO kernels, implement Huber loss and minimum-like operations, pass scalar settings correctly, and handle matrix multiplications where the inner dimension is larger than 65,535.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/pypto-pitfalls
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 mindspore-ai/akg --skill pypto-pitfalls
Clone the repo
git clone --depth 1 https://github.com/mindspore-ai/akg

Made for: Claude Code, 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 pypto-pitfalls

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-pitfalls/github.svg)](https://agentmods.dev/skills/mindspore-ai/akg/pypto-pitfalls)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-pitfalls"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-pitfalls/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 pypto-pitfalls

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-pitfalls"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-pitfalls.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 18 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,862 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. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
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.00018 $0.02862
Opus 5 $0.00009 $0.01431
Sonnet 5 $0.00004 $0.00572
Haiku 4.5 $0.00002 $0.00286

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

Security

Grade A, and why

pypto-pitfalls 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 10d 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.

akg_agents/python/akg_agents/op/resources/skills/pypto/guides/pypto-pitfalls/SKILL.md · 219 lines

How it starts

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

PyPTO 常见陷阱

1. 运算符规则(最高频错误)

+ *:标量任意位置。- /:tensor 必须在左。函数调用:第一参数必须 Tensor。

1.0 + x            # OK(__radd__)
1.0 - x            # CRASH(__rsub__ 未实现)
1.0 / x            # CRASH(__rtruediv__ 未实现)
pypto.add(1.0, x)  # CRASH(函数调用标量在前)

# 1 - x 正确写法
x * (-1.0) + 1.0   # 推荐

# 标量之间用 Python 运算
neg_delta = -delta  # OK(delta 是闭包 float)

2. clamp / min(x, d) 实现

pypto.clamp 不可用。min(x, d) 用双重取反:-max(-x, -d)pypto.minimum(x, 0.0) 可用。

# min(abs_diff, delta) — delta 是闭包 float
neg_abs = pypto.mul(abs_diff, -1.0)
clipped = pypto.mul(pypto.maximum(neg_abs, -delta), -1.0)  # = min(abs_diff, delta)

Huber Loss 完整模式(必须用 clamp,不能简化):

diff = predictions - targets
abs_diff = pypto.abs(diff)
neg_abs = pypto.mul(abs_diff, -1.0)
clipped = pypto.mul(pypto.maximum(neg_abs, -delta), -1.0)  # min(|d|, delta)
half_sq = clipped * clipped * 0.5
loss = half_sq + abs_diff - clipped  # 完整 Huber 公式
total = pypto.sum(loss, dim=0, keepdim=True)
output[:] = total / flat_size

3. 工厂函数

标量参数(eps、slope、margin 等)必须作为工厂函数参数通过闭包传入 kernel。

3D+2D matmul 时,forward 展平后传展平维度 nm=N*M 给工厂,不要分别传 N、M。

4. matmul K > 65535

用逐元素乘法 + pypto.sum(a * b_broadcast, dim=1) 替代。forward 中 B.reshape(1, -1) 使其可广播。

5. 距离度量必须 sqrt

sum(diff*diff)平方距离,不是 L2 距离。TripletMarginLoss 等必须 pypto.sqrt(sum_sq + eps)

6. tile rank = tensor rank

set_vec_tile_shapes 参数个数必须等于被操作 tensor 的 rank。2D tensor 用 2D tile。

6.1 盲抄 tile 常量(尤其 16384)

示例里的 16384/8192 是经验候选,不是固定答案。必须按当前 shape 和归约维重算。

  • 常见误用:输入 (128, 4096) 却写 set_vec_tile_shapes(1, 16384)
  • 更合理候选:set_vec_tile_shapes(4, 4096)(归约轴不浪费,且 batch 并行更高)。

要点:

  • 优先避免明显 tile[i] > shape[i] 的“预算浪费”。
  • 示例代码只能借结构,不能照抄 shape/tile 数字。

6.2 把“少分段”误读成“归约轴越大越快”

“连续搬运达阈值后再调归约轴”是二级目标,但不是“归约轴 tile 越大越快”。

  • 常见误用:直接写 tile_hidden = hidden,追求归约轴一次覆盖。
  • 典型后果:UB/OoOSchedule 报错(即使语义正确也无法编译)。

正确做法:

  • 先满足 prod(tile_shape) <= 16384auto_tiles <= 2048
  • 若出现 UB/OoOSchedule 报错,优先降档:16384 -> 8192 -> 4096
  • auto_tiles > 2048,优先改为 loop 分块,不要硬塞更激进 tile。
  • 先让连续搬运达到约 1KB(经验阈值),再在达标候选里做归约轴甜点比较(常试 16/32/64)。

Read the full file on GitHub · 219 lines

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. 10d ago First seen · 219 lines · 18 tokens per session scan A c6a229c785c6

Subscribe to this mod's changes

pypto-pitfalls is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 18 tokens to every session and 2,862 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.

Related

Other skills, from other repositories

pypto-pitfalls

A reference for PyPTO syntax rules, including where scalar values and tensors may appear in expressions and function calls.

wenyi-li/awesome-agent-kernel-skills · 18 tokens

pypto-loop-view

A troubleshooting note for PyPTO programs that use `pypto.view`, explaining that its shape must be fixed when the code is compiled.

wenyi-li/awesome-agent-kernel-skills · 43 tokens

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.

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

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…

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

dd-code-generation

Use pup CLI for immediate Datadog operations or generate code for integration into applications.

DataDog/pup · 16 tokens

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…

huggingface/kernels · 93 tokens