Skip to content

Commit 0f70cfd

Browse files
authored
Address rendering issues in huggingface guide #2124 (#2127)
* address rendering issues in hf guide * Add file * add ipynb and md files
1 parent e7f48cb commit 0f70cfd

File tree

4 files changed

+26
-50
lines changed

4 files changed

+26
-50
lines changed

guides/ipynb/keras_hub/hugging_face_keras_integration.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"colab_type": "text"
77
},
88
"source": [
9-
"# Load HuggingFace Transformers checkpoint into a multi backend KerasHub model\n",
9+
"# Loading HuggingFace Transformers checkpoints into multi-backend KerasHub models\n",
1010
"\n",
1111
"**Author:** [Laxma Reddy Patlolla](https://github.com/laxmareddyp), [Divyashree Sreepathihalli](https://github.com/divyashreepathihalli)<br><br>\n",
1212
"**Date created:** 2025/06/17<br><br>\n",
@@ -35,6 +35,7 @@
3535
"Hub directly into KerasHub with just a few lines of code.\n",
3636
"\n",
3737
"Key advantages of using KerasHub converters:\n",
38+
"\n",
3839
"- **Ease of Use**: Load HuggingFace models without manual conversion steps.\n",
3940
"- **Broad Compatibility**: Access a vast range of models available on the HuggingFace Hub.\n",
4041
"- **Seamless Integration**: Work with these models using familiar Keras APIs for training,\n",
@@ -121,7 +122,7 @@
121122
"colab_type": "text"
122123
},
123124
"source": [
124-
"### Fine-tune a Gemma Transformer checkpoint using the Keras model.fit(...) API.\n",
125+
"### Fine-tuning a Gemma Transformer checkpoint using the Keras `model.fit(...)` API\n",
125126
"\n",
126127
"Once you have loaded HuggingFace weights, you can use the instantiated model\n",
127128
"just like any other KerasHub model. For instance, you might fine-tune the model\n",
@@ -183,6 +184,7 @@
183184
"giving you access to a vast and diverse selection of state-of-the-art architectures for your projects.\n",
184185
"\n",
185186
"With KerasHub, you can:\n",
187+
"\n",
186188
"- **Tap into State-of-the-Art Models**: Easily experiment with the latest\n",
187189
"architectures and pretrained weights from the research community and industry.\n",
188190
"- **Reduce Development Time**: Leverage existing models instead of training from scratch,\n",
@@ -237,7 +239,7 @@
237239
"\n",
238240
"### Generation\n",
239241
"\n",
240-
"Here\u2019s an example using Llama: loading a PyTorch Hugging Face transformer checkpoint into KerasHub and running it on the JAX backend."
242+
"Here\u2019s an example using Llama: Loading a PyTorch Hugging Face transformer checkpoint into KerasHub and running it on the JAX backend."
241243
]
242244
},
243245
{

guides/keras_hub/hugging_face_keras_integration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Title: Load HuggingFace Transformers checkpoint into a multi backend KerasHub model
2+
Title: Loading HuggingFace Transformers checkpoints into multi-backend KerasHub models
33
Author: [Laxma Reddy Patlolla](https://github.com/laxmareddyp), [Divyashree Sreepathihalli](https://github.com/divyashreepathihalli)<br>
44
Date created: 2025/06/17<br>
55
Last modified: 2025/06/17<br>
@@ -23,6 +23,7 @@
2323
Hub directly into KerasHub with just a few lines of code.
2424
2525
Key advantages of using KerasHub converters:
26+
2627
- **Ease of Use**: Load HuggingFace models without manual conversion steps.
2728
- **Broad Compatibility**: Access a vast range of models available on the HuggingFace Hub.
2829
- **Seamless Integration**: Work with these models using familiar Keras APIs for training,
@@ -69,7 +70,7 @@
6970
gemma_lm.generate("I want to say", max_length=30)
7071

7172
"""
72-
### Fine-tune a Gemma Transformer checkpoint using the Keras model.fit(...) API.
73+
### Fine-tuning a Gemma Transformer checkpoint using the Keras `model.fit(...)` API
7374
7475
Once you have loaded HuggingFace weights, you can use the instantiated model
7576
just like any other KerasHub model. For instance, you might fine-tune the model
@@ -103,6 +104,7 @@
103104
giving you access to a vast and diverse selection of state-of-the-art architectures for your projects.
104105
105106
With KerasHub, you can:
107+
106108
- **Tap into State-of-the-Art Models**: Easily experiment with the latest
107109
architectures and pretrained weights from the research community and industry.
108110
- **Reduce Development Time**: Leverage existing models instead of training from scratch,
@@ -143,7 +145,7 @@
143145
144146
### Generation
145147
146-
Here’s an example using Llama: loading a PyTorch Hugging Face transformer checkpoint into KerasHub and running it on the JAX backend.
148+
Here’s an example using Llama: Loading a PyTorch Hugging Face transformer checkpoint into KerasHub and running it on the JAX backend.
147149
"""
148150
import os
149151

guides/md/keras_hub/hugging_face_keras_integration.md

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Load HuggingFace Transformers checkpoint into a multi backend KerasHub model
1+
# Loading HuggingFace Transformers checkpoints into multi-backend KerasHub models
22

33
**Author:** [Laxma Reddy Patlolla](https://github.com/laxmareddyp), [Divyashree Sreepathihalli](https://github.com/divyashreepathihalli)<br><br>
44
**Date created:** 2025/06/17<br><br>
@@ -26,6 +26,7 @@ This means you can seamlessly load a wide variety of pretrained models from the
2626
Hub directly into KerasHub with just a few lines of code.
2727

2828
Key advantages of using KerasHub converters:
29+
2930
- **Ease of Use**: Load HuggingFace models without manual conversion steps.
3031
- **Broad Compatibility**: Access a vast range of models available on the HuggingFace Hub.
3132
- **Seamless Integration**: Work with these models using familiar Keras APIs for training,
@@ -56,12 +57,12 @@ import keras_hub
5657
<div class="k-default-codeblock">
5758
```
5859
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
59-
E0000 00:00:1750277663.371946 12245 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
60-
E0000 00:00:1750277663.376336 12245 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
61-
W0000 00:00:1750277663.387748 12245 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
62-
W0000 00:00:1750277663.387761 12245 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
63-
W0000 00:00:1750277663.387762 12245 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
64-
W0000 00:00:1750277663.387763 12245 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
60+
E0000 00:00:1750320123.730040 8092 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
61+
E0000 00:00:1750320123.734497 8092 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
62+
W0000 00:00:1750320123.745803 8092 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
63+
W0000 00:00:1750320123.745816 8092 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
64+
W0000 00:00:1750320123.745818 8092 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
65+
W0000 00:00:1750320123.745819 8092 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.
6566
```
6667
</div>
6768

@@ -79,17 +80,8 @@ Google Colab.
7980
gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("hf://google/gemma-2b")
8081
```
8182

82-
8383
<div class="k-default-codeblock">
8484
```
85-
model.safetensors.index.json: 0%| | 0.00/13.5k [00:00<?, ?B/s]
86-
87-
model-00001-of-00002.safetensors: 0%| | 0.00/4.95G [00:00<?, ?B/s]
88-
89-
model-00002-of-00002.safetensors: 0%| | 0.00/67.1M [00:00<?, ?B/s]
90-
91-
tokenizer.model: 0%| | 0.00/4.24M [00:00<?, ?B/s]
92-
9385
normalizer.cc(51) LOG(INFO) precompiled_charsmap is empty. use identity normalization.
9486
```
9587
</div>
@@ -110,7 +102,7 @@ gemma_lm.generate("I want to say", max_length=30)
110102
```
111103
</div>
112104

113-
### Fine-tune a Gemma Transformer checkpoint using the Keras model.fit(...) API.
105+
### Fine-tuning a Gemma Transformer checkpoint using the Keras `model.fit(...)` API
114106

115107
Once you have loaded HuggingFace weights, you can use the instantiated model
116108
just like any other KerasHub model. For instance, you might fine-tune the model
@@ -127,7 +119,7 @@ gemma_lm.fit(x=features, batch_size=2)
127119
```
128120
1/1 ━━━━━━━━━━━━━━━━━━━━ 35s 35s/step - loss: 0.0342 - sparse_categorical_accuracy: 0.1538
129121
130-
<keras.src.callbacks.history.History at 0x7012f814b650>
122+
<keras.src.callbacks.history.History at 0x7e970c14cbf0>
131123
```
132124
</div>
133125

@@ -143,13 +135,6 @@ gemma_lm.save_to_preset("./gemma-2b-finetuned")
143135
keras_hub.upload_preset("hf://laxmareddyp/gemma-2b-finetune", "./gemma-2b-finetuned")
144136
```
145137

146-
147-
<div class="k-default-codeblock">
148-
```
149-
model.weights.h5: 0%| | 0.00/10.0G [00:00<?, ?B/s]
150-
```
151-
</div>
152-
153138
By uploading your preset, you can then load it from anywhere using:
154139
`loaded_model = keras_hub.models.GemmaCausalLM.from_preset("hf://YOUR_HF_USERNAME/gemma-2b-finetuned")`
155140

@@ -162,6 +147,7 @@ Computer Vision, Audio, and more. Of these, approximately 400K models are curren
162147
giving you access to a vast and diverse selection of state-of-the-art architectures for your projects.
163148

164149
With KerasHub, you can:
150+
165151
- **Tap into State-of-the-Art Models**: Easily experiment with the latest
166152
architectures and pretrained weights from the research community and industry.
167153
- **Reduce Development Time**: Leverage existing models instead of training from scratch,
@@ -206,7 +192,7 @@ gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("hf://google/gemma-2b")
206192

207193
### Generation
208194

209-
Here’s an example using Llama: loading a PyTorch Hugging Face transformer checkpoint into KerasHub and running it on the JAX backend.
195+
Here’s an example using Llama: Loading a PyTorch Hugging Face transformer checkpoint into KerasHub and running it on the JAX backend.
210196

211197

212198
```python
@@ -232,25 +218,11 @@ causal_lm.generate(prompts, max_length=30)[0]
232218
```
233219

234220

235-
<div class="k-default-codeblock">
236-
```
237-
config.json: 0%| | 0.00/700 [00:00<?, ?B/s]
238-
239-
model.safetensors.index.json: 0%| | 0.00/23.9k [00:00<?, ?B/s]
240-
241-
model-00001-of-00004.safetensors: 0%| | 0.00/4.98G [00:00<?, ?B/s]
242-
243-
model-00004-of-00004.safetensors: 0%| | 0.00/1.17G [00:00<?, ?B/s]
244221

245-
model-00002-of-00004.safetensors: 0%| | 0.00/5.00G [00:00<?, ?B/s]
246222

247-
model-00003-of-00004.safetensors: 0%| | 0.00/4.92G [00:00<?, ?B/s]
248-
249-
tokenizer.json: 0%| | 0.00/9.09M [00:00<?, ?B/s]
250-
251-
tokenizer_config.json: 0%| | 0.00/56.1k [00:00<?, ?B/s]
252-
253-
'<|eot_id|>Csystem\nYou are a sentient, superintelligent artificial general intelligence, here to teach and assist me.'
223+
<div class="k-default-codeblock">
224+
```
225+
'<tool_call>Csystem\nYou are a sentient, superintelligent artificial general intelligence, here to teach and assist me.\n<tool'
254226
```
255227
</div>
256228

scripts/hub_master.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@
26462646
},
26472647
{
26482648
"path": "hugging_face_keras_integration",
2649-
"title": "Load HuggingFace Transformers checkpoint into a multi backend KerasHub model",
2649+
"title": "Loading HuggingFace Transformers checkpoints into multi-backend KerasHub models",
26502650
},
26512651
],
26522652
}

0 commit comments

Comments
 (0)