-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
[Model] Refactor BLIP/BLIP-2 to support composite model loading #8407
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
84e6ee6
Composite model loading for BLIP encoder and BLIP-2
DarkLight1337 21b2dd4
Clean up existing models
DarkLight1337 67dce75
Fix typo
DarkLight1337 3b179d0
Merge branch 'upstream' into blip2-dynamic-lm
DarkLight1337 baeaad5
Merge branch 'upstream' into blip2-dynamic-lm
DarkLight1337 b4e9241
Apply #8656
DarkLight1337 7db022d
Remove unused loggers
DarkLight1337 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,6 @@ | |
|
||
logger = init_logger(__name__) | ||
|
||
_KEYS_TO_MODIFY_MAPPING = { | ||
"language_model.lm_head": "lm_head", | ||
"language_model.model": "language_model", | ||
} | ||
Comment on lines
-37
to
-40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is unused so I removed it. |
||
|
||
# Result in the max possible feature size (2x2 grid of 336x336px tiles) | ||
MAX_IMAGE_FEATURE_SIZE_HEIGHT = MAX_IMAGE_FEATURE_SIZE_WIDTH = 448 | ||
|
||
|
@@ -635,8 +630,12 @@ def sample( | |
|
||
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]): | ||
# prepare weight iterators for components | ||
vit_weights, mlp_weights, newline_weights, llm_weights = itertools.tee( | ||
weights, 4) | ||
( | ||
vit_weights, | ||
mlp_weights, | ||
newline_weights, | ||
llm_weights, | ||
) = itertools.tee(weights, 4) | ||
|
||
# load vision encoder | ||
vit_weights = filter_weights(vit_weights, "vision_tower") | ||
|
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
_require_post_layernorm
is only used here, thepost_layernorm
layer can be directly referenced here to reduce a layer of indirection, making the code easier to understand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
startswith
to check the weight names is more robust and performant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought with the composite weight loading now that thevision_model
prefix will be dropped - is that not the case?nvm - I was thinking
vision_tower
. Ignore my comment here