|
26 | 26 | RingAttention, |
27 | 27 | UlyssesAttention, |
28 | 28 | ) |
| 29 | +from tensorrt_llm._torch.visual_gen.attention_backend.trtllm import TrtllmAttention |
29 | 30 | from tensorrt_llm._torch.visual_gen.attention_backend.vanilla import VanillaAttention |
30 | 31 | from tensorrt_llm._torch.visual_gen.config import ( |
31 | 32 | DiffusionModelConfig, |
@@ -292,6 +293,43 @@ def test_attn2d_with_sequence_parallel_disabled_allowed(self): |
292 | 293 | assert isinstance(attn.attn, VanillaAttention) |
293 | 294 |
|
294 | 295 |
|
| 296 | +def _build_sage_routed_attention(qkv_mode: QKVMode): |
| 297 | + """Build a TRTLLM-SAGE-configured Attention for backend-routing checks.""" |
| 298 | + quant_cfg = QuantAttentionConfig( |
| 299 | + qk_dtype="int8", q_block_size=1, k_block_size=16, v_block_size=1 |
| 300 | + ) |
| 301 | + config = create_model_config( |
| 302 | + hidden_size=512, |
| 303 | + num_heads=4, |
| 304 | + head_dim=128, |
| 305 | + attn_backend="TRTLLM", |
| 306 | + quant_attention_config=quant_cfg, |
| 307 | + skip_create_weights_in_init=True, |
| 308 | + ) |
| 309 | + attn = Attention( |
| 310 | + hidden_size=512, |
| 311 | + num_attention_heads=4, |
| 312 | + head_dim=128, |
| 313 | + qkv_mode=qkv_mode, |
| 314 | + config=config, |
| 315 | + ) |
| 316 | + return attn, quant_cfg |
| 317 | + |
| 318 | + |
| 319 | +class TestSageAttentionBackendRouting: |
| 320 | + def test_self_attention_uses_trtllm_sage_backend(self): |
| 321 | + attn, quant_cfg = _build_sage_routed_attention(QKVMode.FUSE_QKV) |
| 322 | + assert attn.attn_backend == "TRTLLM" |
| 323 | + assert isinstance(attn.attn, TrtllmAttention) |
| 324 | + assert attn.attn.quant_attention_config == quant_cfg |
| 325 | + assert not attn.attn.support_fused_qkv() |
| 326 | + |
| 327 | + def test_cross_attention_with_sage_config_falls_back_to_vanilla(self): |
| 328 | + attn, _ = _build_sage_routed_attention(QKVMode.SEPARATE_QKV) |
| 329 | + assert attn.attn_backend == "VANILLA" |
| 330 | + assert isinstance(attn.attn, VanillaAttention) |
| 331 | + |
| 332 | + |
295 | 333 | # ============================================================================ |
296 | 334 | # Test functions |
297 | 335 | # ============================================================================ |
|
0 commit comments