optimizing-attention-flash

optimizing-attention-flash is a skill for Claude Code, Codex from braxtonROSE4/zorro-agent. It costs 78 tokens per session (2,908 once invoked), scanned A, a copy of flash-attention, MIT.

A way to run the attention part of transformer models using less GPU memory and less time. Transformer models use attention to compare tokens, such as words, with one another.

In plain words
What is it for?
Use it to enable Flash Attention in PyTorch models, including models using PyTorch’s built-in attention or the flash-attn library, and to check speed and accuracy against a baseline.
Why use it?
Long inputs can make attention slow or exceed available GPU memory. This helps when sequences are longer than about 512 tokens or when inference and training need to run faster.

Skill for Claude CodeCodex

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

Good fit Use it to enable Flash Attention in PyTorch models, including models using PyTorch’s built-in attention or the flash-attn library, and to check speed and accuracy against a baseline.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/braxtonrose4/zorro-agent/flash-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 braxtonROSE4/zorro-agent --skill flash-attention
Clone the repo
git clone --depth 1 https://github.com/braxtonROSE4/zorro-agent

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 optimizing-attention-flash

README.md
[![agentmods](https://agentmods.dev/badge/skills/braxtonrose4/zorro-agent/flash-attention/github.svg)](https://agentmods.dev/skills/braxtonrose4/zorro-agent/flash-attention)
Your own site
<a href="https://agentmods.dev/skills/braxtonrose4/zorro-agent/flash-attention"><img src="https://agentmods.dev/badge/skills/braxtonrose4/zorro-agent/flash-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 optimizing-attention-flash

Your own site · 80×15
<a href="https://agentmods.dev/skills/braxtonrose4/zorro-agent/flash-attention"><img src="https://agentmods.dev/badge/skills/braxtonrose4/zorro-agent/flash-attention.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 78 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,908 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 81% copy Near-identical to another mod 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.00078 $0.02908
Opus 5.5 $0.00031 $0.01163
Sonnet 5.5 $0.00016 $0.00582
Haiku 4.5 $0.00008 $0.00291

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

Security

Grade A, and why

optimizing-attention-flash 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 1mo 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.

Origin

This is a copy

81% identical to flash-attention — 72 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

optional-skills/mlops/flash-attention/SKILL.md · 371 lines

How it starts

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

Flash Attention - Fast Memory-Efficient Attention

Quick start

Flash Attention provides 2-4x speedup and 10-20x memory reduction for transformer attention through IO-aware tiling and recomputation.

PyTorch native (easiest, PyTorch 2.2+):

import torch
import torch.nn.functional as F

q = torch.randn(2, 8, 512, 64, device='cuda', dtype=torch.float16)  # [batch, heads, seq, dim]
k = torch.randn(2, 8, 512, 64, device='cuda', dtype=torch.float16)
v = torch.randn(2, 8, 512, 64, device='cuda', dtype=torch.float16)

# Automatically uses Flash Attention if available
out = F.scaled_dot_product_attention(q, k, v)

flash-attn library (more features):

pip install flash-attn --no-build-isolation
from flash_attn import flash_attn_func

# q, k, v: [batch, seqlen, nheads, headdim]
out = flash_attn_func(q, k, v, dropout_p=0.0, causal=True)

Common workflows

Workflow 1: Enable in existing PyTorch model

Copy this checklist:

Flash Attention Integration:
- [ ] Step 1: Check PyTorch version (≥2.2)
- [ ] Step 2: Enable Flash Attention backend
- [ ] Step 3: Verify speedup with profiling
- [ ] Step 4: Test accuracy matches baseline

Step 1: Check PyTorch version

python -c "import torch; print(torch.__version__)"
# Should be ≥2.2.0

If <2.2, upgrade:

pip install --upgrade torch

Step 2: Enable Flash Attention backend

Replace standard attention:

# Before (standard attention)
attn_weights = torch.softmax(q @ k.transpose(-2, -1) / math.sqrt(d_k), dim=-1)
out = attn_weights @ v

# After (Flash Attention)
import torch.nn.functional as F
out = F.scaled_dot_product_attention(q, k, v, attn_mask=mask)

Force Flash Attention backend:

with torch.backends.cuda.sdp_kernel(
    enable_flash=True,
    enable_math=False,
    enable_mem_efficient=False
):
    out = F.scaled_dot_product_attention(q, k, v)

Step 3: Verify speedup with profiling

import torch.utils.benchmark as benchmark

def test_attention(use_flash):
    q, k, v = [torch.randn(2, 8, 2048, 64, device='cuda', dtype=torch.float16) for _ in range(3)]

    if use_flash:
        with torch.backends.cuda.sdp_kernel(enable_flash=True):
            return F.scaled_dot_product_attention(q, k, v)
    else:
        attn = (q @ k.transpose(-2, -1) / 8.0).softmax(dim=-1)
        return attn @ v

# Benchmark
t_flash = benchmark.Timer(stmt='test_attention(True)', globals=globals())
t_standard = benchmark.Timer(stmt='test_attention(False)', globals=globals())

print(f"Flash: {t_flash.timeit(100).mean:.3f}s")
print(f"Standard: {t_standard.timeit(100).mean:.3f}s")

Read the full file on GitHub · 371 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 1mo ago First seen · 371 lines · 78 tokens per session scan A 992940dd6fbb

Subscribe to this mod's changes

optimizing-attention-flash is a skill published in the GitHub repository braxtonROSE4/zorro-agent (10 stars, last pushed 6mo ago), licensed MIT. It adds 78 tokens to every session and 2,908 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 81% identical to flash-attention, differing in 72 lines, and is treated as a copy.

Related

Other skills, from other repositories

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

knowledge-retrieval

Semantic search over ingested documents using RAG (LlamaIndex/ChromaDB or Foundational RAG).

open-gitagent/opengap · 28 tokens

hr-data

Help HR managers, recruiters, and talent acquisition teams understand Data Engineering, Data Analytics, Data Science, Business Intelligence, Machine Learning, and modern data ecosystems. Use when asked to explain data roles, screen data engineers or data scientists, understand analytics workflows, compare data…

tuanductran/hr-skills · 86 tokens

hr-genai

Help HR professionals, recruiters, and HR teams leverage Generative AI tools to improve HR productivity, content quality, and decision support across the full HR lifecycle. Use when asked to use generative AI for HR, write HR content with AI, use ChatGPT for HR, generate HR documents with AI, automate HR writing, or…

tuanductran/hr-skills · 80 tokens

hr-prompt-engineering

Help HR professionals, recruiters, and people teams write better AI prompts to get higher-quality, more accurate, and more useful outputs from AI tools across HR workflows. Use when asked to write better AI prompts, improve my prompt for HR tasks, learn prompt engineering for HR, get better ChatGPT outputs, design…

tuanductran/hr-skills · 83 tokens

ai-engineering-curriculum

Use when structured AI engineering curriculum — 382 skills + 99 prompts across 20 phases covering ML, deep learning, LLMs, agents, and production systems. Use when learning AI, building AI skills,.

oyi77/1ai-skills · 50 tokens