Views
No views yet


| Model | Download Link | License |
|---|---|---|
| MammothModa2-Preview | 🤗 HuggingFace | Apache-2.0 |
1# Clone the repository
2git clone https://github.com/bytedance/mammothmoda.git
3cd mammothmoda
4
5# Install dependencies
6uv sync --frozen1import torch
2from qwen_vl_utils import process_vision_info
3from transformers import AutoProcessor
4from mammothmoda2.model import DEFAULT_NEGATIVE_PROMPT, Mammothmoda2Model
5from mammothmoda2.utils import decode_diffusion_image
6
7# Mammothmoda2 model and processor loading.
8model = Mammothmoda2Model.from_pretrained(
9 "bytedance-research/MammothModa2-Preview",
10 attn_implementation="flash_attention_2",
11 torch_dtype="bfloat16",
12 t2i_generate=True,
13).to("cuda")
14processor = AutoProcessor.from_pretrained(
15 "bytedance-research/MammothModa2-Preview",
16 t2i_generate=True,
17 ar_height=32,
18 ar_width=32,
19)
20
21# Mammothmoda2 inputs preprocessing.
22messages = [
23 {
24 "role": "user",
25 "content": [
26 {
27 "type": "text",
28 "text": "这张图片展示了一座现代化城市的美丽景象。画面中最显眼的是一座高耸入云的摩天大楼,其外立面在夕阳余晖的映照下显得格外醒目。周围环绕着多栋风格各异的高楼大厦,这些大楼的窗户透出点点灯光,显示出城市的繁华。左侧有一座带有绿色圆顶的建筑,造型独特。在建筑物前方的水面上,有几艘白色的帆船正在航行,给城市增添了一份灵动的气息。天空呈现出浪漫的粉色,可能是日出或日落时分,整个画面色彩柔和,充满了宁静与美好的氛围。",
29 },
30 ],
31 }
32]
33text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
34image_inputs, video_inputs = process_vision_info(messages)
35inputs = processor(
36 text=[text],
37 images=image_inputs,
38 videos=video_inputs,
39 num_images_per_prompt=4,
40 cfg_scale=6.0,
41 negative_prompt=DEFAULT_NEGATIVE_PROMPT,
42 padding=True,
43 padding_side="left",
44 return_tensors="pt",
45 return_token_type_ids=False, # Or generate would raise error.
46).to("cuda")
47
48# Mammothmoda2 t2i generate.
49with torch.inference_mode(), torch.autocast(device_type="cuda", dtype=torch.bfloat16):
50 generated_ids, attention_mask = model.generate(**inputs)
51 diff_return_info = decode_diffusion_image(
52 input_ids=inputs.input_ids,
53 generated_ids=generated_ids,
54 attention_mask=attention_mask,
55 negative_ids=inputs.get("negative_ids", None),
56 negative_mask=inputs.get("negative_mask", None),
57 model=model,
58 tokenizer=processor.tokenizer,
59 output_dir="./mammothmoda2_t2i_release",
60 num_images_per_prompt=4,
61 text_guidance_scale=9.0,
62 vae_scale_factor=16,
63 cfg_range=(0.0, 1.0),
64 num_inference_steps=50,
65 height=1024,
66 width=1024,
67 )1import torch
2from qwen_vl_utils import process_vision_info
3from transformers import AutoProcessor
4from mammothmoda2.model import Mammothmoda2Model
5
6# Mammothmoda2 model and processor loading.
7model = Mammothmoda2Model.from_pretrained(
8 "bytedance-research/MammothModa2-Preview",
9 attn_implementation="flash_attention_2",
10 torch_dtype="bfloat16",
11).to("cuda")
12print(f"model.device={model.device}")
13processor = AutoProcessor.from_pretrained("bytedance-research/MammothModa2-Preview")
14
15# Mammothmoda2 inputs preprocessing.
16messages = [
17 {
18 "role": "user",
19 "content": [
20 {
21 "type": "image",
22 "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
23 },
24 {"type": "text", "text": "Describe this image."},
25 ],
26 }
27]
28text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
29image_inputs, video_inputs = process_vision_info(messages)
30inputs = processor(
31 text=[text],
32 images=image_inputs,
33 videos=video_inputs,
34 padding=True,
35 padding_side="left",
36 return_tensors="pt",
37 return_token_type_ids=False,
38).to("cuda")
39
40# Mammothmoda2 model generation and decoding.
41with torch.inference_mode(), torch.autocast(dtype=torch.bfloat16):
42 generated_ids = model.generate(**inputs)
43generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
44output_texts = processor.batch_decode(
45 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
46)
47print(output_texts)| Model | Model Size | GenEval | DPGBench |
|---|---|---|---|
| Generation | |||
| SDXL | - | 0.55 | 74.65 |
| DALL-E 3 | - | 0.67 | 83.50 |
| FLUX.1-dev | - | 0.67 | 84.00 |
| SD3.5-Medium* | - | 0.65 | 83.86 |
| Unified | |||
| Emu3 | 8B | 0.66 | 80.60 |
| Janus-Pro | 7B | 0.80 | 84.19 |
| MetaQuery-XL | 7B + 1.6B | 0.80 | 82.05 |
| UniWorld-V1 | 7B + 12B | 0.84 | 81.38 |
| Blip3-o-8B | 7B + 1.4B | 0.84 | 81.60 |
| OmniGen2 | 3B + 4B | 0.86 | 83.57 |
| Ovis-U1 | 2.4B + 1.2B | 0.89 | 83.72 |
| UniPic2 | 7B + 2B | 0.90 | 83.79 |
| BAGEL | 7B + 7B | 0.88 | 85.07 |
| Show-o2 | 7B | 0.76 | 86.14 |
| GPT-4o | - | 0.84 | 86.23 |
| MammothModa2-Preview | 7B + (3B + 2B) | 0.85 | 87.1 |
1@misc{mammothmoda2025,
2 title = {MammothModa2: Jointly Optimized Autoregressive-Diffusion Models for Unified Multimodal Understanding and Generation},
3 author = {MammothModa Team},
4 year = {2025},
5 url = {https://github.com/bytedance/mammothmoda}
6}