m-newhauser/senator-tweets
Viewer • Updated • 99.7k • 247 • 6
How to use Realluke/phi-2-senator-tweets with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Realluke/phi-2-senator-tweets", trust_remote_code=True) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Realluke/phi-2-senator-tweets", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Realluke/phi-2-senator-tweets", trust_remote_code=True)How to use Realluke/phi-2-senator-tweets with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Realluke/phi-2-senator-tweets"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Realluke/phi-2-senator-tweets",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/Realluke/phi-2-senator-tweets
How to use Realluke/phi-2-senator-tweets with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Realluke/phi-2-senator-tweets" \
--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": "Realluke/phi-2-senator-tweets",
"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 "Realluke/phi-2-senator-tweets" \
--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": "Realluke/phi-2-senator-tweets",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use Realluke/phi-2-senator-tweets with Docker Model Runner:
docker model run hf.co/Realluke/phi-2-senator-tweets
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Realluke/phi-2-senator-tweets", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Realluke/phi-2-senator-tweets", trust_remote_code=True)Phi-2 finetuned on Senator Tweets.
The starting token is [start] and the ending token is [end]
Example:
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("Realluke/phi-2-senator-tweets", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
inputs = tokenizer("[start]", return_tensors="pt", return_attention_mask=False)
outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Realluke/phi-2-senator-tweets", trust_remote_code=True)