Skip to content

Update gemma3_causal_lm_preprocessor.py #2217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ def call(

# Extract text part of the input.
prompts, responses = x["prompts"], x["responses"]
tf.debugging.assert_shapes([(prompts, ("N",)), (responses, ("N",))])

# Find out if the input is batched/not batched. Uprank if not batched.
# In other preprocessors, we don't have to do this, but here, all
Expand Down
14 changes: 14 additions & 0 deletions keras_hub/src/models/gemma3/gemma3_causal_lm_preprocessor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ def test_generate_postprocess(self):
x = preprocessor.generate_postprocess(input_data)
self.assertAllEqual(x, "the quick brown fox \n\n <start_of_image>")

def test_invalid_shape(self):
with self.assertRaises(ValueError):
input_data = {
"prompts": ["hello world", "this is testing"],
"responses": [""],
}
self.text_preprocessor(input_data)
with self.assertRaises(ValueError):
input_data = {
"prompts": ["hello world", "this is testing"],
"responses": ["hello", "", ""],
}
self.text_preprocessor(input_data)

@pytest.mark.kaggle_key_required
@pytest.mark.extra_large
def test_all_presets(self):
Expand Down
Loading