Add omni_checkpoint_stitcher and omni-gemma3-qwen3 configuration - #4485
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
hengtaoguo
left a comment
There was a problem hiding this comment.
Thanks for the awesome groundwork!
There was a problem hiding this comment.
This test is great! I would slightly prefer this file hierarchy, so later you won't need to create new folders for every new helper functions:
omni_poc/
├── tests/
│ └── stitch_test.py
├── utils/
│ └── stitch_checkpoint.py
├── prepare_checkpoint.py (maybe convert to bash instead?)
└── omni-gemma3-qwen3.yml
There was a problem hiding this comment.
Good idea - I've reorganized the files
There was a problem hiding this comment.
Given its main job is converting checkpoints and calling stitch, would a simple Bash script be a cleaner fit here than Python? WDYT?
| # Combines LLM backbone from Qwen 3 4B with Vision features from Gemma 3 4B | ||
|
|
||
| # NOTE: model_name is set to "gemma3-4b" so encoders.py loads Gemma 3's Vision Tower without modification. | ||
| # Meanwhile, decoders.py can build Qwen 3 LLM decoder directly from reading `decoder_block: "qwen3"` below. |
There was a problem hiding this comment.
Thanks! Since Gemma3 was the first multimodal model in MaxText, all vision-related flags defaulted to Gemma3 values in base.yml and types.py. Just to confirm, is that why you didn't need to add any multimodal configs here?
Even though the values would remain the same as the defaults, I'd highly recommend explicitly adding those specific vision configs below. It'll make this YAML file much more self-contained and easier to read.
There was a problem hiding this comment.
SG - I updated the yml and also did another test run to make sure the results are the same
hengtaoguo
left a comment
There was a problem hiding this comment.
Thanks for the great work!
| # Step 1 of 5 maxtext multimodal alignment proof of concept project. | ||
| # | ||
| # This file: | ||
| # 1. downloads and converts a Vision-Language model (e.g. gemma3-4b) from Hugging Face to MaxText format |
There was a problem hiding this comment.
nit: lower-case vision-language to align with text-only below?
| model_name: "gemma3-4b" | ||
| use_multimodal: true | ||
|
|
||
| image_size_for_vit: 896 |
There was a problem hiding this comment.
One comment line above for something like # Multimodal configs for gemma3 vision encoder?
There was a problem hiding this comment.
I put Multimodal config for vision model for now, but may need to modify the name and parameter structure during step 3
| HF_TOKEN="${HF_TOKEN:-}" | ||
|
|
||
| # Base GCS or local directory where converted and stitched checkpoints will be stored. | ||
| BASE_OUTPUT_DIRECTORY="gs://YOUR_BUCKET_NAME/omni_checkpoints" |
There was a problem hiding this comment.
Can you make this BASE_OUTPUT_DIRECTORY configurable in the usage example above? So later the user don't need to manually change any codes inside the bash script. Instead, they can easily set an env variable for the path.
ref:
maxtext/tests/end_to_end/tpu/deepseek/v3-671b/1_test_deepseek_mtp.sh
Lines 18 to 24 in fe5032a
5394457 to
5ebcc7f
Compare
| def setUp(self): | ||
| super().setUp() | ||
| # Read paths from environment variables or default to standard GCS bucket | ||
| default_dir = "gs://yuchenhou-maxtext-logs/omni_checkpoints" |
There was a problem hiding this comment.
Using a personal GCS bucket (yuchenhou-maxtext-logs) as the default fallback will cause automated CI runs or external developers to encounter permission errors if OMNI_TEST_BASE_DIR is not set in their environment.
Moreover it is not recommended, to use internal gcs bucket names in OOS repos.
There was a problem hiding this comment.
You can use mock for unit tests.
There was a problem hiding this comment.
Output path: Good catch - I just updated the the code such that the out dir must be set manually
OMNI_TEST_BASE_DIR=<path_to_omni_checkpoints> pytest src/maxtext/experimental/omni_poc/tests/stitch_checkpoint_test.pyMock for unit tests: Yes, good point, I had used mock models, and all the unit tests were passed. I later switched to use full checkpoints because we specifically needed to verify the vision and language output logits match the original source models exactly after stitching
a84c20c to
39a79d1
Compare
Add omni_checkpoint_stitcher and omni-gemma3-qwen3 configuration pylint add test file POC Phase 1: Implement checkpoint stitching and preparation pipeline reorg files better file description pyink pyink pyink improve print statement pyink pyink reorganize files rename files rm files small changes rm internal dir format
f1d26dd to
542fb6d
Compare
Description
This PR implements the multi-directory checkpoint loader. It loads pretrained parameter subtrees from two distinct checkpoints (e.g., a Gemma 3 vision tower and a Qwen 3 decoder as the initial setup) and merging them into a unified multimodal checkpoint.
Step 1 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 (MLP connector), special tokenizer mapping for visual placeholder tokens, and train only the MLP using supervised fine tuning.
Files
prepare_checkpoint.shMain script: download original vision and language models' checkpoints from Hugging Face, convert to MaxText format, and stitch two checkpoints into a single multimodal checkpoint.
omni-gemma3-qwen3.ymlConfiguration file combining the Qwen 3 4B language backbone with the Gemma 3 4B vision tower.
utils/stitch_checkpoint.pyCheckpoint stitcher utility that loads pretrained parameter subtrees from two separate checkpoints and merges them into a unified checkpoint.
tests/stitch_checkpoint_test.pyUnit tests.
Usage
The checkpoints from the stitched model will then be saved in output directory.
Tests
Unit tests:
Unit Test Results
Step-by-Step Objectives
√Multi-Directory Checkpoint Restoration: Implemented selective sub-tree parameter loading using Orbax such that we can initiaze a multimodal model with parameters from multiple checkpoints.nextDynamic MLP Connector: Add omni modal adapter layer (MLP) to connect vision tower output to the LLM decodernextSpecial Tokenizer & Placeholder Masking: Add special token <|image|> to tokenizer and make sure the masking is correct in the decoder.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.