chunk_id
large_stringlengths
36
36
doc_type
large_stringclasses
2 values
category
large_stringclasses
17 values
document
large_stringclasses
50 values
version_raw
large_stringclasses
590 values
chunk_index
int64
0
262
text
large_stringlengths
11
5.69k
file_path
large_stringclasses
882 values
74d1b667-9be8-54fb-93cd-0de53f04bf61
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
0
# Multi-Head, Multi-Query, and Group-Query Attention# Source: https://nvidia.github.io/TensorRT-LLM/1.1.0rc5/features/attention.html Version: 1.1.0rc5 This document details the implementation of multi-head attention (MHA), multi-query attention (MQA), and group-query attention (GQA) for autoregressive models in Tenso...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
589a1c34-37fc-5751-9556-6681e0467120
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
1
## Attention Backends[#](#attention-backends "Link to this heading") There are currently three available attention backends: the vanilla backend, the TRT-LLM backend, and the Flashinfer backend. You can specify the desired attention backend using `PyTorchConfig.attn_backend`. For instance, to utilize the Flashinfer ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
29352bc5-d2a7-5cb2-acb9-83b6ab5360dd
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
2
1. **FP8 Quantization**: This feature enables the quantization of inputs and KV cache into FP8 format, significantly reducing memory usage and improving computational throughput. 2. **RoPE Fusion**: By integrating rotary position embedding (RoPE) directly into the attention computation, this feature enhances efficiency...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
66d6f252-4326-5cbb-a0a3-3ed4c5cb0403
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
3
## Implement a New Attention Backend[#](#implement-a-new-attention-backend "Link to this heading") You can implement a new attention backend to integrate other attention libraries. An attention backend consists of an `AttentionBackend` class and an `AttentionMetadata` class. There are three stages in the PyTorch that ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
46ff8616-57f8-5bc5-95f6-25ee2d0d78ac
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
4
3. To prepare parameters of the input and KV cache, call `AttentionMetadata.prepare` to convert from existing metadata and KV cache manager. 3. Single step forward: During the forward pass of each attention layer, call `AttentionBackend.forward` to perform the attention operation. The `AttentionMetadata` will be pro...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
20f43595-117e-56a1-9361-0fd8b9b4f41f
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
5
| num\_tokens | int | Number of tokens in the batch. | | num\_ctx\_tokens | int | Number of tokens in sequences in the context phase. | | kv\_cache\_manager | KVCacheManager | The KV cache manager. | | is\_cuda\_graph | bool | Whether CUDA graph is enabled. | | seq\_lens | Tensor | The length of each sequence in the ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
decd9163-0080-5401-9175-5fd33766bc88
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
6
During `AttentionMetadata.__init__`, you can initialize additional fields for the new attention metadata. For example, the Flashinfer metadata initializes `decode_wrapper` here. During `AttentionMetadata.prepare`, the runtime will fill all predefined fields, and you can fill your customized fields according to these pr...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
93504a18-8f7d-5a78-8452-67ceff765d6e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
7
| quant\_config | QuantConfig | Optional quantization configuration. If None, no quantization is applied. | | pos\_embd\_params | PositionalEmbeddingParams | Optional parameters defining how positional embedding should be applied. If None, positional embedding should be applied by the model before calling the backend. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
9c88e3d3-98f4-5ab9-99fc-496c878ea93f
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
8
For example, the Flashinfer backend calls `append_paged_kv_cache` and then `wrapper.run` to perform the attention operation here. ## The Features of the `TrtllmAttention` Backend[#](#the-features-of-the-trtllmattention-backend "Link to this heading") The following sections introduce some features of the default `Trtl...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
d4108ce8-8a48-526e-a705-0a2f858e87f0
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
9
with a 1D tensor containing the lengths of the different sequences. ### Context and Generation Phases[#](#context-and-generation-phases "Link to this heading") The `TrtllmAttention` backend encapsulates different implementations for both context and generation phases into a single custom torch op. #### Context Phase...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
c0d2092e-b234-5154-98f5-d7e2f97c6ac2
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
10
[FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness](https://arxiv.org/abs/2205.14135) and [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://arxiv.org/abs/2307.08691). Currently, the implementation triggers extra kernels that apply pre-processing to the...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
c578299e-c2cc-5101-8b73-99c2d8415799
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
11
#### Generation Phase[#](#generation-phase "Link to this heading") The generation phase is implemented using a single kernel called the masked multi-head attention in TensorRT LLM. That kernel is able to apply pre-processing on the Q, K, and V elements on-the-fly: it adds the QKV bias, applies RoPE, and performs dequa...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
7c626d03-3c0b-5605-a865-ac1cf77c697e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
12
However, NVIDIA currently recommends testing that mode when `batch_size * num_heads` is less than the number of multi-processors on the GPU. This guidance may be subject to change in the future. Note that even if the multi-block mode is enabled, the attention operator will not immediately trigger the multi-block versi...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
538a7bcc-be28-5521-a7a8-a410cdd10f51
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
13
#### XQA Optimization[#](#xqa-optimization "Link to this heading") XQA optimization is another optimization for MQA/GQA in the generation phase. It currently only supports a limited number of model configurations, such as the LLAMA2 70B model. Support matrix of the XQA optimization: * FP16 / BF16 compute data type. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
2c2939ef-c76b-56c5-bd09-a9e1823d7da0
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
14
### In-flight Batching[#](#in-flight-batching "Link to this heading") TensorRT LLM supports in-flight batching of requests (also known as continuous batching or iteration-level batching) for higher serving throughput. With this feature, sequences in the context phase can be processed together with sequences in the gen...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
990c96e3-70c8-5cdd-a4f0-7e44e407c1a9
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
15
the length of the maximum input sequence is inefficient use of resources*. ### Chunked Context[#](#chunked-context "Link to this heading") In the original state, the common behavior was to process all context tokens at once. This feature splits the context into several chunks. In this way, the context chunks can be b...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
b2d119ef-43cb-5899-952a-0720849b78ef
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
16
that technique to accelerate its generation phase. In TensorRT LLM, there is one KV cache per Transformer layer, which means that there are as many KV caches as layers in a model. The current version of TensorRT LLM supports two different types of KV caches: **contiguous** and **paged** KV caches. #### Contiguous KV C...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
c451bdc6-3833-54a1-9af1-39766709b2c3
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
17
keeps track of the sequences, allocates new blocks from a pool and recycles those blocks when required. See the implementation of [`KVCacheManager`](https://github.com/NVIDIA/TensorRT-LLM/tree/HEAD/tensorrt_llm/_torch/pyexecutor/resource_manager.py). #### INT8/FP8 KV Caches[#](#int8-fp8-kv-caches "Link to this heading...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
4014ca47-eda9-5141-805a-1104c26ab49b
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
18
since it does multiply as `fp_value * (1.0 / kv_cache_scaling_factor)` in plugin. During generation, the values read from the cache are dequantized on-the-fly in the MHA/MQA kernel. Dequantization is defined as `quantized_value * kv_cache_scaling_factor`. ### Sliding Window Attention, Cyclic (Rolling Buffer) KV Cache...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
af4a21a4-6334-54e5-93d4-2b84e7c76673
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
19
dealing with very long sequences. \_Note that the cyclic kv cache feature doesn’t work with beam searching currently as the context kv cache are shared across beams. ### StreamingLLM[#](#streamingllm "Link to this heading") The StreamingLLM feature uses a window attention to perform efficient and stable LLM on long ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
62309e97-72a1-5bd6-b577-46839db0ca9e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
20
When determining the relative distance and adding positional information to tokens, StreamingLLM use the positions within the cache rather than those in the original text. `sink_token_length` is also used to enable this feature. ### Beam-Search[#](#beam-search "Link to this heading") The attention operator supports ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
ce512791-2f2e-58a6-9bd6-6f4addd4f1d9
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
21
### Input QKV tensor[#](#input-qkv-tensor "Link to this heading") The input QKV tensor packs the Q, K and V tensors (concatenated along the last dimension) after the projection of the hidden states. It is a 3D tensor. RoPE and quantization to INT8 or FP8 (when needed) are performed by the GPT attention operator. In p...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
616f29c6-b0f1-567f-af63-7422d045470d
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
22
for seq in generation_phase: num_tokens += seq.beam_width ``` ### Rotary Positional Embedding (RoPE)[#](#rotary-positional-embedding-rope "Link to this heading") The attention operator can perform the computation of the Rotary Positional Embedding (RoPE). When that operation is enabled, `rotary_embedding_dim` is ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
799522b0-8aa5-5f21-9cd2-8de499615634
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
110rc5
23
### Cross Attention[#](#cross-attention "Link to this heading") On top of the MHA as self attention needed by GPT-style decoder-only models, the attention operator also supports cross attention. This enables the attention operator to be more broadly used as a generic decoder component. For example, the Encoder-Decode...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_110rc5.md
1ae9b757-6231-5605-af8a-69c6ff8e475d
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
0
# Multi-Head, Multi-Query, and Group-Query Attention# Source: https://nvidia.github.io/TensorRT-LLM/1.2.0rc0/features/attention.html Version: 1.2.0rc0 This document details the implementation of multi-head attention (MHA), multi-query attention (MQA), and group-query attention (GQA) for autoregressive models in Tenso...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
fb76e8b7-b1ca-59e9-91d4-007b4b1347bd
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
1
## Attention Backends[#](#attention-backends "Link to this heading") There are currently three available attention backends: the vanilla backend, the TRT-LLM backend, and the Flashinfer backend. You can specify the desired attention backend using `PyTorchConfig.attn_backend`. For instance, to utilize the Flashinfer ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
ee114c4c-ba8b-5cad-809d-c4216cc3cf80
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
2
1. **FP8 Quantization**: This feature enables the quantization of inputs and KV cache into FP8 format, significantly reducing memory usage and improving computational throughput. 2. **RoPE Fusion**: By integrating rotary position embedding (RoPE) directly into the attention computation, this feature enhances efficiency...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
76ef144b-fbd7-5fe3-8e26-e32cd4d3e6ca
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
3
## Implement a New Attention Backend[#](#implement-a-new-attention-backend "Link to this heading") You can implement a new attention backend to integrate other attention libraries. An attention backend consists of an `AttentionBackend` class and an `AttentionMetadata` class. There are three stages in the PyTorch that ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
e80b16ea-ba31-5e39-961c-69cad43fd31a
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
4
3. To prepare parameters of the input and KV cache, call `AttentionMetadata.prepare` to convert from existing metadata and KV cache manager. 3. Single step forward: During the forward pass of each attention layer, call `AttentionBackend.forward` to perform the attention operation. The `AttentionMetadata` will be pro...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
a46cf11b-b0ef-5292-b482-bfa72802f6f4
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
5
| num\_tokens | int | Number of tokens in the batch. | | num\_ctx\_tokens | int | Number of tokens in sequences in the context phase. | | kv\_cache\_manager | KVCacheManager | The KV cache manager. | | is\_cuda\_graph | bool | Whether CUDA graph is enabled. | | seq\_lens | Tensor | The length of each sequence in the ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
0246dc78-33c3-5536-8d61-190adc413988
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
6
During `AttentionMetadata.__init__`, you can initialize additional fields for the new attention metadata. For example, the Flashinfer metadata initializes `decode_wrapper` here. During `AttentionMetadata.prepare`, the runtime will fill all predefined fields, and you can fill your customized fields according to these pr...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
9134f323-fac4-5ac6-a3bd-2d1e795f4a6c
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
7
| quant\_config | QuantConfig | Optional quantization configuration. If None, no quantization is applied. | | pos\_embd\_params | PositionalEmbeddingParams | Optional parameters defining how positional embedding should be applied. If None, positional embedding should be applied by the model before calling the backend. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
45980b06-5b6c-549a-8719-d8ce09b18dd7
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
8
For example, the Flashinfer backend calls `append_paged_kv_cache` and then `wrapper.run` to perform the attention operation here. ## The Features of the `TrtllmAttention` Backend[#](#the-features-of-the-trtllmattention-backend "Link to this heading") The following sections introduce some features of the default `Trtl...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
c6e144cc-d68f-534a-8bc8-65b18f89413e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
9
with a 1D tensor containing the lengths of the different sequences. ### Context and Generation Phases[#](#context-and-generation-phases "Link to this heading") The `TrtllmAttention` backend encapsulates different implementations for both context and generation phases into a single custom torch op. #### Context Phase...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
3bbd7a87-d94b-541e-874f-db7f5be85fe9
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
10
[FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness](https://arxiv.org/abs/2205.14135) and [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://arxiv.org/abs/2307.08691). Currently, the implementation triggers extra kernels that apply pre-processing to the...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
c4f81f8c-4a66-5130-8ad8-3a8c93bbbe77
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
11
#### Generation Phase[#](#generation-phase "Link to this heading") The generation phase is implemented using a single kernel called the masked multi-head attention in TensorRT LLM. That kernel is able to apply pre-processing on the Q, K, and V elements on-the-fly: it adds the QKV bias, applies RoPE, and performs dequa...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
fc18d91b-3950-5892-808e-bcb6684aac1f
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
12
However, NVIDIA currently recommends testing that mode when `batch_size * num_heads` is less than the number of multi-processors on the GPU. This guidance may be subject to change in the future. Note that even if the multi-block mode is enabled, the attention operator will not immediately trigger the multi-block versi...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
5ad30f88-a90c-5a90-b5be-e56dfd79c201
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
13
#### XQA Optimization[#](#xqa-optimization "Link to this heading") XQA optimization is another optimization for MQA/GQA in the generation phase. It currently only supports a limited number of model configurations, such as the LLAMA2 70B model. Support matrix of the XQA optimization: * FP16 / BF16 compute data type. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
7a7c7f9d-7c8e-5306-a136-05511b084ded
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
14
### In-flight Batching[#](#in-flight-batching "Link to this heading") TensorRT LLM supports in-flight batching of requests (also known as continuous batching or iteration-level batching) for higher serving throughput. With this feature, sequences in the context phase can be processed together with sequences in the gen...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
9dfaa2d8-deec-5ac0-9b9b-ef9f56731a7e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
15
the length of the maximum input sequence is inefficient use of resources*. ### Chunked Context[#](#chunked-context "Link to this heading") In the original state, the common behavior was to process all context tokens at once. This feature splits the context into several chunks. In this way, the context chunks can be b...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
8f70d150-bfc8-5830-8137-bd104059c829
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
16
that technique to accelerate its generation phase. In TensorRT LLM, there is one KV cache per Transformer layer, which means that there are as many KV caches as layers in a model. The current version of TensorRT LLM supports two different types of KV caches: **contiguous** and **paged** KV caches. #### Contiguous KV C...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
d39296bb-8259-571d-b205-b336824f4582
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
17
keeps track of the sequences, allocates new blocks from a pool and recycles those blocks when required. See the implementation of [`KVCacheManager`](https://github.com/NVIDIA/TensorRT-LLM/tree/560ded5/tensorrt_llm/_torch/pyexecutor/resource_manager.py). #### INT8/FP8 KV Caches[#](#int8-fp8-kv-caches "Link to this head...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
425ae2c2-fe73-56a6-a5c0-308fc0cbdc41
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
18
since it does multiply as `fp_value * (1.0 / kv_cache_scaling_factor)` in plugin. During generation, the values read from the cache are dequantized on-the-fly in the MHA/MQA kernel. Dequantization is defined as `quantized_value * kv_cache_scaling_factor`. ### Sliding Window Attention, Cyclic (Rolling Buffer) KV Cache...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
9fdeb317-7ada-5341-8adc-1067fc9bb35b
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
19
dealing with very long sequences. \_Note that the cyclic kv cache feature doesn’t work with beam searching currently as the context kv cache are shared across beams. ### StreamingLLM[#](#streamingllm "Link to this heading") The StreamingLLM feature uses a window attention to perform efficient and stable LLM on long ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
47caf7a5-cb80-58b1-9ff3-856e584e0eaa
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
20
When determining the relative distance and adding positional information to tokens, StreamingLLM use the positions within the cache rather than those in the original text. `sink_token_length` is also used to enable this feature. ### Beam-Search[#](#beam-search "Link to this heading") The attention operator supports ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
1a876efb-6f64-5bbc-8e1e-945cf0215b5a
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
21
### Input QKV tensor[#](#input-qkv-tensor "Link to this heading") The input QKV tensor packs the Q, K and V tensors (concatenated along the last dimension) after the projection of the hidden states. It is a 3D tensor. RoPE and quantization to INT8 or FP8 (when needed) are performed by the GPT attention operator. In p...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
4e3733d5-7c1d-5fb7-8fdd-6bea50730936
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
22
for seq in generation_phase: num_tokens += seq.beam_width ``` ### Rotary Positional Embedding (RoPE)[#](#rotary-positional-embedding-rope "Link to this heading") The attention operator can perform the computation of the Rotary Positional Embedding (RoPE). When that operation is enabled, `rotary_embedding_dim` is ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
eeb46950-c201-57a2-a405-73f8506691dc
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc0
23
### Cross Attention[#](#cross-attention "Link to this heading") On top of the MHA as self attention needed by GPT-style decoder-only models, the attention operator also supports cross attention. This enables the attention operator to be more broadly used as a generic decoder component. For example, the Encoder-Decode...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc0.md
945a0f79-2632-5792-b3bb-507f9a9027ae
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
0
# Multi-Head, Multi-Query, and Group-Query Attention# Source: https://nvidia.github.io/TensorRT-LLM/1.2.0rc1/features/attention.html Version: 1.2.0rc1 This document details the implementation of multi-head attention (MHA), multi-query attention (MQA), and group-query attention (GQA) for autoregressive models in Tenso...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
de93f7f8-4fe3-5759-9384-2c22df762c9f
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
1
## Attention Backends[#](#attention-backends "Link to this heading") There are currently three available attention backends: the vanilla backend, the TRT-LLM backend, and the Flashinfer backend. You can specify the desired attention backend using `PyTorchConfig.attn_backend`. For instance, to utilize the Flashinfer ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
827115ba-208b-50c6-b917-46d64c5d2125
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
2
1. **FP8 Quantization**: This feature enables the quantization of inputs and KV cache into FP8 format, significantly reducing memory usage and improving computational throughput. 2. **RoPE Fusion**: By integrating rotary position embedding (RoPE) directly into the attention computation, this feature enhances efficiency...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
ae1a9064-6162-5d84-84e1-67ff1bc78333
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
3
## Implement a New Attention Backend[#](#implement-a-new-attention-backend "Link to this heading") You can implement a new attention backend to integrate other attention libraries. An attention backend consists of an `AttentionBackend` class and an `AttentionMetadata` class. There are three stages in the PyTorch that ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
7a32deab-b1d8-5d4a-ad6d-a3de9321cab7
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
4
3. To prepare parameters of the input and KV cache, call `AttentionMetadata.prepare` to convert from existing metadata and KV cache manager. 3. Single step forward: During the forward pass of each attention layer, call `AttentionBackend.forward` to perform the attention operation. The `AttentionMetadata` will be pro...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
32a807c5-4f0e-5bbc-849e-f2f3ff9c44a9
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
5
| num\_tokens | int | Number of tokens in the batch. | | num\_ctx\_tokens | int | Number of tokens in sequences in the context phase. | | kv\_cache\_manager | KVCacheManager | The KV cache manager. | | is\_cuda\_graph | bool | Whether CUDA graph is enabled. | | seq\_lens | Tensor | The length of each sequence in the ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
00545067-b7e5-56e5-a1ff-65ffad4596eb
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
6
During `AttentionMetadata.__init__`, you can initialize additional fields for the new attention metadata. For example, the Flashinfer metadata initializes `decode_wrapper` here. During `AttentionMetadata.prepare`, the runtime will fill all predefined fields, and you can fill your customized fields according to these pr...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
acb12132-297b-539d-86c6-e5e9141dacca
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
7
| quant\_config | QuantConfig | Optional quantization configuration. If None, no quantization is applied. | | pos\_embd\_params | PositionalEmbeddingParams | Optional parameters defining how positional embedding should be applied. If None, positional embedding should be applied by the model before calling the backend. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
ee8d11e4-dea0-587e-a99b-ac83dce17da6
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
8
For example, the Flashinfer backend calls `append_paged_kv_cache` and then `wrapper.run` to perform the attention operation here. ## The Features of the `TrtllmAttention` Backend[#](#the-features-of-the-trtllmattention-backend "Link to this heading") The following sections introduce some features of the default `Trtl...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
8b85ad42-fbe3-5b76-970f-2b5a2dfa7f57
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
9
with a 1D tensor containing the lengths of the different sequences. ### Context and Generation Phases[#](#context-and-generation-phases "Link to this heading") The `TrtllmAttention` backend encapsulates different implementations for both context and generation phases into a single custom torch op. #### Context Phase...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
cbcce0a5-12cd-5dc1-a9df-b82c6ab8d0ed
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
10
[FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness](https://arxiv.org/abs/2205.14135) and [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://arxiv.org/abs/2307.08691). Currently, the implementation triggers extra kernels that apply pre-processing to the...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
ebc56a7c-bdb4-5111-a515-b8d799fc3ad5
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
11
#### Generation Phase[#](#generation-phase "Link to this heading") The generation phase is implemented using a single kernel called the masked multi-head attention in TensorRT LLM. That kernel is able to apply pre-processing on the Q, K, and V elements on-the-fly: it adds the QKV bias, applies RoPE, and performs dequa...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
9abb1a89-99cb-51db-8dc0-f2ef0691ea91
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
12
However, NVIDIA currently recommends testing that mode when `batch_size * num_heads` is less than the number of multi-processors on the GPU. This guidance may be subject to change in the future. Note that even if the multi-block mode is enabled, the attention operator will not immediately trigger the multi-block versi...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
bd092247-f107-5699-ae89-54c0b387e0c6
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
13
#### XQA Optimization[#](#xqa-optimization "Link to this heading") XQA optimization is another optimization for MQA/GQA in the generation phase. It currently only supports a limited number of model configurations, such as the LLAMA2 70B model. Support matrix of the XQA optimization: * FP16 / BF16 compute data type. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
f4d29830-f11f-5112-a65d-6eab2fef7b1c
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
14
### In-flight Batching[#](#in-flight-batching "Link to this heading") TensorRT LLM supports in-flight batching of requests (also known as continuous batching or iteration-level batching) for higher serving throughput. With this feature, sequences in the context phase can be processed together with sequences in the gen...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
eb596e83-fac8-5299-a727-dd22f345aa30
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
15
the length of the maximum input sequence is inefficient use of resources*. ### Chunked Context[#](#chunked-context "Link to this heading") In the original state, the common behavior was to process all context tokens at once. This feature splits the context into several chunks. In this way, the context chunks can be b...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
30488ce9-f970-57dc-8ec1-ecbb16857112
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
16
that technique to accelerate its generation phase. In TensorRT LLM, there is one KV cache per Transformer layer, which means that there are as many KV caches as layers in a model. The current version of TensorRT LLM supports two different types of KV caches: **contiguous** and **paged** KV caches. #### Contiguous KV C...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
ffff9576-862b-54c4-9506-57715298e071
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
17
keeps track of the sequences, allocates new blocks from a pool and recycles those blocks when required. See the implementation of [`KVCacheManager`](https://github.com/NVIDIA/TensorRT-LLM/tree/796891b/tensorrt_llm/_torch/pyexecutor/resource_manager.py). #### INT8/FP8 KV Caches[#](#int8-fp8-kv-caches "Link to this head...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
0d3e8389-4301-5d75-9c39-95fb8a34842e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
18
since it does multiply as `fp_value * (1.0 / kv_cache_scaling_factor)` in plugin. During generation, the values read from the cache are dequantized on-the-fly in the MHA/MQA kernel. Dequantization is defined as `quantized_value * kv_cache_scaling_factor`. ### Sliding Window Attention, Cyclic (Rolling Buffer) KV Cache...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
4b6665d7-61db-5167-b5f4-b3b65546f104
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
19
dealing with very long sequences. \_Note that the cyclic kv cache feature doesn’t work with beam searching currently as the context kv cache are shared across beams. ### StreamingLLM[#](#streamingllm "Link to this heading") The StreamingLLM feature uses a window attention to perform efficient and stable LLM on long ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
f1ef1605-f076-5472-9c57-3d7de23ed8d6
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
20
When determining the relative distance and adding positional information to tokens, StreamingLLM use the positions within the cache rather than those in the original text. `sink_token_length` is also used to enable this feature. ### Beam-Search[#](#beam-search "Link to this heading") The attention operator supports ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
d901857b-f4e4-5c88-92c4-56d7dd958686
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
21
### Input QKV tensor[#](#input-qkv-tensor "Link to this heading") The input QKV tensor packs the Q, K and V tensors (concatenated along the last dimension) after the projection of the hidden states. It is a 3D tensor. RoPE and quantization to INT8 or FP8 (when needed) are performed by the GPT attention operator. In p...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
29125e55-c5ca-559f-affa-1cd78e4a90ed
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
22
for seq in generation_phase: num_tokens += seq.beam_width ``` ### Rotary Positional Embedding (RoPE)[#](#rotary-positional-embedding-rope "Link to this heading") The attention operator can perform the computation of the Rotary Positional Embedding (RoPE). When that operation is enabled, `rotary_embedding_dim` is ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
41c98fcc-039a-5e5b-9237-f4b106a6cc4a
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc1
23
### Cross Attention[#](#cross-attention "Link to this heading") On top of the MHA as self attention needed by GPT-style decoder-only models, the attention operator also supports cross attention. This enables the attention operator to be more broadly used as a generic decoder component. For example, the Encoder-Decode...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc1.md
4533b5f8-7c80-5c2a-98c6-3362c9bef2a6
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
0
# Multi-Head, Multi-Query, and Group-Query Attention# Source: https://nvidia.github.io/TensorRT-LLM/1.2.0rc2/features/attention.html Version: 1.2.0rc2 This document details the implementation of multi-head attention (MHA), multi-query attention (MQA), and group-query attention (GQA) for autoregressive models in Tenso...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
82bc8f20-dc52-5930-823a-a27168af2ae3
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
1
## Attention Backends[#](#attention-backends "Link to this heading") There are currently three available attention backends: the vanilla backend, the TRT-LLM backend, and the Flashinfer backend. You can specify the desired attention backend using `PyTorchConfig.attn_backend`. For instance, to utilize the Flashinfer ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
a6d4268a-de09-59bc-afac-90b3104e106e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
2
1. **FP8 Quantization**: This feature enables the quantization of inputs and KV cache into FP8 format, significantly reducing memory usage and improving computational throughput. 2. **RoPE Fusion**: By integrating rotary position embedding (RoPE) directly into the attention computation, this feature enhances efficiency...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
3bbeaa08-ee4e-58c8-a7c6-43c6ec59f9e5
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
3
## Implement a New Attention Backend[#](#implement-a-new-attention-backend "Link to this heading") You can implement a new attention backend to integrate other attention libraries. An attention backend consists of an `AttentionBackend` class and an `AttentionMetadata` class. There are three stages in the PyTorch that ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
ec2463b6-6cdc-56f3-8412-1073d658f3bd
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
4
3. To prepare parameters of the input and KV cache, call `AttentionMetadata.prepare` to convert from existing metadata and KV cache manager. 3. Single step forward: During the forward pass of each attention layer, call `AttentionBackend.forward` to perform the attention operation. The `AttentionMetadata` will be pro...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
5514f8f6-1d81-5b14-b6ed-5e7ab81be26a
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
5
| num\_tokens | int | Number of tokens in the batch. | | num\_ctx\_tokens | int | Number of tokens in sequences in the context phase. | | kv\_cache\_manager | KVCacheManager | The KV cache manager. | | is\_cuda\_graph | bool | Whether CUDA graph is enabled. | | seq\_lens | Tensor | The length of each sequence in the ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
6ffc3107-f08d-50d8-8a8a-ee66b2c35c3e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
6
During `AttentionMetadata.__init__`, you can initialize additional fields for the new attention metadata. For example, the Flashinfer metadata initializes `decode_wrapper` here. During `AttentionMetadata.prepare`, the runtime will fill all predefined fields, and you can fill your customized fields according to these pr...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
6801693e-97f3-5eb3-9fb9-e907dda08b4b
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
7
| quant\_config | QuantConfig | Optional quantization configuration. If None, no quantization is applied. | | pos\_embd\_params | PositionalEmbeddingParams | Optional parameters defining how positional embedding should be applied. If None, positional embedding should be applied by the model before calling the backend. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
ab9e393e-7677-506d-b63a-fcb79ee0bf5b
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
8
For example, the Flashinfer backend calls `append_paged_kv_cache` and then `wrapper.run` to perform the attention operation here. ## The Features of the `TrtllmAttention` Backend[#](#the-features-of-the-trtllmattention-backend "Link to this heading") The following sections introduce some features of the default `Trtl...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
0fc585a4-0991-5093-aaed-b9c15c26242d
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
9
with a 1D tensor containing the lengths of the different sequences. ### Context and Generation Phases[#](#context-and-generation-phases "Link to this heading") The `TrtllmAttention` backend encapsulates different implementations for both context and generation phases into a single custom torch op. #### Context Phase...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
b2da3842-9b8f-5c2c-a0ab-25894387b585
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
10
[FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness](https://arxiv.org/abs/2205.14135) and [FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning](https://arxiv.org/abs/2307.08691). Currently, the implementation triggers extra kernels that apply pre-processing to the...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
56f4a83f-23d9-5b54-b3e7-764444bff4ae
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
11
#### Generation Phase[#](#generation-phase "Link to this heading") The generation phase is implemented using a single kernel called the masked multi-head attention in TensorRT LLM. That kernel is able to apply pre-processing on the Q, K, and V elements on-the-fly: it adds the QKV bias, applies RoPE, and performs dequa...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
786e10ee-cc68-5daf-abed-c1c33b44f43e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
12
However, NVIDIA currently recommends testing that mode when `batch_size * num_heads` is less than the number of multi-processors on the GPU. This guidance may be subject to change in the future. Note that even if the multi-block mode is enabled, the attention operator will not immediately trigger the multi-block versi...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
e3f9d7a6-536e-5ffd-9da6-7e47c93d5b0d
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
13
#### XQA Optimization[#](#xqa-optimization "Link to this heading") XQA optimization is another optimization for MQA/GQA in the generation phase. It currently only supports a limited number of model configurations, such as the LLAMA2 70B model. Support matrix of the XQA optimization: * FP16 / BF16 compute data type. ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
44469b05-eb46-5dbe-98de-1851f0070835
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
14
### In-flight Batching[#](#in-flight-batching "Link to this heading") TensorRT LLM supports in-flight batching of requests (also known as continuous batching or iteration-level batching) for higher serving throughput. With this feature, sequences in the context phase can be processed together with sequences in the gen...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
fd2f20a0-aaca-5030-b24c-df41d613a66b
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
15
the length of the maximum input sequence is inefficient use of resources*. ### Chunked Context[#](#chunked-context "Link to this heading") In the original state, the common behavior was to process all context tokens at once. This feature splits the context into several chunks. In this way, the context chunks can be b...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
fe200bc5-2fb1-5bf2-970e-5c9427b00621
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
16
that technique to accelerate its generation phase. In TensorRT LLM, there is one KV cache per Transformer layer, which means that there are as many KV caches as layers in a model. The current version of TensorRT LLM supports two different types of KV caches: **contiguous** and **paged** KV caches. #### Contiguous KV C...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
6bb1680c-3e17-5b1d-8bf8-8f999958d08d
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
17
keeps track of the sequences, allocates new blocks from a pool and recycles those blocks when required. See the implementation of [`KVCacheManager`](https://github.com/NVIDIA/TensorRT-LLM/tree/3111682/tensorrt_llm/_torch/pyexecutor/resource_manager.py). #### INT8/FP8 KV Caches[#](#int8-fp8-kv-caches "Link to this head...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
49730dce-2f72-554b-b274-de7912f0526e
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
18
since it does multiply as `fp_value * (1.0 / kv_cache_scaling_factor)` in plugin. During generation, the values read from the cache are dequantized on-the-fly in the MHA/MQA kernel. Dequantization is defined as `quantized_value * kv_cache_scaling_factor`. ### Sliding Window Attention, Cyclic (Rolling Buffer) KV Cache...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
2b8a38da-a45e-52fb-88ee-2bc9207b0a17
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
19
dealing with very long sequences. \_Note that the cyclic kv cache feature doesn’t work with beam searching currently as the context kv cache are shared across beams. ### StreamingLLM[#](#streamingllm "Link to this heading") The StreamingLLM feature uses a window attention to perform efficient and stable LLM on long ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
928ae2ce-cd64-5391-99ac-e498e494694b
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
20
When determining the relative distance and adding positional information to tokens, StreamingLLM use the positions within the cache rather than those in the original text. `sink_token_length` is also used to enable this feature. ### Beam-Search[#](#beam-search "Link to this heading") The attention operator supports ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
c03b832f-dec3-5c85-95a2-0155d1fae977
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
21
### Input QKV tensor[#](#input-qkv-tensor "Link to this heading") The input QKV tensor packs the Q, K and V tensors (concatenated along the last dimension) after the projection of the hidden states. It is a 3D tensor. RoPE and quantization to INT8 or FP8 (when needed) are performed by the GPT attention operator. In p...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
f07ba65a-74cc-556c-882a-803d179a32e9
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
22
for seq in generation_phase: num_tokens += seq.beam_width ``` ### Rotary Positional Embedding (RoPE)[#](#rotary-positional-embedding-rope "Link to this heading") The attention operator can perform the computation of the Rotary Positional Embedding (RoPE). When that operation is enabled, `rotary_embedding_dim` is ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
b5c5fb59-ca04-5466-b9fc-cd45dc6c68d2
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc2
23
### Cross Attention[#](#cross-attention "Link to this heading") On top of the MHA as self attention needed by GPT-style decoder-only models, the attention operator also supports cross attention. This enables the attention operator to be more broadly used as a generic decoder component. For example, the Encoder-Decode...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc2.md
5ad7f7d4-2e58-503c-b5d6-9e1585409efd
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc3
0
# Multi-Head, Multi-Query, and Group-Query Attention# Source: https://nvidia.github.io/TensorRT-LLM/1.2.0rc3/features/attention.html Version: 1.2.0rc3 This document details the implementation of multi-head attention (MHA), multi-query attention (MQA), and group-query attention (GQA) for autoregressive models in Tenso...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc3.md
2134d365-c570-5df1-9bca-0fc96ad05a44
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc3
1
## Attention Backends[#](#attention-backends "Link to this heading") There are currently three available attention backends: the vanilla backend, the TRT-LLM backend, and the Flashinfer backend. You can specify the desired attention backend using `PyTorchConfig.attn_backend`. For instance, to utilize the Flashinfer ba...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc3.md
3713fa5e-e134-52ba-a19c-edf0235e4077
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc3
2
1. **FP8 Quantization**: This feature enables the quantization of inputs and KV cache into FP8 format, significantly reducing memory usage and improving computational throughput. 2. **RoPE Fusion**: By integrating rotary position embedding (RoPE) directly into the attention computation, this feature enhances efficiency...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc3.md
62fed1b5-d927-54a7-8529-3a9ece2bb0ef
docs
nvidia_tensorrt-llm
nvidia_tensorrt-llm_attention
120rc3
3
## Implement a New Attention Backend[#](#implement-a-new-attention-backend "Link to this heading") You can implement a new attention backend to integrate other attention libraries. An attention backend consists of an `AttentionBackend` class and an `AttentionMetadata` class. There are three stages in the PyTorch that ...
large_dataset/raw/docs/nvidia_tensorrt-llm/attention/attention_120rc3.md