LLM_course_hw2
Collection
A collection of repos for second homework. • 3 items • Updated
How to use efromomr/llm-course-hw2-ppo with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="efromomr/llm-course-hw2-ppo")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("efromomr/llm-course-hw2-ppo")
model = AutoModelForCausalLM.from_pretrained("efromomr/llm-course-hw2-ppo")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use efromomr/llm-course-hw2-ppo with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "efromomr/llm-course-hw2-ppo"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "efromomr/llm-course-hw2-ppo",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/efromomr/llm-course-hw2-ppo
How to use efromomr/llm-course-hw2-ppo with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "efromomr/llm-course-hw2-ppo" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "efromomr/llm-course-hw2-ppo",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "efromomr/llm-course-hw2-ppo" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "efromomr/llm-course-hw2-ppo",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use efromomr/llm-course-hw2-ppo with Docker Model Runner:
docker model run hf.co/efromomr/llm-course-hw2-ppo
This model is a fine-tuned version of HuggingFaceTB/SmolLM-135M-Instruct. It has been trained using TRL.
This model is an aligned version of HuggingFaceTB/SmolLM-135M-Instruct. Method used for training is PPO.
Final rlhf reward is 1.60, final score is 1.66.
DEVICE = torch.device("cuda")
tokenizer = AutoTokenizer.from_pretrained(efromomr/llm-course-hw2-dpo)
check_model = AutoModelForCausalLM.from_pretrained(efromomr/llm-course-hw2-dpo)
check_model = check_model.to(DEVICE)
check_model = check_model.eval()
messages = [{"role": "user", "content": "What's your morning routine like?"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
model_inputs = tokenizer([text], return_tensors="pt")
generated_ids = model.generate(model_inputs.input_ids.to(DEVICE), max_new_tokens=256, do_sample=True)
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
#user
#What's your morning routine like?
#assistant
#As I sit here, I'm already feeling a bit...off. I'm trying to get out of bed, but it's hard to get out of bed. I'm trying to get some morning sunlight, but it's just not happening. I'm also feeling a bit...uncomfortable. I'm trying to get some fresh air, but it's just not happening. I'm trying to get some morning exercise, but it's just not happening. I'm trying to get some morning meditation, but it's just not happening.
This model was trained with PPO, a method introduced in Fine-Tuning Language Models from Human Preferences.
Cite PPO as:
@article{mziegler2019fine-tuning,
title = {{Fine-Tuning Language Models from Human Preferences}},
author = {Daniel M. Ziegler and Nisan Stiennon and Jeffrey Wu and Tom B. Brown and Alec Radford and Dario Amodei and Paul F. Christiano and Geoffrey Irving},
year = 2019,
eprint = {arXiv:1909.08593}
}
Cite TRL as:
@misc{vonwerra2022trl,
title = {{TRL: Transformer Reinforcement Learning}},
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
year = 2020,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/huggingface/trl}}
}
Base model
HuggingFaceTB/SmolLM-135M