triton-ascend-attention

triton-ascend-attention is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 122 tokens per session (873 once invoked), scanned A, original, Apache-2.0.

An optimization guide for Transformer attention, which turns query, key, and value tensors into context-aware outputs. It explains blocked computation, causal masking, and online softmax for Flash Attention.

In plain words
What is it for?
Use it to implement or optimize self-attention, cross-attention, masked attention, scaled dot-product attention, and Flash Attention on Ascend devices.
Why use it?
It avoids storing the full attention matrix, whose size grows with the square of the sequence length.

Skill for Claude CodeCodex

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

Good fit Use it to implement or optimize self-attention, cross-attention, masked attention, scaled dot-product attention, and Flash Attention on Ascend devices.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-attention"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-attention.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 122 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 873 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.00122 $0.00873
Opus 5 $0.00061 $0.00436
Sonnet 5 $0.00024 $0.00175
Haiku 4.5 $0.00012 $0.00087

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

Security

Grade A, and why

triton-ascend-attention 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 9d 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/triton-ascend/guides/triton-ascend-attention/SKILL.md · 88 lines

What it actually says

Attention 算子优化

标准 Attention 计算流程

标准的 Scaled Dot-Product Attention:

Attention(Q, K, V) = softmax(Q @ K^T / sqrt(d_k)) @ V

三个阶段

  1. QK^T 计算: scores = Q @ K^T / sqrt(d_k),计算注意力分数
  2. Softmax 归一化: attn_weights = softmax(scores),确保权重和为1
  3. 加权求和: output = attn_weights @ V,得到最终输出

标准实现的问题

# 朴素实现(内存开销大)
scores = (Q @ K.T) / sqrt(d_k)  # (seq_len, seq_len)
attn_weights = softmax(scores)   # 需要存储完整注意力矩阵
output = attn_weights @ V

问题:

  • 需要存储 (seq_len, seq_len) 的注意力矩阵
  • 内存占用: O(seq_len²)
  • 对于长序列(seq_len = 4096),内存占用巨大

Flash Attention 优化策略

Flash Attention 通过分块计算和在线 Softmax 避免存储完整注意力矩阵。

核心思想

  1. 分块计算: 将大矩阵分块处理,减少内存占用
  2. 在线 Softmax: 使用增量式 softmax 算法,分块计算,维护全局最大值和归一化因子
  3. 避免存储: 不存储完整注意力矩阵

在线 Softmax 算法

关键是维护全局统计量,逐块更新:

# 初始化全局统计量
m_i = -float("inf")  # 全局最大值
l_i = 0.0           # 全局 exp 和
acc = 0.0           # 输出累加器

# 分块处理
for start_n in range(0, seq_len, BLOCK_SIZE):
    # 1. 加载当前块的分数
    scores = tl.load(scores_ptr + start_n, mask=load_mask, other=-float("inf"))
    
    # 2. 更新全局最大值
    m_ij = tl.maximum(m_i, tl.max(scores, 0))
    
    # 3. 计算当前块的 exp 值(数值稳定化)
    scores = scores - m_ij
    p = tl.math.exp2(scores * 1.44269504)  # log2(e)
    
    # 4. 更新全局 exp 和
    l_ij = tl.sum(p, 0)
    alpha = tl.math.exp2((m_i - m_ij) * 1.44269504)
    l_i = l_i * alpha + l_ij
    
    # 5. 更新输出累加器
    acc = acc * alpha + p
    
    # 6. 更新全局最大值
    m_i = m_ij

# 最终归一化
acc = acc / l_i
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. 9d ago First seen · 88 lines · 122 tokens per session scan A 90b28a41c892

Subscribe to this mod's changes

triton-ascend-attention is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 122 tokens to every session and 873 once invoked, about $0.0006 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-09-03.

Related

Other skills, from other repositories

fs-notebook-tabs

A computer-science capstone: an on-device ML keyboard that predicts next words privately — problem, method, evaluation, and defense answers. Built as a decision-grade coursework defense deck for professor, defense committee.

nexu-io/open-design · 47 tokens

implementing-llms-litgpt

Implements and trains LLMs using Lightning AI's LitGPT with 20+ pretrained architectures (Llama, Gemma, Phi, Qwen, Mistral). Use when need clean model implementations, educational understanding of architectures, or production fine-tuning with LoRA/QLoRA. Single-file implementations, no abstraction layers.

davila7/claude-code-templates · 77 tokens

nanogpt

Educational GPT implementation in 300 lines. Reproduces GPT-2 (124M) on OpenWebText. Clean, hackable code for learning transformers. By Andrej Karpathy. Perfect for understanding GPT architecture from scratch. Train on Shakespeare (CPU) or OpenWebText (multi-GPU).

davila7/claude-code-templates · 65 tokens

rwkv-architecture

RNN+Transformer hybrid with O(n) inference. Linear time, infinite context, no KV cache. Train like GPT (parallel), infer like RNN (sequential). Linux Foundation AI project. Production at Windows, Office, NeMo. RWKV-7 (March 2025). Models up to 14B parameters.

davila7/claude-code-templates · 72 tokens

lesson-quiz

Test a learner on a single Claude Code tutorial lesson (01-10) with 10 questions, scoring answers and flagging weak spots. Use before, during, or after a lesson. Don't use for whole-tutorial assessment or explaining a topic instead of testing it.

luongnv89/claude-howto · 58 tokens

kaggle-learner

This skill should be used when the user asks to "learn from Kaggle", "study Kaggle solutions", "analyze Kaggle competitions", or mentions Kaggle competition URLs. Provides access to extracted knowledge from winning Kaggle solutions across NLP, CV, time series, tabular, and multimodal domains.

Galaxy-Dawn/claude-scholar · 69 tokens