Skip to content

Commit f60719b

Browse files
committed
Update multimodal docs with new models
1 parent be7748b commit f60719b

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

docs/tutorials/posttraining/multimodal.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ This document provides a guide to use the multimodal functionalities in MaxText
88

99
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:
1010

11-
| Models | Input Modalities | Output Modalities |
12-
| :--------------------------------------------- | :--------------- | :---------------- |
13-
| - Gemma3-4B/12B/27B<br>- Llama4-Scout/Maverick | Text, images | Text |
11+
| Models | Input: Text | Input: Image | Input: Video | Input: Audio | Output |
12+
| :-------------------------- | :---------: | :----------: | :----------: | :----------: | :----: |
13+
| **Gemma3** (4B/12B/27B) ||| | | Text |
14+
| **Gemma4** (26B/31B) ||| | | Text |
15+
| **Llama4** (Scout/Maverick) ||| | | Text |
16+
| **Qwen3-Omni** ||||| Text |
17+
| **Qwen3.5** (35B/397B) |||| | Text |
1418

1519
## Introduction
1620

@@ -73,6 +77,8 @@ MaxText supports multimodal decoding, allowing you to input text with multiple i
7377

7478
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.
7579

80+
### Decode with text+image
81+
7682
To run a forward pass and verify the model's output, use the following command:
7783

7884
```shell
@@ -124,10 +130,47 @@ python -m maxtext.inference.decode \
124130

125131
For larger models such as Llama4-Scout/Maverick, we suggest to run the decoding on a TPU cluster such as v5p-16.
126132

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
140+
python -m maxtext.inference.decode \
141+
model_name=qwen3-omni-30b-a3b \
142+
tokenizer_path=Qwen/Qwen3-Omni-30B-A3B-Instruct \
143+
tokenizer_type=huggingface \
144+
load_parameters_path=${MAXTEXT_CKPT_PATH?}/0/items \
145+
per_device_batch_size=1 \
146+
run_name=ht_test \
147+
steps=1 \
148+
async_checkpointing=false \
149+
scan_layers=false \
150+
use_multimodal=true \
151+
use_audio_in_video=true \
152+
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+
127169
## Supervised Fine-Tuning
128170

129171
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:
131174

132175
```shell
133176
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

Comments
 (0)