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

VGT: Prefix Handling for Checkpoint State Dictionary #175

Open
meichenberger78 opened this issue Sep 23, 2024 · 0 comments
Open

VGT: Prefix Handling for Checkpoint State Dictionary #175

meichenberger78 opened this issue Sep 23, 2024 · 0 comments

Comments

@meichenberger78
Copy link

When attempting to load model weights from a checkpoint in VGT, the model's state dictionary keys do not match the checkpoint keys due to potential prefixing issues. This mismatch results in parameters not being loaded correctly, which lead to a significant increase in "total_loss".

In my opinion, no prefixes are necessary. However, if prefixes are needed, we can implement a simple check to address this issue.

In MyDetectionCheckpointer.py, check if prefixes are required for the keys:

if needs_prefix(checkpoint_state_dict, model_state_dict): 
    new_checkpoint_state_dict = {}
    for k in checkpoint_state_dict.keys():
        new_checkpoint_state_dict[append_prefix(k)] = checkpoint_state_dict[k]

    for k in DiT_checkpoint_state_dict.keys():
        new_checkpoint_state_dict[DiT_append_prefix(k)] = DiT_checkpoint_state_dict[k]

    checkpoint_state_dict = new_checkpoint_state_dict

Here’s the function to determine if prefixes are needed:

def needs_prefix(checkpoint_state_dict, model_state_dict):
    for k in checkpoint_state_dict.keys():
        if k not in model_state_dict:
            prefixed_key = append_prefix(k)
            if prefixed_key in model_state_dict:
                return True
    return False

After implementing these changes, re-training from a checkpoint works flawlessly.

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

No branches or pull requests

1 participant