Text Generation
Transformers
Safetensors
English
Chinese
chatglm
Long Context
llama
conversational
custom_code
Instructions to use NeoZ123/LongReward-glm4-9b-SFT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NeoZ123/LongReward-glm4-9b-SFT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NeoZ123/LongReward-glm4-9b-SFT", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("NeoZ123/LongReward-glm4-9b-SFT", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use NeoZ123/LongReward-glm4-9b-SFT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NeoZ123/LongReward-glm4-9b-SFT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NeoZ123/LongReward-glm4-9b-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/NeoZ123/LongReward-glm4-9b-SFT
- SGLang
How to use NeoZ123/LongReward-glm4-9b-SFT 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 "NeoZ123/LongReward-glm4-9b-SFT" \ --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": "NeoZ123/LongReward-glm4-9b-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "NeoZ123/LongReward-glm4-9b-SFT" \ --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": "NeoZ123/LongReward-glm4-9b-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use NeoZ123/LongReward-glm4-9b-SFT with Docker Model Runner:
docker model run hf.co/NeoZ123/LongReward-glm4-9b-SFT
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("NeoZ123/LongReward-glm4-9b-SFT", trust_remote_code=True, dtype="auto")Quick Links
LongReward-glm4-9b-SFT
🤗 [LongReward Dataset] • 💻 [Github Repo] • 📃 [LongReward Paper]
LongReward-glm4-9b-SFT is supervisedly fined-tuned from glm-4-9b using the sft split of LongReward-10k dataset, and supports a maximum context window of up to 64K tokens.
Environment: Same environment requirement as glm-4-9b-chat (transforemrs>=4.43.0).
A simple demo for deployment of the model:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = "NeoZ123/LongReward-glm4-9b-SFT"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map='auto')
context = '''
W. Russell Todd, 94, United States Army general (b. 1928). February 13. Tim Aymar, 59, heavy metal singer (Pharaoh) (b. 1963). Marshall \"Eddie\" Conway, 76, Black Panther Party leader (b. 1946). Roger Bonk, 78, football player (North Dakota Fighting Sioux, Winnipeg Blue Bombers) (b. 1944). Conrad Dobler, 72, football player (St. Louis Cardinals, New Orleans Saints, Buffalo Bills) (b. 1950). Brian DuBois, 55, baseball player (Detroit Tigers) (b. 1967). Robert Geddes, 99, architect, dean of the Princeton University School of Architecture (1965–1982) (b. 1923). Tom Luddy, 79, film producer (Barfly, The Secret Garden), co-founder of the Telluride Film Festival (b. 1943). David Singmaster, 84, mathematician (b. 1938).
'''
query = "What was Robert Geddes' profession?"
prompt = context + '\n\n' + query
response, _ = model.chat(tokenizer, prompt, temprature=1, max_new_tokens=1024)
print(response)
You can also deploy the model with vllm for faster inference:
import torch
from vllm import LLM, SamplingParams
model_path = "NeoZ123/LongReward-glm4-9b-SFT"
model = LLM(
model= model_path,
dtype=torch.bfloat16,
trust_remote_code=True,
tensor_parallel_size=1,
max_model_len=65536,
gpu_memory_utilization=1,
)
tokenizer = model.get_tokenizer()
context = '''
W. Russell Todd, 94, United States Army general (b. 1928). February 13. Tim Aymar, 59, heavy metal singer (Pharaoh) (b. 1963). Marshall \"Eddie\" Conway, 76, Black Panther Party leader (b. 1946). Roger Bonk, 78, football player (North Dakota Fighting Sioux, Winnipeg Blue Bombers) (b. 1944). Conrad Dobler, 72, football player (St. Louis Cardinals, New Orleans Saints, Buffalo Bills) (b. 1950). Brian DuBois, 55, baseball player (Detroit Tigers) (b. 1967). Robert Geddes, 99, architect, dean of the Princeton University School of Architecture (1965–1982) (b. 1923). Tom Luddy, 79, film producer (Barfly, The Secret Garden), co-founder of the Telluride Film Festival (b. 1943). David Singmaster, 84, mathematician (b. 1938).
'''
query = "What was Robert Geddes' profession?"
prompt = context + '\n\n' + query
inputs = tokenizer.build_chat_input(prompt, history=[], role='user')
eos_token_id = [tokenizer.eos_token_id, tokenizer.get_command("<|user|>"), tokenizer.get_command("<|observation|>")]
generation_params = SamplingParams(
temperature=0.95,
top_p=0.7,
max_tokens=1024,
stop_token_ids=eos_token_id,
)
input_ids = inputs.input_ids[0].tolist()
outputs = model.generate(sampling_params=generation_params, prompt_token_ids=[input_ids])
response = tokenizer.decode(outputs[0].outputs[0].token_ids[:-1])
print(response)
License
Citation
If you find our work useful, please consider citing LongReward:
@article{zhang2024longreward,
title = {LongReward: Improving Long-context Large Language Models
with AI Feedback}
author={Jiajie Zhang and Zhongni Hou and Xin Lv and Shulin Cao and Zhenyu Hou and Yilin Niu and Lei Hou and Yuxiao Dong and Ling Feng and Juanzi Li},
journal={arXiv preprint arXiv:2410.21252},
year={2024}
}
- Downloads last month
- 2
Dataset used to train NeoZ123/LongReward-glm4-9b-SFT
Viewer • Updated • 30k • 998 • 7
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NeoZ123/LongReward-glm4-9b-SFT", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)