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

Fix FlauBERT GPU test #6142

Merged
merged 2 commits into from
Jul 30, 2020
Merged

Fix FlauBERT GPU test #6142

merged 2 commits into from
Jul 30, 2020

Conversation

LysandreJik
Copy link
Member

No description provided.

@codecov
Copy link

codecov bot commented Jul 29, 2020

Codecov Report

Merging #6142 into master will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6142      +/-   ##
==========================================
- Coverage   78.35%   78.32%   -0.04%     
==========================================
  Files         146      146              
  Lines       26403    26403              
==========================================
- Hits        20689    20679      -10     
- Misses       5714     5724      +10     
Impacted Files Coverage Δ
src/transformers/modeling_flaubert.py 86.61% <100.00%> (ø)
src/transformers/generation_tf_utils.py 83.95% <0.00%> (-2.26%) ⬇️
src/transformers/file_utils.py 82.20% <0.00%> (-0.29%) ⬇️

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 54f9fbe...7034997. Read the comment docs.

@LysandreJik LysandreJik requested a review from sgugger July 29, 2020 19:08
if lengths is None:
if input_ids is not None:
lengths = (input_ids != self.pad_index).sum(dim=1).long()
else:
lengths = torch.LongTensor([slen] * bs)
lengths = torch.tensor([slen] * bs, device=device)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not LongTensor?

Copy link
Member Author

Choose a reason for hiding this comment

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

LongTensor isn't a factory to create tensors, but the tensor class, so you can't directly set the device type on it. You would have to do:

lengths = torch.LongTensor([slen] * bs).to(device)

If I understand correctly, this first creates the tensor on the CPU, before creating a new one on the updated device (if the device is different). When using the factory method, I believe it's only created once, and is therefore more efficient. I didn't check the source code directly though so I may be wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense, thanks for clarifying!

@LysandreJik LysandreJik merged commit ec02674 into master Jul 30, 2020
@LysandreJik LysandreJik deleted the fix-flaubert-gpu-test branch July 30, 2020 15:11
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

2 participants