custom processor for omni poc - #4839
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for the 'omni-gemma3-qwen3' stitched model, combining the Gemma 3 vision encoder with the Qwen 3 LLM decoder. It includes configuration updates, routing logic in the multimodal processor, a decoding evaluation script, and corresponding unit tests. The review feedback highlights a 2-token discrepancy in the image offset calculation that needs alignment with the token expansion logic, along with a performance optimization in the decoding loop to use jnp.argmax instead of np.argmax to avoid costly device-to-host transfers.
cf8e290 to
ff229f4
Compare
|
🤖 Hi @subawocit, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
This Pull Request introduces a custom multimodal processor and evaluation script for "omni-gemma3-qwen3," a stitched pilot model combining a Gemma 3 Vision Encoder with a Qwen 3 LLM Decoder. The implementation is of very high quality, with robust unit testing, flexible routing, and extremely clean integration with MaxText's layers and checkpointers.
🔍 General Feedback
- Component Design: The routing and preprocessing are designed elegantly, utilizing local/dynamic imports (
import-outside-toplevel) in the generic multimodal processor, which cleanly isolates the experimental model pilot from the core codebase. - Robustness of Stitching Tests: The checkpoint stitching tests are very comprehensive and cover both structural correctness (layer counts) and parameter-restore verification.
- Evaluation Tooling: The inclusion of
decode_omni.pyas a standalone verification and evaluation tool on the ChartQA dataset is excellent for model validation.
a4ca741 to
52de482
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
52de482 to
342c91d
Compare
Description
This PR introduces the implementations for hybrid multimodal processor.
Specifically, it implements modular hybrid multimodal support in the preprocessing and fusion pipelines:
<|vision_start|>,<|image_pad|>,<|vision_end|>) and tokenized by the text decoder's tokenizer.<|image_pad|>. This ensures the text decoder knows precisely where to inject the 256 projected visual embeddings within the token stream without corrupting text subword tokenization or array indexing.This is Step 3 of a 5-step Proof-of-Concept for any-to-any multimodal alignment in MaxText. Overall goal is to align a pretrained vision encoders with another text-only LLM, and connecting the two with a dynamically configured adaptation layer (customized MLP connector), special tokenizer mapping for visual placeholder tokens, and train only the MLP using supervised fine tuning.
Files
Omni Multimodal Processor
experimental/omni_poc/utils/processor_omni_gemma3_qwen3.py<|vision_start|>,<|image_pad|>,<|vision_end|>) combining Qwen 3's vocabulary with Gemma 3's visual token (256 tokens per image).get_image_offsets_omni,add_extra_tokens_for_omni).Name Registration & Routing
multimodal/processor.py,layers/decoders.py, andlayers/nnx_decoders.pyprocessor.pyfor models withvision_block == "gemma3"anddecoder_block == "qwen3".omni-gemma3-qwen3model name.Unit Tests
experimental/omni_poc/tests/processor_omni_gemma3_qwen3_test.pytests/unit/multimodal_utils_test.pyomni-gemma3-qwen3routing and fusion masking in the multimodal processor.End-to-End Decoding
experimental/omni_poc/utils/decode_omni.pyCheckpoint Stitching (Minor Change)
experimental/omni_poc/utils/stitch_checkpoint.pyexperimental/omni_poc/tests/stitch_checkpoint_test.pyConfiguration (Minor Change)
experimental/omni_poc/omni-gemma3-qwen3.ymlTests
1. Checkpoint Stitching Generation
Generated a stitched Orbax checkpoint from converted Gemma 3 4B vision weights and Qwen 3 4B language weights:
JAX_PLATFORMS=cpu python -m maxtext.experimental.omni_poc.utils.stitch_checkpoint \ src/maxtext/experimental/omni_poc/omni-gemma3-qwen3.yml \ --vision_load_path=gs://yuchenhou-maxtext-logs/omni_checkpoints/gemma3-4b_converted/0/items \ --llm_load_path=gs://yuchenhou-maxtext-logs/omni_checkpoints/qwen3-4b_converted/0/items \ --stitched_output_path=gs://yuchenhou-maxtext-logs/omni_checkpoints/omni_stitched_gemma3-4b_qwen3-4b/0/items2. Checkpoint Stitching Unit Test
Verified that the stitched checkpoint accurately preserves original weights from both source models:
OMNI_TEST_BASE_DIR='gs://yuchenhou-maxtext-logs/omni_checkpoints' JAX_PLATFORMS=cpu \ /home/yuchenhou_google_com/maxtext_env/bin/python -m unittest src/maxtext/experimental/omni_poc/tests/stitch_checkpoint_test.pyOutput:
3. Omni Processor Unit Test
Verified token ID mappings, sequence expansions, and offsets:
Output:
4. Multimodal Processor Unit Tests
Verified hybrid multimodal routing and fusion:
Output:
5. End-to-End Multimodal Decoding
Ran end-to-end decoding on ChartQA validation samples using the stitched checkpoint:
JAX_PLATFORMS=tpu /home/yuchenhou_google_com/maxtext_env/bin/python src/maxtext/experimental/omni_poc/utils/decode_omni.py \ --checkpoint_path="gs://yuchenhou-maxtext-logs/omni_checkpoints/omni_stitched_gemma3-4b_qwen3-4b/0/items" \ --num_samples=2 \ --max_new_tokens=64Output:
This ensures the data is flowing end to end. The response itself does not make sense due to the randomly initialized projector, as expected.
Step-by-Step Objectives
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.