You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/posttraining/multimodal.md
+47-4Lines changed: 47 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,13 @@ This document provides a guide to use the multimodal functionalities in MaxText
8
8
9
9
We also provide a [colab](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/examples/multimodal_gemma3_demo.ipynb) for multimodal features demonstration. The following table provides a list of models and modalities we currently support:
@@ -73,6 +77,8 @@ MaxText supports multimodal decoding, allowing you to input text with multiple i
73
77
74
78
Since each model uses a unique native chatting template from its pretraining, we've implemented these specific templates within `multimodal_utils.py` and apply them directly to your prompt.
75
79
80
+
### Decode with text+image
81
+
76
82
To run a forward pass and verify the model's output, use the following command:
For larger models such as Llama4-Scout/Maverick, we suggest to run the decoding on a TPU cluster such as v5p-16.
126
132
133
+
### Decode with text+video+audio
134
+
135
+
For models that support video input (e.g., Qwen3-Omni and Qwen3.5), pass a video file via `video_path`. For Qwen3-Omni, which also supports audio, set `use_audio_in_video=true` to additionally process the embedded audio track. Since the required token budget scales with video length and resolution, set `max_prefill_predict_length` accordingly.
136
+
137
+
```shell
138
+
# Qwen3-Omni decode with video + audio
139
+
export MAXTEXT_CKPT_PATH=<Checkpoint GCS path># gs://my-bucket/path for Qwen3-Omni
prompt='What can you see and hear? Answer in one short sentence.' \
153
+
video_path='tests/assets/test_video.mp4' \
154
+
max_prefill_predict_length=1250 \
155
+
max_target_length=1280 \
156
+
add_bos=false \
157
+
attention='dot_product' \
158
+
```
159
+
160
+
The expected output will look similar to:
161
+
162
+
```
163
+
Input `<|im_start|>user
164
+
<|vision_start|><|video_pad|><|vision_end|>What can you see and hear? Answer in one short sentence.<|im_end|>
165
+
<|im_start|>assistant
166
+
` -> `A roaring Tyrannosaurus rex animatronic is displayed in a museum exhibit.
167
+
```
168
+
127
169
## Supervised Fine-Tuning
128
170
129
171
Supervised Fine-Tuning (SFT) of multimodal LLMs in MaxText focuses specifically on post-training; we don't yet support pre-training multimodal models from scratch. The SFT process typically involves training on Visual Question Answering (VQA) datasets where the model learns to generate accurate text responses based on both visual and textual inputs. During this fine-tuning phase, we recommend to freeze the pre-trained encoder layers (such as vision transformers) to preserve their learned visual representations, while the projection layers and LLM decoder components remain trainable. This selective training strategy allows the model to adapt the cross-modal alignment and text generation capabilities without disrupting the robust feature extraction abilities of the encoders, ultimately leading to improved performance on multimodal understanding and reasoning tasks while maintaining computational efficiency. This is achieved by setting `freeze_vision_encoder_params=True` in [sft-vision-chartqa.yml](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/configs/post_train/sft-vision-chartqa.yml).
130
-
Here, we use [ChartQA](https://huggingface.co/datasets/HuggingFaceM4/ChartQA) as an example to demonstrate SFT functionality:
172
+
173
+
**Text+image SFT is supported for all models listed above.** The following example uses Gemma3-4B with the [ChartQA](https://huggingface.co/datasets/HuggingFaceM4/ChartQA) dataset:
131
174
132
175
```shell
133
176
export MAXTEXT_CKPT_PATH=<your-checkpoints-path># either set to an already available MaxText ckpt or to the one we just converted in the previous step
0 commit comments