rahul77/rahul-gpt2-1k
Viewer • Updated • 10.4k • 9
How to use rahul77/gpt-2-finetune with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="rahul77/gpt-2-finetune") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("rahul77/gpt-2-finetune")
model = AutoModelForCausalLM.from_pretrained("rahul77/gpt-2-finetune")How to use rahul77/gpt-2-finetune with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "rahul77/gpt-2-finetune"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "rahul77/gpt-2-finetune",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/rahul77/gpt-2-finetune
How to use rahul77/gpt-2-finetune with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "rahul77/gpt-2-finetune" \
--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": "rahul77/gpt-2-finetune",
"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 "rahul77/gpt-2-finetune" \
--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": "rahul77/gpt-2-finetune",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use rahul77/gpt-2-finetune with Docker Model Runner:
docker model run hf.co/rahul77/gpt-2-finetune
This is a fine-tuned version of the GPT-2 model designed for text generation tasks. The model has been fine-tuned to improve its performance on generating coherent and contextually relevant text.
pad_token_id: 50256bos_token_id: 50256eos_token_id: 50256This model supports the following task:
To use this model for text generation via the Hugging Face API, use the following Python code snippet:
import requests
api_url = "https://api-inference.huggingface.co/models/rahul77/gpt-2-finetune"
headers = {
"Authorization": "Bearer YOUR_API_TOKEN", # Replace with your Hugging Face API token
"Content-Type": "application/json"
}
data = {
"inputs": "What is a large language model?",
"parameters": {
"max_length": 50
}
}
response = requests.post(api_url, headers=headers, json=data)
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code}")
print(response.json())
Base model
openai-community/gpt2