Showing posts with label attention. Show all posts
Showing posts with label attention. Show all posts

Monday, December 9, 2024

Attention-based fusion methods

 Attention-based fusion methods are sophisticated techniques used to combine information from multiple modalities or features, and they do not necessarily require token and vocabulary matching in the traditional sense. Here’s a detailed explanation based on the provided sources:


## Attention Mechanism

The core of attention-based fusion is the attention mechanism, which dynamically adjusts the relative importance of different modalities or features based on the context. This is achieved by computing attention weights that reflect how relevant each modality or feature is to the current task or state.


## Multimodal Attention Fusion

In the context of multimodal fusion, such as in video description or vision-language tasks, attention-based methods allow the model to selectively focus on different modalities (e.g., image, audio, text) when generating outputs. For example:

- The method proposed by Hori et al. uses an attention model to handle the fusion of multiple modalities, where each modality has its own sequence of feature vectors. The attention weights are computed based on the decoder state and the feature vectors, allowing the model to dynamically adjust the importance of each modality[1].


## Channel Fusion and Compound Tokens

In vision-language tasks, methods like Compound Tokens fusion use cross-attention to align visual and text tokens. Here, the model does not require exact token matching but instead uses cross-attention to retrieve compatible tokens from different modalities. The visual and text tokens are then concatenated along the channel dimension to form compound tokens, which are fed into a transformer encoder. This approach does not necessitate a direct match between tokens but rather aligns them through cross-attention[2].


## Attentional Feature Fusion

For feature fusion within neural networks, attention-based methods can be applied across different layers and scales. For instance, the Attentional Feature Fusion (AFF) framework generalizes attention-based feature fusion to cross-layer scenarios, including short and long skip connections. This method uses multi-scale channel attention to address issues arising from feature inconsistency across different scales, without requiring token or vocabulary matching[3].


## Multi-criteria Token Fusion

In the context of vision transformers, Multi-criteria Token Fusion (MCTF) optimizes token fusion by considering multiple criteria such as similarity, informativeness, and size. This method uses one-step-ahead attention to measure the informativeness of tokens and does not require a direct match between tokens. Instead, it aggregates tokens based on their relevance and informativeness, minimizing information loss[4].


## Conclusion

Attention-based fusion methods are highly flexible and do not require explicit token or vocabulary matching. They dynamically adjust the importance of different modalities or features based on the context, allowing for more effective and adaptive fusion of information. These methods are applicable across various domains, including multimodal fusion, vision-language tasks, and feature fusion within neural networks.


Citations:

[1] https://openaccess.thecvf.com/content_ICCV_2017/papers/Hori_Attention-Based_Multimodal_Fusion_ICCV_2017_paper.pdf

[2] https://openreview.net/pdf?id=J9Z3MlnPU_f

[3] https://openaccess.thecvf.com/content/WACV2021/papers/Dai_Attentional_Feature_Fusion_WACV_2021_paper.pdf

[4] https://openaccess.thecvf.com/content/CVPR2024/papers/Lee_Multi-criteria_Token_Fusion_with_One-step-ahead_Attention_for_Efficient_Vision_Transformers_CVPR_2024_paper.pdf

[5] https://www.nature.com/articles/s41598-023-50408-6

[6] https://pmc.ncbi.nlm.nih.gov/articles/PMC9462790/

[7] https://openaccess.thecvf.com/content/CVPR2024/papers/Marcos-Manchon_Open-Vocabulary_Attention_Maps_with_Token_Optimization_for_Semantic_Segmentation_in_CVPR_2024_paper.pdf

Sunday, July 2, 2023

flash attention

 FlashAttention is an **IO-aware exact attention algorithm** that uses tiling to reduce the number of memory reads/writes between GPU high bandwidth memory (HBM) and GPU on-chip SRAM. It is designed to be **fast and memory-efficient**¹.


It is optimal for a range of SRAM sizes and requires fewer HBM accesses than standard attention¹. FlashAttention trains Transformers faster than existing baselines and enables longer context in Transformers, yielding higher quality models¹.


Would you like more information on this topic?


Source: Conversation with Bing, 7/2/2023

(1) [2205.14135] FlashAttention: Fast and Memory-Efficient Exact Attention .... https://arxiv.org/abs/2205.14135.

(2) arXiv:2205.14135v2 [cs.LG] 23 Jun 2022. https://arxiv.org/pdf/2205.14135.pdf.

(3) Introducing Lightning Flash — From Deep Learning Baseline To ... - Medium. https://medium.com/pytorch/introducing-lightning-flash-the-fastest-way-to-get-started-with-deep-learning-202f196b3b98.

(4) Attention in Neural Networks - 1. Introduction to attention mechanism. https://buomsoo-kim.github.io/attention/2020/01/01/Attention-mechanism-1.md/.