#12789 Replace assert statements with exceptions#13909
#12789 Replace assert statements with exceptions#13909sgugger merged 3 commits intohuggingface:masterfrom
Conversation
|
Can someone please take a look at my PR. The error log mentions a config.json file to be missing in a tmp directory and then goes on to throw 2 assertion errors. But the files where I have made my changes are not mentioned in the logs anywhere. I'm having trouble understanding why my changes may have caused a missing config file. Sorry about the force-push, it was required for a little cleanup. |
…tion-answering and examples/tensorflow/question-answering
47baaa0 to
8bebcd9
Compare
sgugger
left a comment
There was a problem hiding this comment.
Thanks a lot for fixing those! I've left suggestions in the flax utils (but the others are the same). Could you put them in the three files?
| ``logging`` log level (e.g., ``logging.WARNING``) | ||
| """ | ||
| assert len(predictions) == 2, "`predictions` should be a tuple with two elements (start_logits, end_logits)." | ||
| if not len(predictions) == 2: |
There was a problem hiding this comment.
| if not len(predictions) == 2: | |
| if len(predictions) != 2: |
Will be easier to understand like this :-)
There was a problem hiding this comment.
Yeah sure I'll make the changes and push
There was a problem hiding this comment.
I have pushed the changes. Thanks a lot for the experience!
| all_start_logits, all_end_logits = predictions | ||
|
|
||
| assert len(predictions[0]) == len(features), f"Got {len(predictions[0])} predictions and {len(features)} features." | ||
| if not len(predictions[0]) == len(features): |
There was a problem hiding this comment.
| if not len(predictions[0]) == len(features): | |
| if len(predictions[0]) != len(features): |
| ``logging`` log level (e.g., ``logging.WARNING``) | ||
| """ | ||
| assert len(predictions) == 5, "`predictions` should be a tuple with five elements." | ||
| if not len(predictions) == 5: |
There was a problem hiding this comment.
| if not len(predictions) == 5: | |
| if len(predictions) != 5: |
| assert len(predictions[0]) == len( | ||
| features | ||
| ), f"Got {len(predictions[0])} predicitions and {len(features)} features." | ||
| if not len(predictions[0]) == len(features): |
There was a problem hiding this comment.
| if not len(predictions[0]) == len(features): | |
| if len(predictions[0]) != len(features): |
|
Thanks again! |
What does this PR do?
Replaces the assertions in utils_qa.py file at examples/tensorflow/question-answering, examples/flax/question-answering and examples/pytorch/question-answering (bound by strict copy check) with ValueError and EnvironmentError exceptions as necessary.
Also fixed a typo changing predicitions -> predictions in postprocess_qa_predictions_with_beam_search function.
Contributes towards fixing issue #12789
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.