---
title: "FlashAttention-2 (HI)"
source: "https://systems-analysis.info/int/FlashAttention-2_(HI)"
wiki: "systems-analysis.info/int"
article: "FlashAttention-2_(HI)"
language: "hi"
categories:
  - "Category:Hindi"
  - "Category:Large language models"
  - "Category:Machine learning"
revision_id: 2202
wiki_created_at: 2026-09-06T23:00:09Z
wiki_modified_at: 2026-09-06T23:00:09Z
downloaded_at: 2026-09-07T22:49:48Z
---

# FlashAttention-2 (HI)

**FlashAttention-2** — यह एक उन्नत algorithm है जो बड़े भाषा मॉडलों (LLM) में attention mechanism की गणना के लिए बनाया गया है। यह algorithm **Tri Dao** और Stanford University के शोधकर्ताओं द्वारा विकसित किया गया था और जुलाई 2023 में प्रस्तुत किया गया<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_main-1)</sup>। इसका मुख्य लक्ष्य — GPU के hardware संसाधनों का अधिक कुशलतापूर्वक उपयोग करके transformer मॉडलों के प्रशिक्षण और inference (अनुमान) को काफी तेज करना है, साथ ही standard attention mechanism के साथ पूरी गणनात्मक समानता बनाए रखना, अर्थात् **बिना किसी सटीकता की हानि के**।

FlashAttention-2, उसी टीम द्वारा 2022 में प्रस्तुत **FlashAttention** algorithm का तार्किक विस्तार है। नया संस्करण GPU की अपूर्ण लोडिंग की समस्या को हल करता है जो पूर्ववर्ती में देखी गई थी, और पहले संस्करण की तुलना में लगभग दोगुनी गति प्राप्त करता है।

## पूर्वापेक्षाएँ: transformer में attention की समस्या

Standard self-attention mechanism transformer में लंबे text sequence के साथ कार्य करते समय एक bottleneck है। इसकी गणनात्मक जटिलता और memory की खपत sequence की लंबाई (N) के आधार पर **द्विघात** (O(N²)) रूप से बढ़ती है, जो LLM की अधिकतम context लंबाई और scalability पर गंभीर प्रतिबंध लगाती है<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_main-1)</sup>।

