Interpolate ViT positional embeddings for variable resolutions - #317
Open
Thakor-Yashpal wants to merge 1 commit into
Open
Interpolate ViT positional embeddings for variable resolutions#317Thakor-Yashpal wants to merge 1 commit into
Thakor-Yashpal wants to merge 1 commit into
Conversation
Modifies `load_pretrained` and `interpolate_posembed` functions to support loading pre-trained Vision Transformer (ViT) checkpoints into models initialized with different input resolutions. Changes include: - Detecting shape mismatches in positional embeddings (`Transformer/posembed_input/pos_embedding`) between the checkpoint and the target model. - Calling `interpolate_posembed` to resize the embedding grid using `scipy.ndimage.zoom` (bilinear interpolation). - Adding logic to handle the presence or absence of the class token during separation and concatenation. - Including error checks for non-square grid sizes and shape mismatches after interpolation. This allows fine-tuning or inference with ViT models on image resolutions different from their pre-training resolution.
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The class-token heuristic misclassifies a common no-token 14x14 embedding. For n=196, the first check says no class token, but the fallback tests 195 % int(sqrt(195)) == 0; int(sqrt(195)) is 13 and 195 % 13 == 0, so it flips to True even though 195 is not square. interpolate_posembed then rejects the 195-token grid. Could this use an actual perfect-square check (s*s == n / s*s == n-1) and cover 196 tokens?
|
您好,这是来自QQ邮箱的自动回复邮件。我将尽快阅读您的邮件,谢谢!
|
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.
Modifies
load_pretrainedandinterpolate_posembedfunctions to support loading pre-trained Vision Transformer (ViT) checkpoints into models initialized with different input resolutions.Changes include:
Transformer/posembed_input/pos_embedding) between the checkpoint and the target model.interpolate_posembedto resize the embedding grid usingscipy.ndimage.zoom(bilinear interpolation).This allows fine-tuning or inference with ViT models on image resolutions different from their pre-training resolution.