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

# FlashAttention-2 (HE)

**FlashAttention-2** — הוא אלגוריתם משופר המיועד לחישוב מנגנון הattention במודלי שפה גדולים (LLM). האלגוריתם פותח על ידי **טרי דאו** (Tri Dao) וחוקרים מאוניברסיטת סטנפורד והוצג ביולי 2023<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_main-1)</sup>. מטרתו המרכזית היא לזרז באופן משמעותי את האימון וה-inference של מודלי transformer באמצעות שימוש יעיל יותר במשאבי חומרת ה-GPU, תוך שמירה על זהות מלאה של החישובים עם מנגנון הattention הסטנדרטי, כלומר **ללא אובדן דיוק**.

FlashAttention-2 הוא המשך הגיוני לאלגוריתם **FlashAttention**, שהוצג על ידי אותה קבוצה בשנת 2022. הגרסה החדשה פותרת את בעיית העומס החלקי על ה-GPU שנצפתה אצל קודמו, ומשיגה עלייה של כמעט פי שניים במהירות בהשוואה לגרסה הראשונה.

## רקע: בעיית ה-attention בטרנספורמרים

מנגנון ה-self-attention הסטנדרטי מהווה צוואר בקבוק בעבודה עם רצפי טקסט ארוכים בטרנספורמרים. המורכבות החישובית וצריכת הזיכרון שלו גדלות **בריבועיות** (O(N²)) בהתאם לאורך הרצף (N), מה שמטיל מגבלות חמורות על אורך ההקשר המרבי ועל יכולת ההרחבה של LLM<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_main-1)</sup>.

