Fix: Handle empty prompt gracefully in make_seq2seq_fields with warning
#484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
fixes #483
This PR fixes the crash in
make_seq2seq_fieldswhen an empty prompt array is passed. Instead of crashing with a cryptic NumPy error, the function now handles empty prompts gracefully by issuing a warning and using a default BOS token as a fallback.Solution Overview
The fix adds input validation that:
UserWarningto alert usersChanges Made
File:
gemma/gm/data/_functional.pyLines 139-148: Added empty prompt handling with warning and fallback
Additional change: Added
import warningsat the top of the fileWhy This Solution?
Behavioral Changes
Before:
After:
Technical Details
Why BOS Token (2) as Fallback?
Code Flow
Before (Buggy):
After (Fixed):
Testing
The fix has been verified to:
Backward Compatibility
This change is fully backward compatible:
Files Changed
gemma/gm/data/_functional.py- Added empty prompt handling logic and warnings importRelated Issues
Fixes the crash described in the issue where empty prompts cause
ValueError: negative dimensions are not allowed.