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] text-classification PL example #6027

Merged
merged 9 commits into from
Aug 6, 2020
Merged

Conversation

bhashithe
Copy link
Contributor

The text-classification example needed to have several edits to get it to working. The main one was that the hparams are loaded as a dict instead of a Namespace object from the checkpoint so this needed to be fixed with recasting the hparams to a Namespace object.

Though this is not the ideal solution, it works for now.

I also have some other fixes such as gpus argument which needed to be added to the generic arguments list in the lightning_base.py and removing the default value for n_tpu_cores. And the lr_scheduler was not accessed by the logging callback correctly. These have been all fixed and the example works correctly.

@bhashithe bhashithe changed the title Fixed the text-classification PytorchLightning example #5452 Fixed the text-classification PytorchLightning example Jul 25, 2020
@codecov
Copy link

codecov bot commented Jul 25, 2020

Codecov Report

Merging #6027 into master will increase coverage by 1.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6027      +/-   ##
==========================================
+ Coverage   77.46%   78.50%   +1.04%     
==========================================
  Files         146      146              
  Lines       26243    26243              
==========================================
+ Hits        20330    20603     +273     
+ Misses       5913     5640     -273     
Impacted Files Coverage Δ
src/transformers/modeling_tf_electra.py 26.02% <0.00%> (-69.52%) ⬇️
src/transformers/modeling_tf_roberta.py 43.98% <0.00%> (-49.38%) ⬇️
src/transformers/generation_tf_utils.py 86.21% <0.00%> (+1.25%) ⬆️
src/transformers/modeling_tf_distilbert.py 98.79% <0.00%> (+33.89%) ⬆️
src/transformers/modeling_tf_mobilebert.py 96.77% <0.00%> (+73.38%) ⬆️

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 e168488...4fbcde5. Read the comment docs.

Copy link
Contributor

@sshleifer sshleifer left a comment

Choose a reason for hiding this comment

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

Why wasn't any of this breaking tests? Is there some test coverage we could add to find these sorts of errors earlier?

@@ -23,7 +23,7 @@ mkdir -p $OUTPUT_DIR
# Add parent directory to python path to access lightning_base.py
export PYTHONPATH="../":"${PYTHONPATH}"

python3 run_pl_glue.py --data_dir $DATA_DIR \
python3 run_pl_glue.py --gpus 2 --data_dir $DATA_DIR \
Copy link
Contributor

Choose a reason for hiding this comment

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

should 2 gpus be the default?

Copy link
Contributor

Choose a reason for hiding this comment

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

it should not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So should I add environment variables in the shell script just like $DATA_DIR etc.?

Copy link
Contributor

Choose a reason for hiding this comment

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

DATA_DIR is solid. My only objection is gpus=2.

@sshleifer sshleifer self-assigned this Jul 25, 2020
@@ -72,7 +76,7 @@ def prepare_data(self):
logger.info("Saving features into cached file %s", cached_features_file)
torch.save(features, cached_features_file)

def load_dataset(self, mode, batch_size):
def get_dataloader(self, mode, batch_size):
Copy link
Contributor

Choose a reason for hiding this comment

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

get_dataloader has one more arg - shuffle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, i think wrapping this load_dataset() into a get_dataloader() is the best way to handle this.

@stas00
Copy link
Contributor

stas00 commented Jul 25, 2020

Why wasn't any of this breaking tests? Is there some test coverage we could add to find these sorts of errors earlier?

run_pl_glue.py isn't being tested. It's not in test_examples.py and it doesn't have a dedicated test file like some other examples do.

Besides, looking at the output for examples test:

https://circleci.com/gh/huggingface/transformers/64559?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

it's impossible to tell which examples are being run and which aren't. It will only indicate the name on failure. Perhaps at the very least adding a pytest option so that it can announce which tests were run? Submitted PR to do just that: #6035

@stas00
Copy link
Contributor

stas00 commented Jul 25, 2020

Here is a PR that adds the missing PL glue test: #6034 (which obviously fails by CI - a good thing).

@sshleifer
Copy link
Contributor

@stas00 you can at least see all the files that are run with
ls examples/**/test*.py.

@stas00
Copy link
Contributor

stas00 commented Jul 25, 2020

@stas00 you can at least see all the files that are run with
ls examples/**/test*.py.

you want one dir up as well, so:

ls -1 examples/test*.py examples/*/test*.py

but it tells only part of the story, since most info is hidden in examples/test_examples.py. e.g. you can't tell pl glue is not being there.

Copy link
Contributor

@sshleifer sshleifer left a comment

Choose a reason for hiding this comment

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

Excited for this!

@bhashithe
Copy link
Contributor Author

How does this break tf tests? Looks like the model save still has issues with the state_dict its saving.

@sshleifer
Copy link
Contributor

TF failures are spurious.

@sshleifer sshleifer added the Examples Which is related to examples in general label Aug 6, 2020
@sshleifer
Copy link
Contributor

Merging this, thanks @bhashithe, @stas00 @laibamehnaz and everyone else who helped!

@sshleifer sshleifer changed the title Fixed the text-classification PytorchLightning example [Fix] text-classification PL example Aug 6, 2020
@sshleifer sshleifer merged commit ffceef2 into huggingface:master Aug 6, 2020
@stas00
Copy link
Contributor

stas00 commented Aug 6, 2020

The merged #6027 broke examples/seq2seq/test_seq2seq_examples.py::test_finetune_lr_shedulers - which I think was flagged by failing CI of that PR.

yeah, PL already has --gpus - so it conflicts with the one added by 6027. So I will look at how to rework that need in a different way.

stas00 added a commit to stas00/transformers that referenced this pull request Aug 6, 2020
@stas00
Copy link
Contributor

stas00 commented Aug 6, 2020

Let's continue the discussion here: #6310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Examples Which is related to examples in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants