Add plain PyTorch loader for the CSD checkpoint - #15
Open
fahmeed-nabi wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a plain PyTorch loader for the released CSD checkpoint, answering #8 ("How to load the model as a PyTorch module?").
The checkpoint has no
transformersAutoModelsupport andconfig.jsoncarries no architecture info ({"model_type": "custom"}), so it can't be loaded withfrom_pretrained.models/csd_clip.pyreconstructs the architecture directly from the checkpoint'sstate_dictkey names and shapes:projis unused (noprojkey in the checkpoint), and the raw pooled feature feeds forward instead.last_layer_style/last_layer_contentare separate(1024, 768)matrices applied via matrix multiply, notnn.Linear(the checkpoint stores them as raw(in, out)matrices, notnn.Linear.weight's(out, in)shape).Loading with
strict=Trueagainst this class produces zero missing and zero unexpected keys against the released weights.Also adds a short README section with a runnable example (load the checkpoint, embed an image, get back style/content embeddings).
Why
This has come up a few times (#8, and implicitly in how people are using the HF checkpoint) with no canonical answer in the repo. This closes that gap with a minimal, dependency-light loader that doesn't require guessing the architecture from the state_dict, which is what we had to do to use CSD in our own project.
Testing
strict=Truestate_dict load produces zero missing / zero unexpected keys againsttomg-group-umd/CSD-ViT-L.Closes #8.