benchaffe/shakespeare-lines
Viewer • Updated • 115k • 21
How to use benchaffe/shakespeare-distilgpt2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="benchaffe/shakespeare-distilgpt2") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("benchaffe/shakespeare-distilgpt2")
model = AutoModelForCausalLM.from_pretrained("benchaffe/shakespeare-distilgpt2")How to use benchaffe/shakespeare-distilgpt2 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "benchaffe/shakespeare-distilgpt2"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "benchaffe/shakespeare-distilgpt2",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/benchaffe/shakespeare-distilgpt2
How to use benchaffe/shakespeare-distilgpt2 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "benchaffe/shakespeare-distilgpt2" \
--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": "benchaffe/shakespeare-distilgpt2",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "benchaffe/shakespeare-distilgpt2" \
--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": "benchaffe/shakespeare-distilgpt2",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use benchaffe/shakespeare-distilgpt2 with Docker Model Runner:
docker model run hf.co/benchaffe/shakespeare-distilgpt2
This model is a fine-tuned version of distilbert/distilgpt2 on the shakespeare-lines dataset. It achieves the following results on the evaluation set:
The training and evaluation data was taken from the shakespeare-lines dataset. The dataset was shuffled with a seed of 24, and split into training and evaluation with a ratio of 80:20.
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("benchaffe/shakespeare-distilgpt2")
tokenizer = AutoTokenizer.from_pretrained("benchaffe/shakespeare-distilgpt2")
prompt = "What light through yonder window breaks"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
**inputs,
max_length=80,
temperature=0.8,
top_p=0.95,
do_sample=True
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
The following hyperparameters were used during training:
| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 3.9479 | 1.0 | 22941 | 4.2781 |
| 3.7527 | 2.0 | 45882 | 4.2111 |
| 3.5778 | 3.0 | 68823 | 4.2035 |
| 3.4214 | 4.0 | 91764 | 4.2129 |
| 3.3513 | 5.0 | 114705 | 4.2490 |
Base model
distilbert/distilgpt2