Coverage for transformer_lens/model_bridge/supported_architectures/qwen3_vl_moe.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2026-08-11 18:50 +0000

1"""Qwen3-VL-MoE architecture adapter. 

2 

3Alibaba's Qwen3-VL-MoE (``Qwen3VLMoeForConditionalGeneration``): the 

4Qwen3-VL layout (DeepStack vision tower, interleaved-mRoPE text decoder) 

5with a sparse-MoE MLP — batched experts plus a parameter-only top-k 

6router returning a (logits, scores, indices) tuple, so the router stays 

7unwrapped and MoEBridge delegates the block. Layers listed in 

8``mlp_only_layers`` hold a dense gated MLP under the same name. 

9""" 

10 

11from typing import Any 

12 

13from transformer_lens.model_bridge.generalized_components import ( 

14 MoEBridge, 

15 MoERouterBridge, 

16) 

17from transformer_lens.model_bridge.supported_architectures.qwen3_vl import ( 

18 Qwen3VLArchitectureAdapter, 

19) 

20 

21 

22class Qwen3VLMoeArchitectureAdapter(Qwen3VLArchitectureAdapter): 

23 """Architecture adapter for Qwen3VLMoeForConditionalGeneration models.""" 

24 

25 def _build_mlp_bridge(self) -> Any: 

26 """Sparse MoE block; gate/experts absent on dense mlp_only_layers.""" 

27 return MoEBridge( 

28 name="mlp", 

29 config=self.cfg, 

30 submodules={ 

31 "gate": MoERouterBridge(name="gate", optional=True), 

32 "experts": MoEBridge(name="experts", config=self.cfg, optional=True), 

33 }, 

34 )