לפתרון בעיה זו הוצג ב-2022 האלגוריתם **FlashAttention**<sup>[\[2\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-huggingface_optim-2)</sup>. רעיונותיו המרכזיים:

- **התחשבות בהיררכיית הזיכרון של GPU‏ (IO-awareness)**: האלגוריתם ממזער פעולות קריאה/כתיבה יקרות בין זיכרון ה-GPU האיטי (HBM) לבין זיכרון ה-SRAM המהיר על השבב.
- **עיבוד בבלוקים (tiling)**: החישובים מחולקים לבלוקים קטנים (tiles) המעובדים ב-SRAM המהיר, מה שמאפשר להימנע מהמטריאליזציה של מטריצת ה-attention המלאה בזיכרון.

הדבר אפשר להשיג צמיחה **ליניארית** בצריכת הזיכרון (O(N)) ותאוצה של פי 2–4 בהשוואה למימושים הסטנדרטיים<sup>[\[2\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-huggingface_optim-2)</sup>. FlashAttention זכה לאימוץ נרחב ותרם להופעתן של מודלים עם הקשר מוגדל משמעותית, למשל מ-2–4 אלף token‏ (GPT-3) עד 128 אלף (GPT-4) ומעלה<sup>[\[3\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-tridao_blog_fa3-3)</sup>. כך, במודל **Falcon-40B** השימוש ב-FlashAttention האיץ את ה-inference פי 3, ואת ביצועי היצירה הכוללים — פי 5 בהשוואה ל-GPT-3<sup>[\[4\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-e2e_analysis-4)</sup>.

## פיתוח ומטרות FlashAttention-2

למרות ההצלחה, הגרסה הראשונה של FlashAttention לא ניצלה את משאבי החישוב של ה-GPU במלואם. בכרטיסי המסך **NVIDIA A100** הביצועים הגיעו לכדי **25–40%** בלבד מהמקסימום התיאורטי (FLOPs/s)<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_main-1)</sup>. הסיבה העיקרית הייתה עומס לא אופטימלי על מעבדי הזרמים (Streaming Multiprocessors) ופעולות עודפות עם הזיכרון המשותף<sup>[\[5\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-openreview_fa2-5)</sup>.

מטרתו של **FlashAttention-2** הייתה להאיץ עוד יותר את החישובים באמצעות מקבול יעיל יותר של העבודה ומזעור פעולות עזר. האלגוריתם נוסח מחדש במלואו תוך שימוש בפרימיטיבים ברמה נמוכה של ספריית **NVIDIA CUTLASS 3.x** להשגת ביצועים מרביים<sup>[\[6\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-hazyresearch_blog-6)</sup>.

## ארכיטקטורה טכנית ועקרונות עבודה

FlashAttention-2 מציג שלושה שיפורים מרכזיים לשיפור המקביליות והיעילות<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_main-1)</sup>:

### 1. מזעור פעולות שאינן מטריציות

האלגוריתם מצמצם את מספר פעולות הנקודה הצפה העזריות שאינן כפל מטריצות (non-matmul FLOPs). מאחר שגרעיני ה-tensor של ה-GPU מותאמים בדיוק לפעולות מטריציות (GEMM) ומבצעים אותן עד פי 16 מהר יותר, שינוי זה מאפשר לנצל את רוב הזמן בבלוקי ה-GPU היעילים ביותר.

### 2. מקביליות משופרת

ב-FlashAttention המקורי, עבודה על "ראש" attention אחד לא עברה מקבול, מה שגרם להשבתות בעת רצפים ארוכים וגדלי batch קטנים. FlashAttention-2 מציג **מקביליות בין-בלוקית**: כעת החישובים עבור ראש attention אחד מתחלקים בין מעבדי זרמים שונים של ה-GPU, מה שמגביר משמעותית את העומס עליהם.

### 3. חלוקת עבודה אופטימלית בתוך בלוק

ברמה של בלוק חישובי אחד, העבודה חולקה מחדש בין קבוצות threads‏ (warps) כדי לצמצם את החלפת הנתונים דרך הזיכרון המשותף (shared memory). הדבר מפחית את מספר פעולות הקריאה/כתיבה העודפות הנדרשות לנירמול Softmax.

## ביצועים ויעילות

בזכות השיפורים הארכיטקטוניים, FlashAttention-2 מפגין עלייה משמעותית בביצועים:

- **תאוצה כפולה**: האלגוריתם פועל בקירוב **פי 2 מהר יותר** בהשוואה לגרסה הראשונה של FlashAttention<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_main-1)</sup>.
- **ניצול GPU גבוה**: על GPU **NVIDIA A100** מושגים **50–73%** מרוחב הפס התיאורטי המרבי (TFLOPs), הקרוב ליעילות של פעולות כפל מטריצות אופטימליות (GEMM)<sup>[\[1\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_main-1)</sup>.
- **מהירות חישוב שיא**:
  - על GPU **A100** מושגת מהירות של עד **225 TFLOP/s** במחזור האימון המלא של מודל מסוג GPT, המתאים ל-72% ניצול של בלוקי החישוב. לשם השוואה, attention סטנדרטי באותם תנאים העמיס את ה-GPU בפחות מ-100 TFLOP/s<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_pdf-7)</sup>.
  - על GPU **H100** הביצועים מגיעים ל-**335 TFLOP/s**<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_pdf-7)</sup>.

עלייה כזו בביצועים מאפשרת, למשל, לאמן מודל עם חלון הקשר של **16k** token באותו זמן שנדרש בעבר לחלון **8k** token<sup>[\[5\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-openreview_fa2-5)</sup>. חשוב לציין שהאלגוריתם נשאר **מדויק** ודטרמיניסטי, ולכן שימוש בו אינו משפיע על איכות תחזיות המודל<sup>[\[8\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-raschka_blog-8)</sup>.

## שימוש ואינטגרציה במערכת האקולוגית

FlashAttention-2 הפך במהירות לכלי סטנדרטי במערכת האקולוגית של LLM. הוא משולב בפריימוורקים וספריות פופולריות רבות:

- **PyTorch**: תמיכה מובנית.
- **Hugging Face Transformers**: התמיכה מופעלת באמצעות הפרמטר \`attn_implementation="flash_attention_2"\` בעת טעינת המודל<sup>[\[9\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-linkedin_younes-9)</sup>. תואם לעשרות ארכיטקטורות (GPT,‏ Llama,‏ Falcon,‏ BERT ואחרות)<sup>[\[10\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-huggingface_gpu_infer-10)</sup>.
- **TensorRT-LLM**,‏ **xFormers** ו-**Triton**: האלגוריתם ממומש עבור פלטפורמות אלה, מה שמבטיח שימוש נרחב<sup>[\[7\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-arxiv_pdf-7)</sup>.

האינטגרציה מאפשרת לשלב בקלות את FlashAttention-2 עם שיטות אופטימיזציה אחרות, כגון קוונטיזציה (GPTQ,‏ QLoRA) ו-fine-tuning יעיל (PEFT)<sup>[\[9\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-linkedin_younes-9)</sup>.

## השוואה עם גרסאות עוקבות

### FlashAttention-3

המחקר בתחום אופטימיזציית ה-attention נמשך. ביולי 2024 הציג טרי דאו את **FlashAttention-3**, המכוון לניצול יכולות ארכיטקטורת ה-GPU **NVIDIA Hopper** ‏(H100/H200). חידושים מרכזיים<sup>[\[3\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_note-tridao_blog_fa3-3)</sup>:

- **תמיכה ב-FP8**: שימוש בחישובי נקודה צפה של 8 סיביות להאצה נוספת.
- **פעולות אסינכרוניות**: ניצול יעיל יותר של יכולות ה-GPU האסינכרוניות.

FlashAttention-3 מספק תאוצה של **פי 1.5–2** בהשוואה ל-FlashAttention-2 על GPU H100, ומשיג ביצועים של עד **740 TFLOP/s** (75% מהמקסימום התיאורטי)<sup>[\[11\]](https://systems-analysis.info/int/FlashAttention-2_(HE)#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_(HE)#cite_ref-arxiv_main_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-arxiv_main_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-arxiv_main_1-2)</sup> <sup>[1.3](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-arxiv_main_1-3)</sup> <sup>[1.4](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-arxiv_main_1-4)</sup> <sup>[1.5](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[1]</a></span>
2.  <span id="cite_note-huggingface_optim-2">↑ <sup>[2.0](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-huggingface_optim_2-0)</sup> <sup>[2.1](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[2]</a></span>
3.  <span id="cite_note-tridao_blog_fa3-3">↑ <sup>[3.0](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-tridao_blog_fa3_3-0)</sup> <sup>[3.1](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[3]</a></span>
4.  <span id="cite_note-e2e_analysis-4">[↑](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[4]</a></span>
5.  <span id="cite_note-openreview_fa2-5">↑ <sup>[5.0](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-openreview_fa2_5-0)</sup> <sup>[5.1](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[5]</a></span>
6.  <span id="cite_note-hazyresearch_blog-6">[↑](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[6]</a></span>
7.  <span id="cite_note-arxiv_pdf-7">↑ <sup>[7.0](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-arxiv_pdf_7-0)</sup> <sup>[7.1](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-arxiv_pdf_7-1)</sup> <sup>[7.2](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[7]</a></span>
8.  <span id="cite_note-raschka_blog-8">[↑](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[8]</a></span>
9.  <span id="cite_note-linkedin_younes-9">↑ <sup>[9.0](https://systems-analysis.info/int/FlashAttention-2_(HE)#cite_ref-linkedin_younes_9-0)</sup> <sup>[9.1](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[9]</a></span>
10. <span id="cite_note-huggingface_gpu_infer-10">[↑](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[10]</a></span>
11. <span id="cite_note-arxiv_fa3-11">[↑](https://systems-analysis.info/int/FlashAttention-2_(HE)#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">[11]</a></span>
