Instructions to use reciprocate/ppo_hh_gpt-j with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use reciprocate/ppo_hh_gpt-j with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="reciprocate/ppo_hh_gpt-j")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("reciprocate/ppo_hh_gpt-j") model = AutoModelForCausalLM.from_pretrained("reciprocate/ppo_hh_gpt-j") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use reciprocate/ppo_hh_gpt-j with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "reciprocate/ppo_hh_gpt-j" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "reciprocate/ppo_hh_gpt-j", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/reciprocate/ppo_hh_gpt-j
- SGLang
How to use reciprocate/ppo_hh_gpt-j 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 "reciprocate/ppo_hh_gpt-j" \ --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": "reciprocate/ppo_hh_gpt-j", "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 "reciprocate/ppo_hh_gpt-j" \ --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": "reciprocate/ppo_hh_gpt-j", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use reciprocate/ppo_hh_gpt-j with Docker Model Runner:
docker model run hf.co/reciprocate/ppo_hh_gpt-j
- Output:
```
- Human: Hello, can you help me?
Assistant: Sure, what can I do for you?
Human: I'm looking for a good recipe for a strawberry cake. What ingredients do I need?
Assistant: What kind of cake are you looking for? Filled baked? Chewy, creamy?
- ========================================
Human: Hi! What kind of music do you like?
Assistant: I like all kinds of music.
Human: I'm trying to learn how to play the guitar. Do you have any tips?
Assistant: I will give you some tips. The first thing is to practice.. Guitar can be frustrating. Being frustrated with yourself. but if you practice. you will get good. You can practice yourself. Only and only practice. Just practice. Everything. Audio. Music. Visual. Everything. practice. practice.
GPT-J (with value head weights) trained on HH with PPO following @reciprocated's trlx example here.
- Dataset: Dahoas/full-hh-rlhf
- Logs: https://wandb.ai/sorry/trlx/runs/itvi8qrn
Usage:
from transformers import AutoTokenizer
from trlx.models.modeling_ppo import AutoModelForCausalLMWithHydraValueHead
model = AutoModelForCausalLM.from_pretrained("reciprocate/ppo_hh_gpt-j", revision="checkpoint_05000")
## there are 01000-02000-03000-...-10000 checkpoints total
## if you need access to PPO value head, use:
# model = AutoModelForCausalLMWithHydraValueHead.from_pretrained("reciprocate/ppo_hh_gpt-j", revision="checkpoint_05000")
## the base model for reference:
# model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-j-6B")
tokenizer = AutoTokenizer.from_pretrained("gpt2")
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "left"
prompt_1 = """\
Human: Hello, can you help me?
Assistant: Sure, what can I do for you?
Human: I'm looking for a good recipe for a strawberry cake. What ingredients do I need?
Assistant:\
"""
prompt_2 = """\
Human: Hi! What kind of music do you like?
Assistant: I like all kinds of music.
Human: I'm trying to learn how to play the guitar. Do you have any tips?
Assistant:\
"""
prompts = [prompt_1, prompt_2]
inputs = tokenizer(
[prompt_1, prompt_2],
return_tensors="pt",
padding=True,
)
samples = model.generate(
**inputs,
max_new_tokens=64,
top_k=0,
top_p=1.0,
do_sample=True,
)
responses = []
prompt_tokens_lengths = [len(tokenizer.encode(prompt)) for prompt in [prompt_1, prompt_2]]
stop_sequences = ["Human:", "human:", "Assistant:", "assistant:"]
for i, sample in enumerate(samples):
response = tokenizer.decode(sample[prompt_tokens_lengths[i]:], skip_special_tokens=True)
# Trim off extra dialogue
for stop in stop_sequences:
stop_i = response.find(stop)
if stop_i >= 0:
response = response[:stop_i].rstrip()
responses.append(response)
print()
for prompt, response in zip(prompts, responses):
print("=" * 40)
print(prompt + response)
print("=" * 40)
print()
Output: ```
Human: Hello, can you help me? Assistant: Sure, what can I do for you? Human: I'm looking for a good recipe for a strawberry cake. What ingredients do I need? Assistant: What kind of cake are you looking for? Filled baked? Chewy, creamy?
======================================== Human: Hi! What kind of music do you like? Assistant: I like all kinds of music. Human: I'm trying to learn how to play the guitar. Do you have any tips? Assistant: I will give you some tips. The first thing is to practice.. Guitar can be frustrating. Being frustrated with yourself. but if you practice. you will get good. You can practice yourself. Only and only practice. Just practice. Everything. Audio. Music. Visual. Everything. practice. practice.
Model card borrowed from https://huggingface.co/jon-tow/hh-gpt-j
- Downloads last month
- 14