pypto-api

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

A quick reference for PyPTO's programming interface, including kernel decorators, tensors, data types, and tile configuration. PyPTO is a Python interface for describing tensor and kernel computations.

In plain words
What is it for?
Declaring PyPTO kernels and tensor types, creating outputs and accumulators, selecting data types, configuring vector or matrix tiles, switching tile layouts, and avoiding excessive tile counts.
Why use it?
It puts API signatures and important limits in one place, reducing mistakes when writing PyPTO kernels. It also explains tile-size constraints and when a computation may need to be split into loops and views.

Skill for Claude CodeCodex

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

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.

agentmods
npx agentmods add skills/mindspore-ai/akg/pypto-api
Any agent
npx skills add mindspore-ai/akg --skill pypto-api
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-api

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-api.svg)](https://agentmods.dev/skills/mindspore-ai/akg/pypto-api)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-api"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-api.svg" alt="Measured on agentmods" 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 1,576 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.01576
Opus 5 $0.00009 $0.00788
Sonnet 5 $0.00004 $0.00315
Haiku 4.5 $0.00002 $0.00158

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

Security

Grade A, and why

pypto-api 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 6d 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-api/SKILL.md · 117 lines

How it starts

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

PyPTO API 速查

Kernel 装饰器

@pypto.frontend.jit(
    runtime_options={"run_mode": _PYPTO_RUN_MODE},
    debug_options={"runtime_debug_mode": _PYPTO_RUNTIME_DEBUG_MODE},
)
def kernel(x: pypto.Tensor(shape_tuple, dtype)) -> pypto.Tensor(shape_tuple, dtype):
    ...

张量

API 用途 示例
pypto.Tensor(shape, dtype) 输入/输出类型标注 x: pypto.Tensor((m, k), pypto.DT_FP32)
pypto.tensor(shape_list, dtype) kernel 内创建输出 output = pypto.tensor([m, n], pypto.DT_FP32)
pypto.zeros(shape_list, dtype=) 零初始化张量(累加器) acc = pypto.zeros([1], dtype=pypto.DT_FP32)
pypto.full(shape, val, dtype, valid_shape=) 常量填充张量 ones = pypto.full(s, 1.0, pypto.DT_FP32, valid_shape=s)

数据类型:pypto.DT_FP32pypto.DT_INT32pypto.DT_INT64(INT64 仅用于输入标注)。

Tile 配置

API 约束
pypto.set_vec_tile_shapes(*shapes) 参数个数 = 被操作张量 rank
pypto.set_cube_tile_shapes(m, k, n, l1, split_k) 固定 5 参数

tile 双约束

  1. prod(tile_shape) ≤ 16384
  2. auto_tiles = prod(每维 ceil(shape[i]/tile[i])) ≤ 2048(每个 op)
  • 必须在任何计算操作之前调用。一个 kernel 内可多次切换 tile。
  • auto_tiles > 2048,优先改为 loop + view/assemble 分块实现。
  • vec tile 推荐(8192) (1D)、(1, 16384) (2D)、(1, 1, 16384) (3D)
  • cube tile 推荐set_cube_tile_shapes([128, 128], [32, 128], [256, 256], True, False)

分块

API 用途 约束
pypto.loop(start, end, step, name=, idx_name=) 编译期循环 不嵌套、尽量少用
pypto.view(tensor, shape, offset) 切片提取(等价 tensor[a:b, c:d] shape 各维为编译期常量,rank 不变,每维 ≤ 输入对应维
pypto.assemble(chunk, offset, output) 写回子块(等价切片赋值)

pypto.view 不是 reshape。它是 tensor[offset[0]:offset[0]+shape[0], ...] 的等价 API。不能改变维度数,不能改变维度排布。所有 reshape 必须在 forward 中用 torch 完成。

算术运算

运算符规则+ * 支持标量在任意位置;- / 要求 tensor 在左侧(1.0 - x crash)。 函数调用pypto.add/sub/mul/div 第一参数必须 Tensor。 一元取反 -x:不支持,用 pypto.mul(x, -1.0)x * (-1.0)。 切片赋值:output[:] = expr

数学函数

函数 说明
pypto.exp(x) 指数
pypto.log(x) 对数
pypto.sqrt(x) 平方根
pypto.abs(x) 绝对值
pypto.sigmoid(x) sigmoid
pypto.softmax(x, dim=) softmax
pypto.maximum(a, b) 逐元素最大,b 可以是标量:pypto.maximum(x, 0.0)
pypto.minimum(a, b) 逐元素最小,b 可以是标量:pypto.minimum(x, 0.0)

Read the full file on GitHub · 117 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. 6d ago First seen · 117 lines · 18 tokens per session scan A 48a44a183214

Subscribe to this mod's changes

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