Skip to content
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

Permits TokenClassificationOption / DistilBertForTokenClassification to fail gracefully for an invalid configuration. #320

Merged
merged 7 commits into from
Jan 15, 2023

Conversation

andyHa
Copy link
Contributor

@andyHa andyHa commented Jan 6, 2023

A production system shouldn't panic, if an invalid config is present. The implementation
is placed in a new method, so that the change is non-breaking.

Copy link
Owner

@guillaume-be guillaume-be left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion @andyHa ,
I have a few minor comments on the DistilBert implementation. This applies to other models, could you please update all instances of unwrapping/expecting in these model instantiations for consistency ? If you do not have the capacity please let me know I'd be happy to support.

src/distilbert/distilbert_model.rs Outdated Show resolved Hide resolved
src/distilbert/distilbert_model.rs Outdated Show resolved Hide resolved
src/distilbert/distilbert_model.rs Outdated Show resolved Hide resolved
@andyHa andyHa closed this Jan 8, 2023
Instead of panic, we now return a proper RustBertError so that
an invalid model or config thereof wouldn't crash the whole system.
@andyHa andyHa reopened this Jan 8, 2023
@andyHa
Copy link
Contributor Author

andyHa commented Jan 8, 2023

Thank you for the suggestion @andyHa , I have a few minor comments on the DistilBert implementation. This applies to other models, could you please update all instances of unwrapping/expecting in these model instantiations for consistency ? If you do not have the capacity please let me know I'd be happy to support.

@guillaume-be thanks for the feedback - I updated all methods to consistently return a Result and changed all .expect to .ok_or_else(..)?

src/fnet/fnet_model.rs Outdated Show resolved Hide resolved
tests/fnet.rs Outdated
@@ -227,7 +228,7 @@ fn fnet_for_token_classification() -> anyhow::Result<()> {

// Forward pass
let model_output = no_grad(|| {
fnet_model
fnet_model.unwrap()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please be consistent for all tests with the model error handling (see the changes for albert for example):
let albert_model = AlbertForTokenClassification::new(vs.root(), &config)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@guillaume-be guillaume-be merged commit 445b76f into guillaume-be:master Jan 15, 2023
Miezhiko pushed a commit to Masha/rust-bert that referenced this pull request Mar 21, 2023
…to fail gracefully for an invalid configuration. (guillaume-be#320)

* Properly handle config errors when creating classification models

Instead of panic, we now return a proper RustBertError so that
an invalid model or config thereof wouldn't crash the whole system.

* Properly formats newly added code.

* Fixes an example within the documentation

* Properly unwraps the newly created results in unit tests.

* Fixes some code formatting issues.

* Uses proper/idiomatic error handling in unit tests.

* Moves the "?" to the correct position.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants