pypto-loop-view

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

A rulebook for using PyPTO loops and views when view shapes must be known during compilation. A view is a different way of interpreting part of a tensor without changing its data.

In plain words
What is it for?
Use it to split tensors into looped chunks, choose batch sizes that divide the input, and assemble processed chunks back into an output tensor without invalid view shapes.
Why use it?
Using a runtime loop value as a view size can cause a compile-time error, so the guide shows safe fixed-size chunking patterns.

Skill for Claude CodeCodex

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

Good fit Use it to split tensors into looped chunks, choose batch sizes that divide the input, and assemble processed chunks back into an output tensor without invalid view shapes.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/pypto-loop-view
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-loop-view
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-loop-view

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-loop-view.svg)](https://agentmods.dev/skills/mindspore-ai/akg/pypto-loop-view)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-loop-view"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-loop-view.svg" alt="Measured on agentmods" height="20"></a>
Per session 43 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,297 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.00043 $0.01297
Opus 5 $0.00022 $0.00648
Sonnet 5 $0.00009 $0.00259
Haiku 4.5 $0.00004 $0.00130

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

Security

Grade A, and why

pypto-loop-view 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 7d 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-loop-view/SKILL.md · 124 lines

How it starts

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

Loop + View:编译期常量规则

致命错误:ValueError: Not concrete value

最常见的首次生成错误。所有 pypto.view 的 shape 参数必须是编译期常量(字面量或闭包变量)。

# WRONG — min() 含 loop 变量 offset,是运行时值
for idx in pypto.loop(0, num_iters, 1, ...):
    offset = idx * BASIC_BATCH
    current = min(BASIC_BATCH, total_size - offset)      # runtime!
    chunk = pypto.view(x, [current, n], [offset, 0])     # ValueError!

任何含 loop idx 的表达式都是运行时值,不能用于 view shape。

通用正确写法

方法 A:确保整除(推荐)

选择 BASIC_BATCH 使 total_size 可整除,或在 forward 中 assert 整除性:

def create_kernel(total_rows, cols, basic_batch):
    assert total_rows % basic_batch == 0
    num_iters = total_rows // basic_batch  # 闭包常量

    @pypto.frontend.jit(...)
    def kernel(x: pypto.Tensor((total_rows, cols), ...)) -> ...:
        output = pypto.tensor([total_rows, cols], pypto.DT_FP32)
        pypto.set_vec_tile_shapes(1, 8192)
        for idx in pypto.loop(0, num_iters, 1, name="LOOP", idx_name="idx"):
            off = idx * basic_batch
            chunk = pypto.view(x, [basic_batch, cols], [off, 0])
            result_chunk = chunk * 2.0  # 示例操作
            pypto.assemble(result_chunk, [off, 0], output)
        return output
    return kernel

class ModelNew(torch.nn.Module):
    def forward(self, x):
        total_rows = x.shape[0] * x.shape[1]
        # 调参由 loop_count 空间驱动:先试 16/32,再反推 basic_batch
        target_loop_count = 16
        assert total_rows % target_loop_count == 0
        basic_batch = total_rows // target_loop_count
        ...

方法 B:主循环 + 尾部

当无法保证整除时:

def create_kernel(total_rows, cols, basic_batch):
    full_iterations = total_rows // basic_batch
    tail = total_rows % basic_batch
    tail_offset = full_iterations * basic_batch
    # full_iterations, tail, tail_offset 都是闭包常量

    @pypto.frontend.jit(...)
    def kernel(x: pypto.Tensor((total_rows, cols), ...)) -> ...:
        output = pypto.tensor([total_rows, cols], pypto.DT_FP32)
        pypto.set_vec_tile_shapes(1, 8192)

        for idx in pypto.loop(0, full_iterations, 1, name="LOOP", idx_name="idx"):
            off = idx * basic_batch
            chunk = pypto.view(x, [basic_batch, cols], [off, 0])
            pypto.assemble(chunk * 2.0, [off, 0], output)

        if tail > 0:  # 编译期求值(tail 是闭包常量)
            tail_chunk = pypto.view(x, [tail, cols], [tail_offset, 0])
            pypto.assemble(tail_chunk * 2.0, [tail_offset, 0], output)
        return output
    return kernel

Read the full file on GitHub · 124 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. 7d ago First seen · 124 lines · 43 tokens per session scan A 07ff79e832b3

Subscribe to this mod's changes

pypto-loop-view is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 27d ago), licensed Apache-2.0. It adds 43 tokens to every session and 1,297 once invoked, about $0.0002 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

ai-loop

Runs a bounded spec-build-review development loop with explicit scope, stop conditions, and human approval gates for risky or ambiguous work.

sickn33/agentic-awesome-skills · 28 tokens

project-execution

Executes implementation plans with progress tracking, checkpoint validation, and quality gates. Use after planning is complete and tasks are ready to implement.

athola/claude-night-market · 31 tokens

software-implementation

Write the minimal production code needed to make failing TDD tests pass (Green phase of red-green-refactor). Use when failing tests exist and production code must be written or modified to satisfy them. Reads and interprets failing test output, discovers codebase conventions (module layout, naming, import patterns…

stencila/stencila · 124 tokens

architecture-paradigms

Selects and routes to the right architecture paradigm. Use when choosing patterns for a new system or comparing trade-offs before making architecture decisions.

athola/claude-night-market · 33 tokens

choosing-and-executing

Provides a toolkit for moving from deliberation to commitment and from commitment to results. Covers the cost of decision paralysis, the 70% rule for when to stop gathering information, implementation planning after the choice is made, transparency as a trust mechanism, handling challenges to decisions, and combating…

fatihguner/foreman · 118 tokens

kotter-change-model

Guides organizational change initiatives using Kotter's eight-step model: creating urgency, forming a guiding coalition, developing a vision, communicating the vision, empowering action, generating short-term wins, consolidating gains, and anchoring changes in culture. Use when leading a strategic pivot, implementing…

fatihguner/foreman · 90 tokens