Instructions to use zeromodels/gpt2_large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/gpt2_large with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/gpt2_large") - Keras
How to use zeromodels/gpt2_large with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/gpt2_large") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +15 -15
- kf_config.json → zm_config.json +20 -20
README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
| 2 |
pipeline_tag: text-generation
|
| 3 |
license: mit
|
| 4 |
base_model: openai-community/gpt2-large
|
| 5 |
-
library_name:
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
tags:
|
| 9 |
- keras
|
| 10 |
-
-
|
| 11 |
- gpt2
|
| 12 |
- gpt-2
|
| 13 |
- text-generation
|
|
@@ -18,9 +18,9 @@ tags:
|
|
| 18 |
|
| 19 |
# Run GPT-2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 20 |
|
| 21 |
-
[](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
|
| 26 |
|
|
@@ -32,7 +32,7 @@ activations, a tied output head, and a byte-level BPE tokenizer. This is the
|
|
| 32 |
For more details, see the upstream [model card](https://huggingface.co/openai-community/gpt2-large).
|
| 33 |
|
| 34 |
Pure-**Keras 3** conversion of [`openai-community/gpt2-large`](https://huggingface.co/openai-community/gpt2-large) for
|
| 35 |
-
[
|
| 36 |
**TensorFlow / Torch / JAX**.
|
| 37 |
|
| 38 |
## Quick start
|
|
@@ -41,31 +41,31 @@ Pure-**Keras 3** conversion of [`openai-community/gpt2-large`](https://huggingfa
|
|
| 41 |
import os
|
| 42 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 43 |
|
| 44 |
-
from
|
| 45 |
|
| 46 |
-
model = GPT2TextGenerate.from_weights("
|
| 47 |
-
tokenizer = GPT2Tokenizer.from_weights("
|
| 48 |
|
| 49 |
inputs = tokenizer("The meaning of life is")
|
| 50 |
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 51 |
print(tokenizer.decode(outputs[0]))
|
| 52 |
```
|
| 53 |
|
| 54 |
-
All GPT-2 sizes load the same way with `from_weights("
|
| 55 |
|
| 56 |
| Variant | Hub | Params |
|
| 57 |
|---|---|---|
|
| 58 |
-
| `gpt2` | [`
|
| 59 |
-
| `gpt2_medium` | [`
|
| 60 |
-
| `gpt2_large` | [`
|
| 61 |
-
| `gpt2_xl` | [`
|
| 62 |
|
| 63 |
## Tips
|
| 64 |
|
| 65 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 66 |
- This is a base completion model: it continues a prompt and is not
|
| 67 |
instruction-tuned.
|
| 68 |
-
- See the [GPT-2 docs](https://imvision12.github.io/
|
| 69 |
- Upstream safetensors still work via the `hf:` prefix, e.g.
|
| 70 |
`GPT2TextGenerate.from_weights("hf:openai-community/gpt2-large")`.
|
| 71 |
|
|
|
|
| 2 |
pipeline_tag: text-generation
|
| 3 |
license: mit
|
| 4 |
base_model: openai-community/gpt2-large
|
| 5 |
+
library_name: zeromodels
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
tags:
|
| 9 |
- keras
|
| 10 |
+
- zeromodels
|
| 11 |
- gpt2
|
| 12 |
- gpt-2
|
| 13 |
- text-generation
|
|
|
|
| 18 |
|
| 19 |
# Run GPT-2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 20 |
|
| 21 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/gpt2/)
|
| 22 |
|
| 23 |
+
# zeromodels/gpt2_large
|
| 24 |
|
| 25 |
Paper: [Language Models are Unsupervised Multitask Learners (Radford et al., 2019)](https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf)
|
| 26 |
|
|
|
|
| 32 |
For more details, see the upstream [model card](https://huggingface.co/openai-community/gpt2-large).
|
| 33 |
|
| 34 |
Pure-**Keras 3** conversion of [`openai-community/gpt2-large`](https://huggingface.co/openai-community/gpt2-large) for
|
| 35 |
+
[zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on
|
| 36 |
**TensorFlow / Torch / JAX**.
|
| 37 |
|
| 38 |
## Quick start
|
|
|
|
| 41 |
import os
|
| 42 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 43 |
|
| 44 |
+
from zeromodels.models.gpt2 import GPT2TextGenerate, GPT2Tokenizer
|
| 45 |
|
| 46 |
+
model = GPT2TextGenerate.from_weights("zeromodels/gpt2_large")
|
| 47 |
+
tokenizer = GPT2Tokenizer.from_weights("zeromodels/gpt2_large")
|
| 48 |
|
| 49 |
inputs = tokenizer("The meaning of life is")
|
| 50 |
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 51 |
print(tokenizer.decode(outputs[0]))
|
| 52 |
```
|
| 53 |
|
| 54 |
+
All GPT-2 sizes load the same way with `from_weights("zeromodels/<variant>")`:
|
| 55 |
|
| 56 |
| Variant | Hub | Params |
|
| 57 |
|---|---|---|
|
| 58 |
+
| `gpt2` | [`zeromodels/gpt2`](https://huggingface.co/zeromodels/gpt2) | 124M |
|
| 59 |
+
| `gpt2_medium` | [`zeromodels/gpt2_medium`](https://huggingface.co/zeromodels/gpt2_medium) | 355M |
|
| 60 |
+
| `gpt2_large` | [`zeromodels/gpt2_large`](https://huggingface.co/zeromodels/gpt2_large) | 774M |
|
| 61 |
+
| `gpt2_xl` | [`zeromodels/gpt2_xl`](https://huggingface.co/zeromodels/gpt2_xl) | 1.5B |
|
| 62 |
|
| 63 |
## Tips
|
| 64 |
|
| 65 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 66 |
- This is a base completion model: it continues a prompt and is not
|
| 67 |
instruction-tuned.
|
| 68 |
+
- See the [GPT-2 docs](https://imvision12.github.io/ZeroModels/gpt2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 69 |
- Upstream safetensors still work via the `hf:` prefix, e.g.
|
| 70 |
`GPT2TextGenerate.from_weights("hf:openai-community/gpt2-large")`.
|
| 71 |
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "GPT2Model",
|
| 6 |
-
"variant": "gpt2_large",
|
| 7 |
-
"weights": "model.weights.json",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "gpt2",
|
| 11 |
-
"text_config": {
|
| 12 |
-
"vocab_size": 50257,
|
| 13 |
-
"embed_dim": 1280,
|
| 14 |
-
"mlp_dim": 5120,
|
| 15 |
-
"num_layers": 36,
|
| 16 |
-
"num_heads": 20,
|
| 17 |
-
"max_position_embeddings": 1024,
|
| 18 |
-
"norm_eps": 1e-05,
|
| 19 |
-
"tie_embeddings": true
|
| 20 |
-
}
|
| 21 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.gpt2",
|
| 5 |
+
"model_class": "GPT2Model",
|
| 6 |
+
"variant": "gpt2_large",
|
| 7 |
+
"weights": "model.weights.json",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "gpt2",
|
| 11 |
+
"text_config": {
|
| 12 |
+
"vocab_size": 50257,
|
| 13 |
+
"embed_dim": 1280,
|
| 14 |
+
"mlp_dim": 5120,
|
| 15 |
+
"num_layers": 36,
|
| 16 |
+
"num_heads": 20,
|
| 17 |
+
"max_position_embeddings": 1024,
|
| 18 |
+
"norm_eps": 1e-05,
|
| 19 |
+
"tie_embeddings": true
|
| 20 |
+
}
|
| 21 |
}
|