optimizing-attention-flash

Replace standard attention with Flash Attention in PyTorch transformer models.

6|2|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/GregsGreyCode/Logos --skill optimizing-attention-flash-gregsgreycode
Or copy as Structured Prompt for Agentâ–¼
Please help me install this Agent Skill.
Skill: optimizing-attention-flash
Source: https://github.com/GregsGreyCode/Logos/tree/main/skills/mlops/training/flash-attention
Command: npx skills add https://github.com/GregsGreyCode/Logos --skill optimizing-attention-flash-gregsgreycode

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Flash Attention solves the memory bottlenecks and speed limitations of standard Transformer attention, enabling efficient training and inference with long sequences.

Core Features & Use Cases

  • 2-4x speedup and 10-20x memory reduction for transformer attention on long sequences.
  • Supports PyTorch native SDPA, flash-attn library, H100 FP8, and sliding window attention.
  • Use cases include training large models with long contexts and fast inference in memory-constrained environments.

Quick Start

Enable Flash Attention in your PyTorch model to accelerate training or inference on long sequences and verify memory savings.

Frequently Asked Questions about optimizing-attention-flash

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce memory usage for PyTorch transformer attention on long sequences?â–¼

Flash Attention reduces memory usage for PyTorch transformer attention by replacing standard attention, achieving 10-20x memory reduction and 2-4x speedup on sequences of 512+ tokens. It supports PyTorch SDPA and the flash-attn library.

When should I use Flash Attention instead of standard attention in my transformer model?â–¼

Use Flash Attention instead of standard attention when training large models with long contexts or running inference in memory-constrained environments. It provides significant memory savings and throughput increases specifically for sequences of 512 tokens or more.

Can I use FP8 Flash Attention on H100 GPUs for inference?â–¼

Yes, FP8 Flash Attention is supported on H100 GPUs for inference. The implementation integrates with PyTorch workflows and the flash-attn API to accelerate throughput while maintaining safe defaults and providing rollback guidance if needed.

Does PyTorch SDPA support sliding window attention?â–¼

PyTorch SDPA supports sliding window attention as one of its multi-head attention variants. This Skill configures sliding window Flash Attention to replace standard attention while ensuring compatibility with PyTorch native APIs.

What is the best way to implement Flash Attention without breaking my existing PyTorch model?â–¼

The best way to implement Flash Attention safely is by replacing standard attention with compatible SDPA or flash-attn APIs. This Skill provides safe defaults and rollback guidance to ensure multi-head attention variants and optional features remain compatible.

Why does standard transformer attention cause memory bottlenecks with long contexts?â–¼

Standard transformer attention causes memory bottlenecks with long contexts because its memory scales quadratically with sequence length. Flash Attention solves this bottleneck, enabling efficient training and fast inference on long sequences.