-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Covert a
safetensor
checkpoint from Hugging Face hub (#1662)
* chore: adding gemma and llama3 * chore: adding init * chore: removing hard coded values * chore: using backbone properties * chore: reformat * chore: review changes * chore: removing einops with custom np operations * fix: variable name * check: none type for reshape and transpose patterns * chore: fixing the nesting of reshape and transpose patterns * fixing nesting of patterns * chore: gemma weight rearrange fix * chore: adding a hook function to reshape and transpose the hf tensors to match the keras weights * fix: variable to assign * fix: gemma port * chore: adding tests * review comments * adding safetensors as a dep * chore: adding jax memory cleanup * utf 8 encoding * chore: changing tests * chore: fixing tests * fix tests * chore: adding guard rails for None types * Trigger Build * review suggestions * fix raising ValueError * fix error message
- Loading branch information
Showing
18 changed files
with
600 additions
and
30 deletions.
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.