इस समस्या को हल करने के लिए 2022 में **FlashAttention** algorithm प्रस्तुत किया गया<sup>[\[2\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-huggingface_optim-2)</sup>। इसके प्रमुख विचार:

- **GPU memory hierarchy का ध्यान (IO-awareness)**: Algorithm GPU की धीमी memory (HBM) और चिप पर तेज static memory (SRAM) के बीच महंगे read/write operations को न्यूनतम करता है।
- **Block processing (tiling)**: गणनाएं छोटे blocks (tiles) में विभाजित की जाती हैं जो तेज SRAM में संसाधित होते हैं, जिससे memory में पूरी attention matrix को materialized करने से बचा जाता है।

इससे memory की खपत में **रैखिक** वृद्धि (O(N)) और standard implementations की तुलना में 2–4 गुना तेजी प्राप्त हुई<sup>[\[2\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-huggingface_optim-2)</sup>। FlashAttention व्यापक रूप से अपनाया गया और उन मॉडलों के उद्भव में योगदान दिया जिनका context काफी बढ़ा, उदाहरण के लिए 2–4 हजार tokens (GPT-3) से 128 हजार (GPT-4) और उससे अधिक तक<sup>[\[3\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-tridao_blog_fa3-3)</sup>। उदाहरण के तौर पर, **Falcon-40B** मॉडल में FlashAttention के उपयोग ने GPT-3 की तुलना में inference को 3 गुना और generation की समग्र performance को 5 गुना तेज किया<sup>[\[4\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-e2e_analysis-4)</sup>।

## FlashAttention-2 का विकास और लक्ष्य

सफलता के बावजूद, FlashAttention के पहले संस्करण ने GPU के computational संसाधनों का पूरी तरह उपयोग नहीं किया। **NVIDIA A100** GPU पर performance theoretical maximum (FLOPs/s) के केवल **25–40%** तक पहुँचती थी<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_main-1)</sup>। इसका मुख्य कारण Streaming Multiprocessors की अनुपयुक्त लोडिंग और shared memory के साथ अतिरिक्त operations थे<sup>[\[5\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-openreview_fa2-5)</sup>।

**FlashAttention-2** का उद्देश्य कार्य के अधिक कुशल parallelization और सहायक operations को न्यूनतम करके गणनाओं को और तेज करना बना। Algorithm को **NVIDIA CUTLASS 3.x** library के low-level primitives का उपयोग करके अधिकतम performance प्राप्त करने के लिए पूरी तरह से पुनर्लिखित किया गया<sup>[\[6\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-hazyresearch_blog-6)</sup>।

## तकनीकी architecture और कार्य के सिद्धांत

FlashAttention-2 parallelism और दक्षता बढ़ाने के लिए तीन प्रमुख सुधार प्रस्तुत करता है<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_main-1)</sup>:

### 1. गैर-matrix operations को न्यूनतम करना

Algorithm floating-point के ऐसे सहायक operations की संख्या घटाता है जो matrix multiplication नहीं हैं (non-matmul FLOPs)। चूँकि GPU के tensor cores matrix operations (GEMM) के लिए अनुकूलित हैं और उन्हें 16 गुना तेज निष्पादित करते हैं, इस परिवर्तन से अधिकांश समय GPU के सबसे उत्पादक blocks का उपयोग होता है।

### 2. उन्नत parallelism

मूल FlashAttention में एक attention "head" पर कार्य parallelized नहीं था, जिससे लंबे sequences और छोटे batch sizes पर idle time होता था। FlashAttention-2 **inter-block parallelization** प्रस्तुत करता है: अब एक attention head की गणनाएं GPU के विभिन्न Streaming Multiprocessors में वितरित होती हैं, जिससे उनकी लोडिंग काफी बढ़ जाती है।

### 3. Block के भीतर कार्य का अनुकूलित विभाजन

एक computational block के स्तर पर, shared memory के माध्यम से डेटा exchange को कम करने के लिए thread groups (warps) के बीच कार्य का पुनर्वितरण किया गया। इससे Softmax normalization के लिए आवश्यक अतिरिक्त read/write operations की संख्या कम होती है।

## Performance और दक्षता

Architectural सुधारों के कारण, FlashAttention-2 performance में उल्लेखनीय वृद्धि प्रदर्शित करता है:

- **दोगुनी गति**: Algorithm FlashAttention के पहले संस्करण की तुलना में लगभग **2 गुना तेज** काम करता है<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_main-1)</sup>।
- **उच्च GPU utilization**: **NVIDIA A100** GPU पर theoretical maximum throughput (TFLOPs) का **50–73%** प्राप्त होता है, जो optimized matrix multiplication (GEMM) operations की दक्षता के करीब है<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_main-1)</sup>।
- **रिकॉर्ड गणना गति**:
  - **A100** GPU पर GPT-type मॉडल के end-to-end training cycle में **225 TFLOP/s** तक की गति प्राप्त होती है, जो computational blocks के 72% utilization के अनुरूप है। तुलना के लिए, समान परिस्थितियों में standard attention GPU को 100 TFLOP/s से कम पर लोड करता था<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_pdf-7)</sup>।
  - **H100** GPU पर performance **335 TFLOP/s** तक पहुँचती है<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_pdf-7)</sup>।

