vllm.v1.attention.ops.merge_attn_states
¶
Functions:
-
merge_attn_states–Merge partial attention outputs from prefix (KV cache) and suffix
merge_attn_states(output, prefix_output, prefix_lse, suffix_output, suffix_lse, output_lse=None, prefill_tokens_with_context=None, output_scale=None)
¶
Merge partial attention outputs from prefix (KV cache) and suffix (new tokens) into a single output tensor using the log-sum-exp (LSE) rescaling method described in section 2.2 of https://www.arxiv.org/pdf/2501.01005.
For tokens that have prefix context (token index < prefill_tokens_with_context), the prefix and suffix partial outputs are combined as a weighted sum. For tokens without prefix context, the suffix output is copied directly.
Parameters:
-
(output¶Tensor) –Output tensor of shape [NUM_TOKENS, NUM_HEADS, HEAD_SIZE].
-
(prefix_output¶Tensor) –Partial attention output over the prefix (KV cache), shape [NUM_TOKENS, NUM_HEADS, HEAD_SIZE].
-
(prefix_lse¶Tensor) –Log-sum-exp values for the prefix attention, shape [NUM_HEADS, NUM_TOKENS].
-
(suffix_output¶Tensor) –Partial attention output over the suffix (new KV), shape [NUM_TOKENS, NUM_HEADS, HEAD_SIZE].
-
(suffix_lse¶Tensor) –Log-sum-exp values for the suffix attention, shape [NUM_HEADS, NUM_TOKENS].
-
(output_lse¶Tensor | None, default:None) –Optional tensor to store the merged LSE values, shape [NUM_HEADS, NUM_TOKENS]. If None, LSE is not written out.
-
(prefill_tokens_with_context¶int | None, default:None) –Number of prefill tokens that have prefix context and therefore require merging. Tokens at indices
= this value are decode or context-free prefill tokens whose output is taken directly from suffix_output. If None, all tokens are treated as having context.
-
(output_scale¶Tensor | None, default:None) –Optional scalar tensor for FP8 static quantization. When provided, output must be FP8 dtype.
Source code in vllm/v1/attention/ops/merge_attn_states.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |