-
Notifications
You must be signed in to change notification settings - Fork 228
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
Covert a safetensor
checkpoint from Hugging Face hub
#1662
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
72ce619
chore: adding gemma and llama3
ariG23498 8f2fe93
chore: adding init
ariG23498 a3fdc06
chore: removing hard coded values
ariG23498 3235592
chore: using backbone properties
ariG23498 0bb47ad
chore: reformat
ariG23498 4994ca8
chore: review changes
ariG23498 606fcd7
chore: removing einops with custom np operations
ariG23498 3eec438
fix: variable name
ariG23498 225219b
check: none type for reshape and transpose patterns
ariG23498 7f42b2d
chore: fixing the nesting of reshape and transpose patterns
ariG23498 59aeb70
fixing nesting of patterns
ariG23498 47c1ea3
chore: gemma weight rearrange fix
ariG23498 8f90f9b
chore: adding a hook function to reshape and transpose the hf tensors…
ariG23498 f016fbb
fix: variable to assign
ariG23498 09d8689
fix: gemma port
ariG23498 99588a1
Merge branch 'master' into aritra/hf-port
ariG23498 767ee2a
Merge branch 'master' into aritra/hf-port
ariG23498 07183d5
chore: adding tests
ariG23498 cc969bc
review comments
ariG23498 56e0dfc
adding safetensors as a dep
ariG23498 57a3d33
Merge branch 'master' into aritra/hf-port
ariG23498 22109a2
chore: adding jax memory cleanup
ariG23498 e021465
utf 8 encoding
ariG23498 7d0cfad
chore: changing tests
ariG23498 e99f98e
chore: fixing tests
ariG23498 f61a9fa
fix tests
ariG23498 5a29dc0
chore: adding guard rails for None types
ariG23498 85c2586
Merge branch 'master' into aritra/hf-port
ariG23498 c34241b
Trigger Build
ariG23498 851fd69
review suggestions
ariG23498 cf1ff29
fix raising ValueError
ariG23498 b06c6e4
fix error message
ariG23498 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2023 The KerasNLP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2024 The KerasNLP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Convert huggingface models to KerasNLP.""" | ||
|
||
|
||
from keras_nlp.src.utils.transformers.convert_gemma import load_gemma_backbone | ||
from keras_nlp.src.utils.transformers.convert_gemma import load_gemma_tokenizer | ||
from keras_nlp.src.utils.transformers.convert_llama3 import load_llama3_backbone | ||
from keras_nlp.src.utils.transformers.convert_llama3 import ( | ||
load_llama3_tokenizer, | ||
) | ||
|
||
|
||
def load_transformers_backbone(cls, preset, load_weights): | ||
if cls is None: | ||
raise ValueError("Backbone class is None") | ||
if cls.__name__ == "GemmaBackbone": | ||
return load_gemma_backbone(cls, preset, load_weights) | ||
if cls.__name__ == "Llama3Backbone": | ||
return load_llama3_backbone(cls, preset, load_weights) | ||
raise ValueError( | ||
f"{cls} has not been ported from the Hugging Face format yet. " | ||
"Please check Hugging Face Hub for the Keras model. " | ||
) | ||
|
||
|
||
def load_transformers_tokenizer(cls, preset): | ||
if cls is None: | ||
raise ValueError("Tokenizer class is None") | ||
if cls.__name__ == "GemmaTokenizer": | ||
return load_gemma_tokenizer(cls, preset) | ||
if cls.__name__ == "Llama3Tokenizer": | ||
return load_llama3_tokenizer(cls, preset) | ||
raise ValueError( | ||
f"{cls} has not been ported from the Hugging Face format yet. " | ||
"Please check Hugging Face Hub for the Keras model. " | ||
) |
Oops, something went wrong.
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.
@mattdangerw this does not account for the fact if a hugging face repository has safetensors and a h5 file, as you can see in google-bert/bert-base-uncased.
The current tests fail becasue there is yet to be a port written for the bert. Do you think having a check for
METADATA_FILE
first, and then checking for safetensors make more sense here?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.
To me it seems like everything is works as intended here, we just need to tweak the tests.
We have four tests that were added for showing a friendly error if someone is trying to load a transformers checkpoint we do not support....
https://github.com/search?q=repo%3Akeras-team%2Fkeras-nlp+%22hf%3A%2F%2Fgoogle-bert%2Fbert-base-uncased%22&type=code
I think we just need to change to error expectation, instead of a
FileNotFound
error we will get aValueError
. Eventually, we might want to delete those tests and consolidate all of this "transformers testing" into the new directory you are adding, but that can be a follow up I think.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.
So no changes here right?
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 think we still need to update the error here (and three equivalent checks in the search above), to a
ValueError
, maybe just ditch the message regex.keras-nlp/keras_nlp/src/models/backbone_test.py
Lines 53 to 55 in e0efbc8