Text Generation
Transformers
PyTorch
TensorFlow
JAX
Rust
ONNX
Safetensors
English
gpt2
text-generation-inference
Instructions to use openai-community/gpt2-medium with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openai-community/gpt2-medium with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openai-community/gpt2-medium")# Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2-medium") model = AutoModelForMultimodalLM.from_pretrained("openai-community/gpt2-medium") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use openai-community/gpt2-medium with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openai-community/gpt2-medium" # 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-medium", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openai-community/gpt2-medium
- SGLang
How to use openai-community/gpt2-medium 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-medium" \ --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-medium", "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-medium" \ --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-medium", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openai-community/gpt2-medium with Docker Model Runner:
docker model run hf.co/openai-community/gpt2-medium
Adding ONNX file of this model
#18
by Viinzouz - opened
- README.md +2 -0
- onnx/config.json +3 -2
- onnx/generation_config.json +1 -1
- onnx/model.onnx +3 -0
- onnx/tokenizer.json +0 -0
- onnx/tokenizer_config.json +12 -1
README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
---
|
| 2 |
language: en
|
| 3 |
license: mit
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
# GPT-2 Medium
|
|
|
|
| 1 |
---
|
| 2 |
language: en
|
| 3 |
license: mit
|
| 4 |
+
tags:
|
| 5 |
+
- onnx
|
| 6 |
---
|
| 7 |
|
| 8 |
# GPT-2 Medium
|
onnx/config.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"
|
| 3 |
"activation_function": "gelu_new",
|
| 4 |
"architectures": [
|
| 5 |
"GPT2LMHeadModel"
|
|
@@ -34,7 +34,8 @@
|
|
| 34 |
"max_length": 50
|
| 35 |
}
|
| 36 |
},
|
| 37 |
-
"
|
|
|
|
| 38 |
"use_cache": true,
|
| 39 |
"vocab_size": 50257
|
| 40 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"_attn_implementation_autoset": true,
|
| 3 |
"activation_function": "gelu_new",
|
| 4 |
"architectures": [
|
| 5 |
"GPT2LMHeadModel"
|
|
|
|
| 34 |
"max_length": 50
|
| 35 |
}
|
| 36 |
},
|
| 37 |
+
"torch_dtype": "float32",
|
| 38 |
+
"transformers_version": "4.51.3",
|
| 39 |
"use_cache": true,
|
| 40 |
"vocab_size": 50257
|
| 41 |
}
|
onnx/generation_config.json
CHANGED
|
@@ -2,5 +2,5 @@
|
|
| 2 |
"_from_model_config": true,
|
| 3 |
"bos_token_id": 50256,
|
| 4 |
"eos_token_id": 50256,
|
| 5 |
-
"transformers_version": "4.
|
| 6 |
}
|
|
|
|
| 2 |
"_from_model_config": true,
|
| 3 |
"bos_token_id": 50256,
|
| 4 |
"eos_token_id": 50256,
|
| 5 |
+
"transformers_version": "4.51.3"
|
| 6 |
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8821773ce660466f98b9611209fe6857660688aeabd9bf115dfb8991ec705362
|
| 3 |
+
size 1626003448
|
onnx/tokenizer.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
onnx/tokenizer_config.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
| 1 |
{
|
| 2 |
"add_prefix_space": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"bos_token": "<|endoftext|>",
|
| 4 |
-
"clean_up_tokenization_spaces":
|
| 5 |
"eos_token": "<|endoftext|>",
|
|
|
|
| 6 |
"model_max_length": 1024,
|
| 7 |
"tokenizer_class": "GPT2Tokenizer",
|
| 8 |
"unk_token": "<|endoftext|>"
|
|
|
|
| 1 |
{
|
| 2 |
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"50256": {
|
| 5 |
+
"content": "<|endoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
"bos_token": "<|endoftext|>",
|
| 14 |
+
"clean_up_tokenization_spaces": false,
|
| 15 |
"eos_token": "<|endoftext|>",
|
| 16 |
+
"extra_special_tokens": {},
|
| 17 |
"model_max_length": 1024,
|
| 18 |
"tokenizer_class": "GPT2Tokenizer",
|
| 19 |
"unk_token": "<|endoftext|>"
|