Instructions to use zeromodels/gpt2_medium with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/gpt2_medium 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_medium") - Keras
How to use zeromodels/gpt2_medium 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_medium") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
a6316f5 verified |
Download README.md from zeromodels/gpt2_medium: direct link, hf CLI and curl.
- Browser
- Download file 2.89 kB
-
https://huggingface.co/zeromodels/gpt2_medium/resolve/main/README.md
- Command line
-
hf download hf://zeromodels/gpt2_medium/README.md
-
curl -L -o README.md https://huggingface.co/zeromodels/gpt2_medium/resolve/main/README.md
2.89 kB
| pipeline_tag: text-generation | |
| license: mit | |
| base_model: openai-community/gpt2-medium | |
| library_name: zeromodels | |
| language: | |
| - en | |
| tags: | |
| - keras | |
| - zeromodels | |
| - gpt2 | |
| - gpt-2 | |
| - text-generation | |
| - pytorch | |
| - jax | |
| - tf | |
| # Run GPT-2 with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/gpt2/) | |
| # zeromodels/gpt2_medium | |
| 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) | |
| GPT-2 is OpenAI's decoder-only transformer language model trained on WebText: | |
| learned absolute position embeddings, pre-LayerNorm blocks, `gelu_new` | |
| activations, a tied output head, and a byte-level BPE tokenizer. This is the | |
| **355M** variant, a base completion model (no chat template). | |
| For more details, see the upstream [model card](https://huggingface.co/openai-community/gpt2-medium). | |
| Pure-**Keras 3** conversion of [`openai-community/gpt2-medium`](https://huggingface.co/openai-community/gpt2-medium) for | |
| [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on | |
| **TensorFlow / Torch / JAX**. | |
| ## Quick start | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from zeromodels.models.gpt2 import GPT2TextGenerate, GPT2Tokenizer | |
| model = GPT2TextGenerate.from_weights("zeromodels/gpt2_medium") | |
| tokenizer = GPT2Tokenizer.from_weights("zeromodels/gpt2_medium") | |
| inputs = tokenizer("The meaning of life is") | |
| outputs = model.generate(**inputs, max_new_tokens=40) | |
| print(tokenizer.decode(outputs[0])) | |
| ``` | |
| All GPT-2 sizes load the same way with `from_weights("zeromodels/<variant>")`: | |
| | Variant | Hub | Params | | |
| |---|---|---| | |
| | `gpt2` | [`zeromodels/gpt2`](https://huggingface.co/zeromodels/gpt2) | 124M | | |
| | `gpt2_medium` | [`zeromodels/gpt2_medium`](https://huggingface.co/zeromodels/gpt2_medium) | 355M | | |
| | `gpt2_large` | [`zeromodels/gpt2_large`](https://huggingface.co/zeromodels/gpt2_large) | 774M | | |
| | `gpt2_xl` | [`zeromodels/gpt2_xl`](https://huggingface.co/zeromodels/gpt2_xl) | 1.5B | | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / zeromodels. | |
| - This is a base completion model: it continues a prompt and is not | |
| instruction-tuned. | |
| - See the [GPT-2 docs](https://imvision12.github.io/ZeroModels/gpt2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/). | |
| - Upstream safetensors still work via the `hf:` prefix, e.g. | |
| `GPT2TextGenerate.from_weights("hf:openai-community/gpt2-medium")`. | |
| ## Special Thanks | |
| A huge thank you to the OpenAI GPT-2 authors for creating and releasing these models. | |
| License: MIT, inherited from the upstream OpenAI GPT-2 release. | |