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

Empty assert hunt #6056

Merged
merged 7 commits into from
Aug 3, 2020
Merged

Empty assert hunt #6056

merged 7 commits into from
Aug 3, 2020

Conversation

TevenLeScao
Copy link
Contributor

@TevenLeScao TevenLeScao commented Jul 27, 2020

Empty asserts are bad for debugging. I tried to remove them all and to add helpful Pytorch-style messages with the shapes of the corresponding objects when they were mismatched-lengths checks + the file paths when they were file-not-found checks.

@codecov
Copy link

codecov bot commented Jul 27, 2020

Codecov Report

Merging #6056 into master will decrease coverage by 0.35%.
The diff coverage is 22.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6056      +/-   ##
==========================================
- Coverage   78.82%   78.47%   -0.36%     
==========================================
  Files         146      146              
  Lines       26200    26204       +4     
==========================================
- Hits        20653    20564      -89     
- Misses       5547     5640      +93     
Impacted Files Coverage Δ
src/transformers/commands/train.py 0.00% <ø> (ø)
src/transformers/data/metrics/__init__.py 26.66% <0.00%> (ø)
src/transformers/data/metrics/squad_metrics.py 0.00% <0.00%> (ø)
src/transformers/data/processors/utils.py 27.63% <0.00%> (ø)
src/transformers/data/processors/xnli.py 27.08% <0.00%> (-2.47%) ⬇️
src/transformers/modeling_albert.py 82.04% <0.00%> (ø)
src/transformers/modeling_bert.py 88.39% <0.00%> (ø)
src/transformers/modeling_electra.py 81.55% <0.00%> (ø)
src/transformers/modeling_gpt2.py 85.88% <0.00%> (ø)
src/transformers/modeling_mobilebert.py 89.45% <0.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12f1471...09c7880. Read the comment docs.

@mfuntowicz
Copy link
Member

I'm in love 😍 😍. Thanks @TevenLeScao !

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

This is great! Thanks a lot for fixing those!
(just one nit in passing)

src/transformers/convert_marian_to_pytorch.py Outdated Show resolved Hide resolved
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
src/transformers/commands/train.py Outdated Show resolved Hide resolved
self.state_dict = dict(self.state_dict)
self.wemb, self.final_bias = add_emb_entries(self.state_dict["Wemb"], self.state_dict[BIAS_KEY], 1)
self.pad_token_id = self.wemb.shape[0] - 1
cfg["vocab_size"] = self.pad_token_id + 1
# self.state_dict['Wemb'].sha
self.state_keys = list(self.state_dict.keys())
if "Wtype" in self.state_dict:
raise ValueError("found Wtype key")
assert "Wtype" not in self.state_dict, "Wtype key in state dictionary"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure ? it seems to me that the assert clause activates when the key is in the state dict, not the reverse, so that's what the error message should display

Copy link
Contributor

Choose a reason for hiding this comment

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

no you're correct. I don't see the value of the change but my suggestion is horrible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was just trying to harmonize things, not much of a change from raising an error to having an assert clause

src/transformers/convert_marian_to_pytorch.py Outdated Show resolved Hide resolved
Co-authored-by: Sam Shleifer <sshleifer@gmail.com>
self.state_dict = dict(self.state_dict)
self.wemb, self.final_bias = add_emb_entries(self.state_dict["Wemb"], self.state_dict[BIAS_KEY], 1)
self.pad_token_id = self.wemb.shape[0] - 1
cfg["vocab_size"] = self.pad_token_id + 1
# self.state_dict['Wemb'].sha
self.state_keys = list(self.state_dict.keys())
if "Wtype" in self.state_dict:
raise ValueError("found Wtype key")
assert "Wtype" not in self.state_dict, "Wtype key in state dictionary"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure ? it seems to me that the assert clause activates when the key is in the state dict, not the reverse, so that's what the error message should display

@TevenLeScao
Copy link
Contributor Author

@LysandreJik can I merge this?

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Yes, let's go! Thanks @TevenLeScao

@TevenLeScao TevenLeScao merged commit 5a0dac5 into huggingface:master Aug 3, 2020
Mehrad0711 pushed a commit to Mehrad0711/transformers that referenced this pull request Aug 3, 2020
* Fixed empty asserts

* black-reformatted stragglers in templates

* More code quality checks

* Update src/transformers/convert_marian_to_pytorch.py

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

* Update src/transformers/convert_marian_to_pytorch.py

Co-authored-by: Sam Shleifer <sshleifer@gmail.com>

* removed unused line as per @sshleifer

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sam Shleifer <sshleifer@gmail.com>
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.

None yet

5 participants