Text Generation
Transformers
PyTorch
TensorFlow
JAX
LiteRT
Rust
ONNX
Safetensors
English
gpt2
exbert
text-generation-inference
Instructions to use openai-community/gpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openai-community/gpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openai-community/gpt2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2") model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openai-community/gpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openai-community/gpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai-community/gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openai-community/gpt2
- SGLang
How to use openai-community/gpt2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "openai-community/gpt2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai-community/gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "openai-community/gpt2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai-community/gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openai-community/gpt2 with Docker Model Runner:
docker model run hf.co/openai-community/gpt2
Commit History
-
Adds the tokenizer configuration file (#80)
Verified signature- Adds tokenizer_config.json file (db6d57930088fb63e52c010bd9ac77c955ac55e7)607a30d
-
Adding ONNX file of this model (#60)
- Adding ONNX file of this model (9411f419c589519e1a46c94ac7789ea20fd7c322)11c5a3d
-
Update generation_config.json
e7da7f2
-
Add note that this is the smallest version of the model (#18)
- Add note that this is the smallest version of the model (611838ef095a5bb35bf2027d05e1194b7c9d37ac) Co-authored-by: helen <mathemakitten@users.noreply.huggingface.co>f27b190
-
Our very first generation_config.json (#17)
- Our very first generation_config.json (671851b7e9d56ef062890732065d7bd5f4628bd6) Co-authored-by: Joao Gante <joaogante@users.noreply.huggingface.co>0dd7bcc
-
Upload model.safetensors with huggingface_hub (#12)
- Upload model.safetensors with huggingface_hub (ba2f794b2e4ea09ef932a6628fa0815dfaf09661) Co-authored-by: Nicolas Patry <Narsil@users.noreply.huggingface.co>75e09b4
-
Convert weights to .safetensors (#6)
- Convert weights to .safetensors (f0946a6b3259a3bb628d54f1045cb64ee6dc4176)909a290
-
add gpt2
6c0e608 -
Update .gitattributes
aff9832
-
Migrate model card from transformers-repo
Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755 Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/gpt2-README.md6a8c602
-
For clarity, delete deprecated modelcard.json
We now use the README.md model card instead Approved-by: Julien Chaumond <julien@huggingface.co>84d42a0
-
Update tokenizer.json
210ab4c
-
Update config.json
7979bb7
-
Update rust_model.ot
ee92bbb -
Update config.json
26b7c7a
-
Update config.json
8bfcadd
-
Update modelcard.json
99dd285
-
Update 64-8bits.tflite
8faa6d7 -
Update 64-fp16.tflite
5d494dc
-
Update 64.tflite
b57efa2
-
Update tf_model.h5
ddceb78
-
Update config.json
703af34 -
Update vocab.json
9228726 -
Update merges.txt
a9eff68 -
Update pytorch_model.bin
a49587d -
initial commit
9b865ef