llmcompressor.modifiers.transform.awq.dynamic_mappings
Dynamic AWQ mapping builders for hybrid attention models.
Models with hybrid attention (mix of full self-attention and linear/Gated DeltaNet attention) need layer-index-specific AWQ mappings that vary by model size. This module provides runtime detection and mapping generation for such architectures (e.g. Qwen3Next, Qwen3.5).
Functions:
-
get_layer_mappings_from_model–Infer AWQ mappings from a model. Checks the dynamic mapping registry
build_gemma4_mappings
Build AWQ mappings for Gemma4ForConditionalGeneration and Gemma4UnifiedForConditionalGeneration.
Gemma4 has hybrid attention with two types of layers: - sliding_attention layers: have separate k_proj and v_proj (GQA) - full_attention layers: share k=v projection (no separate v_proj)
For sliding_attention layers with GQA, the v_proj -> o_proj mapping is skipped since it would hit a GQA dimension mismatch. For full_attention layers, k and v are shared, so the k_proj -> o_proj mapping is also skipped since altering k_proj would change the attention behavior.
Source code in src/llmcompressor/modifiers/transform/awq/dynamic_mappings.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
build_hybrid_attention_mappings
Dynamically build AWQ mappings for models with hybrid attention (full self-attention + linear/Gated DeltaNet attention), such as Qwen3Next and Qwen3.5.
Reads layer_types from the model config to determine which layers use full vs linear attention, then inspects the model's module names to detect the correct linear attention projection names and MLP structure.
Returns None if the model is not a hybrid attention model.
Source code in src/llmcompressor/modifiers/transform/awq/dynamic_mappings.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 | |
build_step3p5_mappings
Dynamically build AWQ mappings for Step3p5 models.
Step-3.5-Flash uses dense FFN layers early in the stack and MoE FFN layers later in the stack. The dense and MoE post-attention mappings must be layer-index-specific so AWQ only groups each norm with balance layers that exist in the same decoder layer.
Source code in src/llmcompressor/modifiers/transform/awq/dynamic_mappings.py
get_layer_mappings_from_model
Infer AWQ mappings from a model. Checks the dynamic mapping registry first (for models needing runtime-generated mappings), then falls back to the static registry, then to default mappings.
Parameters:
-
model(Module) –the model to infer mappings for
Returns:
-
list[AWQMapping]–list of AWQMapping for the model