pypto-case-loss-crossentropy

pypto-case-loss-crossentropy is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 37 tokens per session (524 once invoked), scanned A, original, Apache-2.0.

An example of a PyPTO kernel for calculating cross-entropy loss, a common machine-learning measure of prediction error. It processes predictions and target classes in tiles, applies softmax, selects the target probabilities, and returns one scalar loss.

In plain words
What is it for?
Use it as a reference when implementing a PyPTO CrossEntropyLoss kernel with prediction scores, integer class targets, softmax, indexed selection, reduction, and scalar output.
Why use it?
It shows how this calculation can be structured for PyPTO, including the required data type conversion and separate processing stages.

Skill for Claude CodeCodex

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

Good fit Use it as a reference when implementing a PyPTO CrossEntropyLoss kernel with prediction scores, integer class targets, softmax, indexed selection, reduction, and scalar output.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-case-loss-crossentropy"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-case-loss-crossentropy.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 37 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 524 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.00037 $0.00524
Opus 5.5 $0.00015 $0.00210
Sonnet 5.5 $0.00007 $0.00105
Haiku 4.5 $0.00004 $0.00052

Measured 3mo ago against content hash 19d8f43ca898, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

pypto-case-loss-crossentropy 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 3mo 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/cases/pypto-case-loss-crossentropy/SKILL.md · 46 lines

What it actually says

模式 D:Loss — CrossEntropyLoss

def create_cross_entropy_kernel(batch, num_classes):
    @pypto.frontend.jit(runtime_options=..., debug_options=...)
    def kernel(
        predictions: pypto.Tensor((batch, num_classes), pypto.DT_FP32),
        targets: pypto.Tensor((batch,), pypto.DT_INT64),
    ) -> pypto.Tensor((1,), pypto.DT_FP32):
        output = pypto.tensor([1], pypto.DT_FP32)
        # Phase 1: per-sample softmax + gather
        pypto.set_vec_tile_shapes(1024, 16)
        log_probs = pypto.log(pypto.softmax(predictions, dim=1))
        targets_i32 = pypto.cast(targets, pypto.DT_INT32)
        idx = pypto.unsqueeze(targets_i32, 1)
        picked = pypto.gather(log_probs, dim=1, index=idx)
        neg_picked = pypto.mul(picked, -1.0)
        # Phase 2: batch reduction
        pypto.set_vec_tile_shapes(2048, 8)
        total = pypto.sum(neg_picked, dim=0, keepdim=False)
        output[:] = total / batch
        return output
    return kernel

forward:assert → contiguous → 调 kernel → reshape(1,)

模式要点

  • 两段 tile:不同计算阶段用不同 tile 配置
  • pypto.cast(targets, DT_INT32) — INT64 输入需转 INT32
  • pypto.unsqueeze + pypto.gather — 按 index 取元素
  • pypto.mul(x, -1.0) — 取反的标准写法(规则 R2 的应用)
  • 标量输出:pypto.tensor([1], ...) + output[:] = scalar
  • 逐元素 loss(MSE/Huber 等)更简单:所有输入 reshape(-1) 用 1D kernel
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. 3mo ago First seen · 46 lines · 37 tokens per session scan A 19d8f43ca898

Subscribe to this mod's changes

pypto-case-loss-crossentropy is a skill published in the GitHub repository mindspore-ai/akg (269 stars, last pushed today), licensed Apache-2.0. It adds 37 tokens to every session and 524 once invoked, about $0.0001 per session on Opus 5.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

pypto-case-loss-crossentropy compared with skills from other repositories

pypto-case-loss-crossentropy next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
pypto-case-loss-crossentropymindspore-ai/akgSkill269todayApache-2.0A37Claude Code, Codex
torchdrugK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA64Claude Code
arboretoK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA55Claude Code, Codex
deepspot-mK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA70Claude Code
pyhealthK-Dense-AI/scientific-agent-skillsSkill59k3d agoMITA84Claude Code, Codex
nemo-mbridge-perf-expert-parallel-overlapNVIDIA/skillsSkill4.3ktodayApache-2.0A56Claude Code
tao-validate-recipe-transferNVIDIA/skillsSkill4.3ktodayApache-2.0A179Claude Code