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

9 statements  

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

1"""Emu3 architecture adapter. 

2 

3BAAI's Emu3 (``Emu3ForConditionalGeneration``, native in transformers): 

4unified next-token prediction over text AND image tokens — images are 

5VQ-VAE-quantized into the shared vocabulary, so one Llama-shaped decoder 

6(at ``model.text_model``) generates both modalities. The VQ tokenizer 

7(``model.vqmodel``) is not mapped: it has no forward (encode/decode only) 

8and images become ordinary tokens before the decoder runs — reach it via 

9bridge.original_model. 

10""" 

11 

12from typing import Any 

13 

14from transformer_lens.model_bridge.supported_architectures.llama import ( 

15 LlamaArchitectureAdapter, 

16) 

17 

18 

19class Emu3ArchitectureAdapter(LlamaArchitectureAdapter): 

20 """Architecture adapter for Emu3ForConditionalGeneration models.""" 

21 

22 _testing_lm_attr = "model.text_model" 

23 _testing_eager = "config" 

24 

25 def __init__(self, cfg: Any) -> None: 

26 super().__init__(cfg) 

27 

28 self.cfg.is_multimodal = True 

29 self._reprefix_components("model.", "model.text_model.")