Extend LoRA for Gemma4#3969
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
2bc8632 to
ab61640
Compare
| def test_tokenizer_wo_generation_prompt(self): | ||
| verify_chat_template_generation_prompt_logic(self.llama2_tokenizer) | ||
|
|
||
| def test_tokenizer_gemma4_thought_channel_bypass(self): |
There was a problem hiding this comment.
This test expects to not fail with TemplateError or ValueError. Can you add an assertion for this so that it is readable what this test actually verifies?
There was a problem hiding this comment.
I updated verify_chat_template_generation_prompt_logic to return True on success, and wrapped all three test cases in explicit self.assertTrue() assertions.
This cleanly verifies that validation succeeds and keeps all tests uniform. All tests pass successfully!"
61626bd to
ef50ff7
Compare
| actual_prefix_in_full_turn = full_turn_ids[len(prompt_wo_gen_ids) : len(prompt_wo_gen_ids) + len(assistant_prefix)] | ||
|
|
||
| if actual_prefix_in_full_turn != assistant_prefix: | ||
| # Allow the generation prompt to include a thought channel block (e.g., for Gemma 4). |
There was a problem hiding this comment.
This logic looks like a hacky approach to support Gemma4. I am working on a generalized logic to support any model that requires specific prefix shifting. I will send out the PR soon.
There was a problem hiding this comment.
Agreed, it was definitely a workaround. Thanks for taking the lead on a generalized solution! I'll track #4010 and we can use that approach instead.
ef50ff7 to
5fd616b
Compare
Description
This PR extends the recent LoRA support to accurately target and process Gemma 4 architectures (including MoE).
Gemma 4 introduces complex nested structures (like scanned_blocks and layers_remainder) and unique chat template behaviors (such as the <|channel>thought block) that are incompatible with standard LoRA targeting and data
processing. Furthermore, MoE models require dynamic metadata synchronization during forward passes which is broken by aggressive NNX graph caching.
This PR addresses these challenges by:
Tests
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.