pypto-optimization

pypto-optimization is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 63 tokens per session (4,080 once invoked), scanned A, original, Apache-2.0.

A set of PyPTO performance-tuning rules for tile sizes, loops, data reduction, and operations such as softmax, normalization, and loss calculations. A tile is a small block of tensor data processed together.

In plain words
What is it for?
Use it to tune reduction kernels, keep tile sizes within hardware and shape limits, improve continuous data transfers, decide when to add loop-based chunking, and compare candidate tile configurations.
Why use it?
It gives an order for choosing tile sizes and diagnosing compilation or performance problems instead of changing settings at random.

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-optimization.svg)](https://agentmods.dev/skills/mindspore-ai/akg/pypto-optimization)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-optimization"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 63 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,080 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.00063 $0.04080
Opus 5 $0.00032 $0.02040
Sonnet 5 $0.00013 $0.00816
Haiku 4.5 $0.00006 $0.00408

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

Security

Grade A, and why

pypto-optimization 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-optimization/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:连续搬运先达阈值,再在归约轴找甜点

对包含归约的算子(softmax、logsoftmax、sum/amax/amin,以及 mean=sum/count 语义)按以下优先级:

  • 对固定题型 shape=(16,256,256), dim=1,默认模板直接用 set_vec_tile_shapes(1, 16, 256)
  • 先满足硬约束:prod(tile_shape) <= 16384auto_tiles <= 2048
  • auto_tiles > 2048,优先引入 loop + view/assemble 分块,再做 tile 微调。
  • 若编译/验证出现 UB 或 OoOSchedule 相关报错,优先降 prod(tile_shape)(常见从 16384 -> 8192 -> 4096)。
  • 先让连续搬运达经验阈值contiguous_bytes(tile) >= 1KB(经验值,第一性能门槛)。
  • 在同等可编译约束下,未达 1KB 的候选默认淘汰,不能仅因“规约轴不分段”直接入选。
  • 只有当可编译候选都达不到 1KB 时,才在 <1KB 候选中比较规约轴分段与实测。
  • 达到阈值后,不要默认“规约轴越大越快”;对规约轴 tile 做候选实测(默认顺序 16 -> 32 -> 64),按实测选甜点。
  • tile 不浪费:优先让每一维 tile[i] <= shape[i]tile[i] 远大于对应维度通常不会增加有效并行,反而会浪费 tile 预算并抬高 auto-tiling 开销。
  • 禁止误读:不是“越连续越好”也不是“归约轴不切分”。连续搬运达标后,目标转为减少规约分段,而不是继续放大非规约轴 tile。

其中(关键,禁止误算):

  • contiguous_bytes(tile) = contiguous_tile_elems * dtype_bytes
  • contiguous_tile_elems一次连续搬运段里的 tile 元素数,不是原始 shape 元素数。
  • Vec 场景默认按最后一维估算:contiguous_tile_elems = tile[last_axis](不做转置/置换时)。
  • 连续搬运阈值判定前,优先满足 tile[last_axis] <= shape[last_axis];不要通过 tile > shape 做“折算达标”。
  • FP32 常用阈值:contiguous_tile_elems >= 256(约 1KB)
  • FP16/BF16 常用阈值:contiguous_tile_elems >= 512(约 1KB)
  • 反例:shape=(16,256,256), dim=1, tile=(1,256,64) 时,连续搬运按 tile[2]=64 算,仅 64*4=256B未达到 1KB

原因

  • 连续搬运不足时,访存碎片和跨步开销会先成为瓶颈。
  • 连续搬运达到高效区后,进一步放大通常边际收益很低。
  • 归约轴 tile 过大时,单 task 可能过胖(局部归约树更重、寄存器/流水压力更高)。
  • 归约轴 tile 过小时,分段与合并开销会上升。
  • 因此常见是非单调关系(U 型),需要在达标候选中找甜点,而不是单调追大。

示例 A:Softmax (16, 16384), dim=1

  • set_vec_tile_shapes(1, 8192):每行 2 段(优先)
  • set_vec_tile_shapes(2, 4096):每行 4 段
  • set_vec_tile_shapes(4, 4096):每行 4 段,且更多预算给了非归约轴

经验上,(1, 8192) 通常优于 (2, 4096)(4, 4096)

示例 B:Reduction (16, 64, 256, 256), dim=1

  • set_vec_tile_shapes(1, 16, 1, 256) / (1, 32, 1, 256) / (1, 64, 1, 256):均满足连续搬运达标,需做甜点比较。
  • set_vec_tile_shapes(1, 1, 16, 256):虽然连续搬运达标,但归约轴未被有效利用,通常是劣候选。

这个例子体现了层级规则:连续搬运先达标,达标后做归约轴甜点搜索。

示例 C:TripletMarginLoss Phase-1 (128, 4096), dim=1

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. 6d ago First seen · 219 lines · 63 tokens per session scan A f57f2afea546

Subscribe to this mod's changes

pypto-optimization is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 26d ago), licensed Apache-2.0. It adds 63 tokens to every session and 4,080 once invoked, about $0.0003 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

agent-platform-rag-engine-management

Manage and query Agent Platform RAG Engine Corpora and retrieve grounded contexts using the Google GenAI SDK. Use when listing RAG corpora or files, inspecting a corpus, retrieving contexts, or generating content grounded in a RAG corpus. Do not use for standard database queries (use SQL/Spanner skills), Google…

google/skills · 85 tokens

agent-platform-model-registry

Agent Platform Model Registry Management. Use when you need to upload, list, describe, update, or delete machine learning models (and their versions) in the Agent Platform Model Registry. Don't use for model training, model deployment to endpoints, or managing non-Agent Platform models.

google/skills · 60 tokens

foundry-config-setup

Resolve missing setup caused by a hardcoded Foundry project endpoint or model in a sample. Use when a sample fails because it uses a placeholder/hardcoded projectendpoint (for example "https://your-project.services.ai.azure.com") or a hardcoded model instead of reading them from the environment.

microsoft/agent-framework · 65 tokens

google-cloud-solution-agentic-analytics-spark-knowledge-catalog

Discovers requirements and generates guidance to design and deploy a governed, secure agentic-analytics solution for data that's distributed across Google Cloud, other cloud providers, or on-premises. Data that's outside Google Cloud (such as data from Databricks, Snowflake, Salesforce, SAP, or Oracle systems) is…

google/skills · 138 tokens

training-check

Interactively monitor training metrics from the current Codex session, periodically checking WandB or fallback logs for NaN, divergence, plateaus, and broken runs.

wanshuiyin/Auto-claude-code-research-in-sleep · 35 tokens

nemo-automodel-launcher-config

Configure NeMo AutoModel job launches for interactive runs, Slurm clusters, and SkyPilot cloud execution.

NVIDIA/skills · 30 tokens