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
+79-53Lines changed: 79 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,46 +27,85 @@ Multimodal Large Language Models (LLMs) extend traditional text-only models by i
27
27

28
28
*Figure 1: Overview of multimodal dataflow in MaxText.*
29
29
30
-
## Checkpoint Conversion
30
+
## Install MaxText
31
+
32
+
For instructions on installing MaxText on your VM, please refer to the [official documentation](../../install_maxtext.md#from-source) and use the `maxtext[tpu]` installation path to include all necessary dependencies.
31
33
32
-
Recently we have onboarded a new centralized tool for bidirectional checkpoint conversion between MaxText and HuggingFace ([README](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/checkpoint_conversion/README.md)).
34
+
> **Note:** If you have previously installed MaxText with a different option, we strongly recommend using a fresh virtual environment for `maxtext[tpu]` to avoid potential library version conflicts.
33
35
34
-
Install pytorch:
36
+
## Setup environment variables
35
37
38
+
Login to Hugging Face. Provide your access token when prompted:
### Option 2: Converting a Hugging Face checkpoint
80
+
81
+
Refer to [Hugging Face to MaxText](hf-to-maxtext) to convert a hugging face checkpoint to MaxText. Make sure you have correct checkpoint files converted and saved. Use this command to convert an unscanned checkpoint from HuggingFace to MaxText:
For the Llama4 model family, we are using a separate checkpoint conversion script (of note, we will gradually migrate all checkpoint conversion scripts to the above consolidated tool soon):
97
+
After conversion finishes, set `MAXTEXT_CKPT_PATH`to the converted MaxText checkpoint path.
59
98
60
-
```shell
61
-
export LOCAL_HF_MODEL_PATH=... # Need to pre-download the safetensors from HuggingFace
> The `scan_layers` setting during your fine-tuning run **must match** the setting used when creating the checkpoint at `MAXTEXT_CKPT_PATH`.
106
+
>
107
+
> - If the checkpoint was converted or saved with `scan_layers=False` (which is common for Hugging Face conversions and inference-ready models), you **must also provide `scan_layers=False` in the MaxText command.**
108
+
70
109
## Multimodal Decode
71
110
72
111
MaxText supports multimodal decoding, allowing you to input text with multiple images to get a text output. To use this feature, you need three main settings:
@@ -77,23 +116,18 @@ MaxText supports multimodal decoding, allowing you to input text with multiple i
77
116
78
117
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.
79
118
80
-
### Decode with text+image
119
+
### Decode with Text + Image
81
120
82
121
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.
132
166
133
-
### Decode with text+video+audio
167
+
### Decode with Text + Video + Audio
134
168
135
169
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
170
137
-
```shell
171
+
```sh
138
172
# 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 \
173
+
export MAXTEXT_CKPT_PATH=<Checkpoint GCS path># gs://my-bucket/path/0/items for Qwen3-Omni
@@ -173,15 +204,10 @@ Supervised Fine-Tuning (SFT) of multimodal LLMs in MaxText focuses specifically
173
204
**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:
174
205
175
206
```shell
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