shentao.scott commited on
Commit
aad3282
·
1 Parent(s): 1bf6632

update readme

Browse files
Files changed (3) hide show
  1. README.md +217 -0
  2. doc/logo.png +3 -0
  3. doc/mammoth.png +3 -0
README.md ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center">
2
+
3
+
4
+ # MammothModa2: Jointly Optimized Autoregressive-Diffusion Models for Unified Multimodal Understanding and Generation
5
+ <img src='./doc/logo.png' alt="MammothModa Logo" width="100" style="max-width: 100px; height: auto;">
6
+
7
+ [![GitHub](https://img.shields.io/badge/MammothModa2-GitHub-blue)](https://github.com/bytedance/mammothmoda)
8
+ [![Project Page](https://img.shields.io/badge/MammothModa2-Project_Page-green)](https://ali-vilab.github.io/MammothModa-Page/)
9
+ [![HuggingFace](https://img.shields.io/badge/MammothModa2-HuggingFace_Model-yellow)](https://huggingface.co/bytedance-research/MammothModa2-Preview)
10
+
11
+ </div>
12
+
13
+
14
+ ## Introduction
15
+
16
+ MammothModa2 is a unified Autoregressive-Diffusion (AR-Diffusion) framework designed for comprehensive multimodal understanding and generation. The model adopts a novel serial architecture: the AR backbone utilizes MammothTok—a unified, language-aligned visual tokenizer—to execute complex semantic planning, which then conditions a high-fidelity Diffusion Decoder. Our core technical contribution is a unified joint training strategy, pioneering the simultaneous optimization of the discrete Next-Token Prediction (NTP) loss and the continuous Flow Matching loss within a serial AR-Diffusion system. This end-to-end alignment between the planning and generation spaces enables MammothModa to achieve competitive performance across complex text-to-image generation, editing, and visual understanding benchmarks.
17
+
18
+ ## Show cases
19
+ <!-- <div align="center">
20
+ <img src='./mammoth.png' alt="MammothModa Overview" width="80%">
21
+ </div> -->
22
+
23
+ <div align="center">
24
+ <img src='./doc/mammoth.png' alt="MammothModa2 Show cases" style="max-width: 80%; height: auto;">
25
+ </div>
26
+
27
+ ## 🎉 News
28
+ - [x] 2025-10-01: 🔥MammothModa2-Preview models are now available at [HuggingFace](https://huggingface.co/bytedance-research/MammothModa2-Preview)
29
+
30
+
31
+ ## 🪄 Models
32
+ | Model | Download Link | License |
33
+ |-------|---------------|----------|
34
+ | MammothModa2-Preview | [🤗 HuggingFace](https://huggingface.co/bytedance-research/MammothModa2-Preview) | [Apache-2.0](https://opensource.org/licenses/Apache-2.0) |
35
+
36
+ ## ⚙️ Installation
37
+
38
+ The codebase has been tested with Python 3.11.9, CUDA 12.4, and PyTorch 2.6.0. You can set up the environment using uv with the following command:
39
+
40
+ ```bash
41
+ # Clone the repository
42
+ git clone https://github.com/bytedance/mammothmoda.git
43
+ cd mammothmoda
44
+
45
+ # Install dependencies
46
+ uv sync --frozen
47
+ ```
48
+
49
+ ## 🚀 Usage
50
+
51
+ ### Text-to-Image Generation
52
+
53
+ ```python
54
+ import torch
55
+ from qwen_vl_utils import process_vision_info
56
+ from transformers import AutoProcessor
57
+ from mammothmoda2.model import DEFAULT_NEGATIVE_PROMPT, Mammothmoda2Model
58
+ from mammothmoda2.utils import decode_diffusion_image
59
+
60
+ # Mammothmoda2 model and processor loading.
61
+ model = Mammothmoda2Model.from_pretrained(
62
+ "bytedance-research/MammothModa2-Preview",
63
+ attn_implementation="flash_attention_2",
64
+ torch_dtype="bfloat16",
65
+ t2i_generate=True,
66
+ ).to("cuda")
67
+ processor = AutoProcessor.from_pretrained(
68
+ "bytedance-research/MammothModa2-Preview",
69
+ t2i_generate=True,
70
+ ar_height=32,
71
+ ar_width=32,
72
+ )
73
+
74
+ # Mammothmoda2 inputs preprocessing.
75
+ messages = [
76
+ {
77
+ "role": "user",
78
+ "content": [
79
+ {
80
+ "type": "text",
81
+ "text": "这张图片展示了一座现代化城市的美丽景象。画面中最显眼的是一座高耸入云的摩天大楼,其外立面在夕阳余晖的映照下显得格外醒目。周围环绕着多栋风格各异的高楼大厦,这些大楼的窗户透出点点灯光,显示出城市的繁华。左侧有一座带有绿色圆顶的建筑,造型独特。在建筑物前方的水面上,有几艘白色的帆船正在航行,给城市增添了一份灵动的气息。天空呈现出浪漫的粉色,可能是日出或日落时分,整个画面色彩柔和,充满了宁静与美好的氛围。",
82
+ },
83
+ ],
84
+ }
85
+ ]
86
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
87
+ image_inputs, video_inputs = process_vision_info(messages)
88
+ inputs = processor(
89
+ text=[text],
90
+ images=image_inputs,
91
+ videos=video_inputs,
92
+ num_images_per_prompt=4,
93
+ cfg_scale=6.0,
94
+ negative_prompt=DEFAULT_NEGATIVE_PROMPT,
95
+ padding=True,
96
+ padding_side="left",
97
+ return_tensors="pt",
98
+ return_token_type_ids=False, # Or generate would raise error.
99
+ ).to("cuda")
100
+
101
+ # Mammothmoda2 t2i generate.
102
+ with torch.inference_mode(), torch.autocast(device_type="cuda", dtype=torch.bfloat16):
103
+ generated_ids, attention_mask = model.generate(**inputs)
104
+ diff_return_info = decode_diffusion_image(
105
+ input_ids=inputs.input_ids,
106
+ generated_ids=generated_ids,
107
+ attention_mask=attention_mask,
108
+ negative_ids=inputs.get("negative_ids", None),
109
+ negative_mask=inputs.get("negative_mask", None),
110
+ model=model,
111
+ tokenizer=processor.tokenizer,
112
+ output_dir="./mammothmoda2_t2i_release",
113
+ num_images_per_prompt=4,
114
+ text_guidance_scale=9.0,
115
+ vae_scale_factor=16,
116
+ cfg_range=(0.0, 1.0),
117
+ num_inference_steps=50,
118
+ height=1024,
119
+ width=1024,
120
+ )
121
+ ```
122
+
123
+ ### Multi-modal Understanding
124
+
125
+ ```python
126
+ import torch
127
+ from qwen_vl_utils import process_vision_info
128
+ from transformers import AutoProcessor
129
+ from mammothmoda2.model import Mammothmoda2Model
130
+
131
+ # Mammothmoda2 model and processor loading.
132
+ model = Mammothmoda2Model.from_pretrained(
133
+ "bytedance-research/MammothModa2-Preview",
134
+ attn_implementation="flash_attention_2",
135
+ torch_dtype="bfloat16",
136
+ ).to("cuda")
137
+ print(f"model.device={model.device}")
138
+ processor = AutoProcessor.from_pretrained("bytedance-research/MammothModa2-Preview")
139
+
140
+ # Mammothmoda2 inputs preprocessing.
141
+ messages = [
142
+ {
143
+ "role": "user",
144
+ "content": [
145
+ {
146
+ "type": "image",
147
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
148
+ },
149
+ {"type": "text", "text": "Describe this image."},
150
+ ],
151
+ }
152
+ ]
153
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
154
+ image_inputs, video_inputs = process_vision_info(messages)
155
+ inputs = processor(
156
+ text=[text],
157
+ images=image_inputs,
158
+ videos=video_inputs,
159
+ padding=True,
160
+ padding_side="left",
161
+ return_tensors="pt",
162
+ return_token_type_ids=False,
163
+ ).to("cuda")
164
+
165
+ # Mammothmoda2 model generation and decoding.
166
+ with torch.inference_mode(), torch.autocast(dtype=torch.bfloat16):
167
+ generated_ids = model.generate(**inputs)
168
+ generated_ids_trimmed = [out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]
169
+ output_texts = processor.batch_decode(
170
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
171
+ )
172
+ print(output_texts)
173
+ ```
174
+
175
+ ## 📊 Benchmark Results
176
+
177
+ | Model | Model Size | GenEval | DPGBench |
178
+ |-------|------------|---------|----------|
179
+ | **Generation** |
180
+ | SDXL | - | 0.55 | 74.65 |
181
+ | DALL-E 3 | - | 0.67 | 83.50 |
182
+ | FLUX.1-dev | - | 0.67 | 84.00 |
183
+ | SD3.5-Medium* | - | 0.65 | 83.86 |
184
+ | **Unified** |
185
+ | Emu3 | 8B | 0.66 | 80.60 |
186
+ | Janus-Pro | 7B | 0.80 | 84.19 |
187
+ | MetaQuery-XL | 7B + 1.6B | 0.80 | 82.05 |
188
+ | UniWorld-V1 | 7B + 12B | 0.84 | 81.38 |
189
+ | Blip3-o-8B | 7B + 1.4B | 0.84 | 81.60 |
190
+ | OmniGen2 | 3B + 4B | 0.86 | 83.57 |
191
+ | Ovis-U1 | 2.4B + 1.2B | 0.89 | 83.72 |
192
+ | UniPic2 | 7B + 2B | 0.90 | 83.79 |
193
+ | BAGEL | 7B + 7B | 0.88 | 85.07 |
194
+ | Show-o2 | 7B | 0.76 | 86.14 |
195
+ | GPT-4o | - | 0.84 | 86.23 |
196
+ | MammothModa2-Preview | 7B + (3B + 2B) | 0.85 | 87.1 |
197
+
198
+ **Note**: Model sizes in "A + B" format indicate separate understanding (A) and generation (B) parameters. Models without "+" share parameters for both tasks. MammothModa2-Preview uses a 7B + (3B + 2B) architecture, where the 7B parameters are for understanding, and the generation part consists of 3B parameters in the AR (MLLM backbone) and 2B parameters in the DiT component.
199
+
200
+
201
+ ## Acknowledgement
202
+
203
+ We are grateful to the following open-source projects:
204
+
205
+ - [OmniGen2](https://github.com/VectorSpaceLab/OmniGen2)
206
+ - [Qwen3-VL](https://github.com/QwenLM/Qwen3-VL)
207
+
208
+
209
+ ## Citation
210
+
211
+ ```bibtex
212
+ @misc{mammothmoda2025,
213
+ title = {MammothModa2: Jointly Optimized Autoregressive-Diffusion Models for Unified Multimodal Understanding and Generation},
214
+ author = {MammothModa Team},
215
+ year = {2025},
216
+ url = {https://github.com/bytedance/mammothmoda}
217
+ }
doc/logo.png ADDED

Git LFS Details

  • SHA256: f3a7f4b55da91063e4fb1129b0cd9810ab1a62c4770650575c7797c77e5a2b2e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.09 MB
doc/mammoth.png ADDED

Git LFS Details

  • SHA256: 44f53e8552f252cb4c6f344b251885ee44382e4dd088e2cc8938c2a2eaf578a6
  • Pointer size: 132 Bytes
  • Size of remote file: 3.73 MB