vllm.attention.selector ¶
_cached_get_attn_backend cached ¶
_cached_get_attn_backend(
head_size: int,
dtype: dtype,
kv_cache_dtype: CacheDType | None,
block_size: int | None,
use_mla: bool = False,
has_sink: bool = False,
use_sparse: bool = False,
) -> type[AttentionBackend]
Source code in vllm/attention/selector.py
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 185 186 187 188 189 190 191 192 | |
get_attn_backend ¶
get_attn_backend(
head_size: int,
dtype: dtype,
kv_cache_dtype: str | None,
block_size: int | None,
use_mla: bool = False,
has_sink: bool = False,
use_sparse: bool = False,
) -> type[AttentionBackend]
Selects which attention backend to use and lazily imports it.
Source code in vllm/attention/selector.py
get_env_variable_attn_backend ¶
get_env_variable_attn_backend() -> (
AttentionBackendEnum | None
)
Get the backend override specified by the vLLM attention backend environment variable, if one is specified.
Returns:
- AttentionBackendEnum value if an override is specified
- None otherwise
Source code in vllm/attention/selector.py
get_global_forced_attn_backend ¶
get_global_forced_attn_backend() -> (
AttentionBackendEnum | None
)
Get the currently-forced choice of attention backend, or None if auto-selection is currently enabled.
global_force_attn_backend ¶
global_force_attn_backend(
attn_backend: AttentionBackendEnum | None,
) -> None
Force all attention operations to use a specified backend.
Passing None for the argument re-enables automatic backend selection.,
Arguments:
- attn_backend: backend selection (None to revert to auto)
Source code in vllm/attention/selector.py
global_force_attn_backend_context_manager ¶
global_force_attn_backend_context_manager(
attn_backend: AttentionBackendEnum,
) -> Generator[None, None, None]
Globally force a vLLM attention backend override within a context manager, reverting the global attention backend override to its prior state upon exiting the context manager.
Arguments:
- attn_backend: attention backend to force
Returns:
- Generator