Performance में ऐसी वृद्धि, उदाहरण के लिए, उतने ही समय में **16k** tokens की context window वाले मॉडल को प्रशिक्षित करने की अनुमति देती है, जितना पहले **8k** tokens की window के लिए आवश्यक था<sup>[\[5\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-openreview_fa2-5)</sup>। महत्वपूर्ण बात यह है कि algorithm **सटीक** और deterministic रहता है, इसलिए इसका उपयोग मॉडल के predictions की गुणवत्ता को प्रभावित नहीं करता<sup>[\[8\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-raschka_blog-8)</sup>।

## LLM ecosystem में अनुप्रयोग और एकीकरण

FlashAttention-2 जल्दी ही LLM ecosystem में एक standard tool बन गया। यह कई लोकप्रिय frameworks और libraries में एकीकृत है:

- **PyTorch**: Native support।
- **Hugging Face Transformers**: Model लोड करते समय \`attn_implementation="flash_attention_2"\` parameter द्वारा support सक्रिय होता है<sup>[\[9\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-linkedin_younes-9)</sup>। दर्जनों architectures (GPT, Llama, Falcon, BERT आदि) के साथ संगत<sup>[\[10\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-huggingface_gpu_infer-10)</sup>।
- **TensorRT-LLM**, **xFormers** और **Triton**: Algorithm इन platforms के लिए लागू किया गया है, जो व्यापक उपयोग सुनिश्चित करता है<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_pdf-7)</sup>।

एकीकरण FlashAttention-2 को अन्य optimization विधियों जैसे quantization (GPTQ, QLoRA) और efficient fine-tuning (PEFT) के साथ आसानी से संयोजित करने की अनुमति देता है<sup>[\[9\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-linkedin_younes-9)</sup>।

## परवर्ती संस्करणों के साथ तुलना

### FlashAttention-3

Attention optimization के क्षेत्र में अनुसंधान जारी है। जुलाई 2024 में Tri Dao ने **FlashAttention-3** प्रस्तुत किया, जो **NVIDIA Hopper** (H100/H200) GPU architecture की क्षमताओं के उपयोग पर लक्षित है। प्रमुख नवाचार<sup>[\[3\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-tridao_blog_fa3-3)</sup>:

- **FP8 support**: आगे की गति के लिए 8-bit floating-point गणनाओं का उपयोग।
- **Asynchronous operations**: GPU की asynchronous क्षमताओं का अधिक कुशलतापूर्वक उपयोग।

FlashAttention-3, H100 GPU पर FlashAttention-2 की तुलना में **1.5–2 गुना** तेजी प्रदान करता है, **740 TFLOP/s** तक की performance प्राप्त करता है (theoretical maximum का 75%)<sup>[\[11\]](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_note-arxiv_fa3-11)</sup>।

## साहित्य

- Dao, T. (2023). *FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning*. arXiv:2307.08691.
- Dao, T. et al. (2022). *FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness*. arXiv:2205.14135.
- Shah, J. et al. (2024). *FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision*. arXiv:2407.08608.
- Kwon, W. et al. (2023). *Efficient Memory Management for Large Language Model Serving with PagedAttention*. arXiv:2309.06180.
- Ye, Z. et al. (2025). *FlashInfer: Efficient and Customizable Attention Engine for LLM Inference Serving*. arXiv:2501.01005.
- Chen, Y. et al. (2023). *FlashDecoding++: Faster Large Language Model Inference on GPUs*. arXiv:2311.01282.
- Liu, Y. et al. (2024). *FastAttention: Extending FlashAttention-2 to NPUs and Low-Resource GPUs*. OpenReview: 76NYyOrnfk.
- Dege, P. et al. (2025). *FlashMLA-ETAP: Efficient Transpose Attention Pipeline for Accelerating MLA Inference on NVIDIA H20 GPUs*. arXiv:2506.01969.
- Wang, G. et al. (2024). *FlashMask: Efficient and Rich Mask Extension of FlashAttention*. OpenReview: rog0J435OO.
- Abbott, V.; Zardini, G. (2025). *FlashAttention on a Napkin: A Diagrammatic Approach to Deep Learning IO-Awareness*. arXiv:2412.03317.

## संदर्भ

1.  <span id="cite_note-arxiv_main-1">↑ <sup>[1.0](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_main_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_main_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_main_1-2)</sup> <sup>[1.3](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_main_1-3)</sup> <sup>[1.4](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_main_1-4)</sup> <sup>[1.5](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_main_1-5)</sup> Дао, Три. «FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning». *arXiv:2307.08691* \[cs.LG\], 17 июля 2023 г. <a href="https://arxiv.org/abs/2307.08691" class="external autonumber" rel="nofollow">[१]</a></span>
2.  <span id="cite_note-huggingface_optim-2">↑ <sup>[2.0](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-huggingface_optim_2-0)</sup> <sup>[2.1](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-huggingface_optim_2-1)</sup> «Optimizing LLMs for Speed and Memory». *Hugging Face Documentation*. <a href="https://huggingface.co/docs/transformers/v4.42.0/en/llm_tutorial_optimization" class="external autonumber" rel="nofollow">[२]</a></span>
3.  <span id="cite_note-tridao_blog_fa3-3">↑ <sup>[3.0](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-tridao_blog_fa3_3-0)</sup> <sup>[3.1](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-tridao_blog_fa3_3-1)</sup> Дао, Три. «FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision». *Tri Dao's Blog*. <a href="https://tridao.me/blog/2024/flash3/" class="external autonumber" rel="nofollow">[३]</a></span>
4.  <span id="cite_note-e2e_analysis-4">[↑](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-e2e_analysis_4-0) «FlashAttention vs FlashAttention-2 - an Analysis». *E2E Networks Blog*. <a href="https://www.e2enetworks.com/blog/shades-of-attention-flashattention-vs-flashattention-2-a-comprehensive-study" class="external autonumber" rel="nofollow">[४]</a></span>
5.  <span id="cite_note-openreview_fa2-5">↑ <sup>[5.0](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-openreview_fa2_5-0)</sup> <sup>[5.1](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-openreview_fa2_5-1)</sup> «FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning». *OpenReview*. <a href="https://openreview.net/forum?id=mZn2Xyh9Ec" class="external autonumber" rel="nofollow">[५]</a></span>
6.  <span id="cite_note-hazyresearch_blog-6">[↑](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-hazyresearch_blog_6-0) «FlashAttention-2». *Hazy Research, Stanford University*. <a href="https://hazyresearch.stanford.edu/blog/2023-07-17-flash2" class="external autonumber" rel="nofollow">[६]</a></span>
7.  <span id="cite_note-arxiv_pdf-7">↑ <sup>[7.0](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_pdf_7-0)</sup> <sup>[7.1](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_pdf_7-1)</sup> <sup>[7.2](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_pdf_7-2)</sup> Дао, Три. «FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning» (PDF). *arXiv:2307.08691*. <a href="https://arxiv.org/pdf/2307.08691.pdf" class="external autonumber" rel="nofollow">[७]</a></span>
8.  <span id="cite_note-raschka_blog-8">[↑](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-raschka_blog_8-0) Рашка, Себастьян. «Llama 2 and FlashAttention 2». *Ahead of AI Magazine*. <a href="https://magazine.sebastianraschka.com/p/research-highlights-in-three-sentences" class="external autonumber" rel="nofollow">[८]</a></span>
9.  <span id="cite_note-linkedin_younes-9">↑ <sup>[9.0](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-linkedin_younes_9-0)</sup> <sup>[9.1](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-linkedin_younes_9-1)</sup> Белькада, Юнес. «Faster and more memory efficient models with Flash Attention 2!». *LinkedIn*. <a href="https://www.linkedin.com/posts/younes-belkada-b1a903145_flashattention-llms-activity-7112061650106474496-1dzz" class="external autonumber" rel="nofollow">[९]</a></span>
10. <span id="cite_note-huggingface_gpu_infer-10">[↑](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-huggingface_gpu_infer_10-0) «GPU inference». *Hugging Face Documentation*. <a href="https://huggingface.co/docs/transformers/v4.39.0/perf_infer_gpu_one" class="external autonumber" rel="nofollow">[१०]</a></span>
11. <span id="cite_note-arxiv_fa3-11">[↑](https://systems-analysis.info/int/FlashAttention-2_(HI)#cite_ref-arxiv_fa3_11-0) Дао, Три, и др. «FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision». *arXiv:2407.08608* \[cs.LG\], 11 июля 2024 г. <a href="https://arxiv.org/abs/2407.08608" class="external autonumber" rel="nofollow">[११]</a></span>
