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

Add support for partial checkpoint restore #1392

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

terrykong
Copy link
Contributor

This change allows partial checkpoint restores to be configurable, which is often needed when fine-tuning from a pretrained checkpoint. You can add the following code to your gin config to restore only a subset of the model variables from the given checkpoint:

utils.RestoreCheckpointConfig:
  fallback_to_scratch = True
  strict = False
  state_transformation_fns = [@state_transform]

where state_transform determines which parameters to restore. For example, to restore only model weights and reset optimizer states, we can use the following transformation function:

def just_states_transform(checkpoint, opt_state):
    return state_utils.apply_assignment_map(checkpoint, opt_state,
        assignment_map=[(r'state.*', None)])

Mapping all variables beginning with state. (i.e. the optimizer states) to None causes them to be ignored during checkpoint restore. All variables beginning with target. (i.e. the model weights) will be restored.

@google-cla
Copy link

google-cla bot commented Sep 8, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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