fix: raise clear ValueError when add_batch receives None inputs#757
Open
YousefZahran1 wants to merge 1 commit into
Open
fix: raise clear ValueError when add_batch receives None inputs#757YousefZahran1 wants to merge 1 commit into
YousefZahran1 wants to merge 1 commit into
Conversation
Previously, passing None as predictions or references to add_batch() caused a cryptic 'TypeError: object of type NoneType has no len()' deep inside the Arrow serialisation path (module.py:518), making it hard to diagnose. The TypeError was re-raised from inside the except handler (line 523), which also called len() on the None value and crashed again. Fix: validate the batch dict immediately after construction and raise a descriptive ValueError that names the offending fields and directs the user to check their compute_metrics function. Fixes huggingface#668
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
add_batch()crashed with a crypticTypeError: object of type 'NoneType' has no len()whenpredictionsorreferenceswasNone. The error originated at line 518 (if len(column) > 0), was caught by theexcept (pa.ArrowInvalid, TypeError)handler, then immediately crashed again at line 523 (len(batch[c])) — producing a second, equally confusing traceback.Why
This affects anyone following the HuggingFace Trainer tutorial whose
compute_metricsfunction conditionally returnsNone(e.g. when evaluation data is partially unavailable). The root error message gives no indication which field wasNoneor why.Reproduce
Fix
Validate the batch dict immediately after construction and raise a descriptive
ValueErrorthat names the offending fields and tells the user to check theircompute_metricsreturn value. The change is 6 lines.Testing
Fixes #668