Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions swift/template/templates/gemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ def replace_tag(self, media_type: Literal['image', 'video', 'audio'], index: int
return ['<start_of_image>']

def _encode(self, inputs: StdTemplateInputs) -> Dict[str, Any]:
from transformers.models.gemma3.processing_gemma3 import Gemma3ProcessorKwargs

encoded = super()._encode(inputs)
# Keep text-only rows aligned with multimodal rows in mixed batches.
encoded['token_type_ids'] = [0] * len(encoded['input_ids'])
if inputs.images:
from transformers.models.gemma3.processing_gemma3 import Gemma3ProcessorKwargs

input_ids = encoded['input_ids']
labels = encoded['labels']
loss_scale = encoded.get('loss_scale', None)
Expand Down
5 changes: 3 additions & 2 deletions tests/general/test_gemma3_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def test_text_only_encode_has_token_type_ids(self):
encoded = {'input_ids': [2, 10, 20], 'labels': [-100, 10, 20]}
inputs = SimpleNamespace(images=[])

with patch.object(Gemma3Template, '_encode', return_value=encoded):
result = template._encode(inputs)
with patch.dict('sys.modules', {'transformers.models.gemma3.processing_gemma3': None}):
with patch.object(Gemma3Template, '_encode', return_value=encoded):
result = template._encode(inputs)

self.assertEqual(result['token_type_ids'], [0, 0, 0])
6 changes: 3 additions & 3 deletions tests/llm/test_web_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from swift.arguments import WebUIArguments
from swift.ui import webui_main

if __name__ == '__main__':
from swift.arguments import WebUIArguments
from swift.ui import webui_main

webui_main(WebUIArguments())
Loading