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

Fixing model checkpoints to be robust to mutli -> single GPU usage #1091

Closed
wants to merge 7 commits into from

Conversation

pruksmhc
Copy link
Contributor

@pruksmhc pruksmhc commented May 17, 2020

This is a fix to #1087. I decided to make the change in the model loading portion because making the change in model saving as suggested in the #1087 will fix multi -> single GPU model loading, but will break multi -> multi GPU model loading (if we want to reload a checkpoint that was trained in multi-GPU on a multi-GPU machine).
Additionally, I also did some light cleanup of model loading in trainer to not be redundant, and also deleted an unused parameter.

Tests
Multi -> Single GPU: I tested by training a roberta-large model on SST on multi-GPU, and then loading that checkpoint in a single-GPU for further training.
Multi -> Multi GPU: This is implicitly already done in jiant, specifically we load the best checkpoint before doing evaluation, so this was tested when I trained the roberta-large SST model the first time on multi-GPU.

@pep8speaks
Copy link

pep8speaks commented May 17, 2020

Hello @pruksmhc! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 541:55: W291 trailing whitespace
Line 548:12: W291 trailing whitespace

Line 329:77: W291 trailing whitespace

You can repair most issues by installing black and running: black -l 100 ./*. If you contribute often, have a look at the 'Contributing' section of the README for instructions on doing this automatically.

Comment last updated at 2020-05-18 20:46:53 UTC

@pruksmhc pruksmhc changed the title Fixing model checkpoints to be robust to mutli -> single GPU usage [WIP] Fixing model checkpoints to be robust to mutli -> single GPU usage May 17, 2020
@pruksmhc pruksmhc changed the title [WIP] Fixing model checkpoints to be robust to mutli -> single GPU usage Fixing model checkpoints to be robust to mutli -> single GPU usage May 17, 2020
Comment on lines 345 to 346
if "module" in key:
key = key.replace("module.", "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make this check explicitly for prefix with .startswith, and drop the first n characters (in case module appears somewhere else in the parameter name).


for name, weights in model_state.items():
key = get_key(name)
final_model_state[key] = model_state[name]
Copy link
Collaborator

Choose a reason for hiding this comment

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

= weights

log.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

self._model.load_state_dict(model_state, strict=False)
load_model_state(self._model, model_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this warning being disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not. This warning is also inside load_model_state function

@pyeres
Copy link
Contributor

pyeres commented May 19, 2020

Hi @zphang & @HaokunLiu — are either of you available to provide the substantial review for this PR? The core concerns seem to be 1) whether this addresses issue #1087, and 2) whether these changes introduce new risks/regressions.

"""
final_model_state = collections.OrderedDict()

def get_key(name):
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment explaining why we need this logic.

log.error("Parameter missing from checkpoint: " + name)
log.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

self._model.load_state_dict(model_state, strict=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

You're no longer setting strict=False here. It's debatable whether that's the ideal behavior here, but it was intentional, and I believe it has had some real experimental uses. Why the change?

@jeswan
Copy link
Collaborator

jeswan commented Sep 17, 2020

Are these changes still necessary? Planning to close all PRs to move jiant2 to this repo in the near future.

@jeswan jeswan added the jiant-v1-legacy Relevant to versions <= v1.3.2 label Sep 17, 2020
@jeswan jeswan closed this Sep 22, 2020
@jeswan jeswan deleted the fix_multi_to_single branch September 22, 2020 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jiant-v1-legacy Relevant to versions <= v1.3.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants