HuggingFaceH4/ultrafeedback_binarized
Viewer • Updated • 187k • 17k • 338
How to use AIR-hl/Qwen2.5-1.5B-SimPO with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="AIR-hl/Qwen2.5-1.5B-SimPO")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("AIR-hl/Qwen2.5-1.5B-SimPO")
model = AutoModelForCausalLM.from_pretrained("AIR-hl/Qwen2.5-1.5B-SimPO")
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 AIR-hl/Qwen2.5-1.5B-SimPO with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "AIR-hl/Qwen2.5-1.5B-SimPO"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "AIR-hl/Qwen2.5-1.5B-SimPO",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/AIR-hl/Qwen2.5-1.5B-SimPO
How to use AIR-hl/Qwen2.5-1.5B-SimPO with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "AIR-hl/Qwen2.5-1.5B-SimPO" \
--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": "AIR-hl/Qwen2.5-1.5B-SimPO",
"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 "AIR-hl/Qwen2.5-1.5B-SimPO" \
--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": "AIR-hl/Qwen2.5-1.5B-SimPO",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use AIR-hl/Qwen2.5-1.5B-SimPO with Docker Model Runner:
docker model run hf.co/AIR-hl/Qwen2.5-1.5B-SimPO
devices: 4 * NPU 910B-64GB
precision: bf16 mixed-precision
global_batch_size: 128
beta: 1 gamma: 0.1 bf16: True learning_rate: 1e-6 lr_scheduler_type: cosine per_device_train_batch_size: 16 gradient_accumulation_steps: 2 torch_dtype: bfloat16 num_train_epochs: 1 max_prompt_length: 512 max_length: 1024 warmup_ratio: 0.05
init_train_loss: 0.7551 final_train_loss: 0.6715 accuracy: 0.6375 reward_margin: 0.3633
import torch
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer
from trl import (
CPOConfig,
CPOTrainer,
ModelConfig,
ScriptArguments,
TrlParser,
get_kbit_device_map,
get_peft_config,
get_quantization_config,
)
from trl.trainer.utils import SIMPLE_CHAT_TEMPLATE
if __name__ == "__main__":
parser = TrlParser((ScriptArguments, CPOConfig, ModelConfig))
script_args, training_args, model_config = parser.parse_args_and_config()
torch_dtype = (
model_config.torch_dtype
if model_config.torch_dtype in ["auto", None]
else getattr(torch, model_config.torch_dtype)
)
quantization_config = get_quantization_config(model_config)
model_kwargs = dict(
revision=model_config.model_revision,
attn_implementation=model_config.attn_implementation,
torch_dtype=torch_dtype,
use_cache=False if training_args.gradient_checkpointing else True,
device_map=get_kbit_device_map() if quantization_config is not None else None,
quantization_config=quantization_config,
)
model = AutoModelForCausalLM.from_pretrained(
model_config.model_name_or_path, trust_remote_code=model_config.trust_remote_code, **model_kwargs
)
peft_config = get_peft_config(model_config)
tokenizer = AutoTokenizer.from_pretrained(
model_config.model_name_or_path, trust_remote_code=model_config.trust_remote_code
)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
if tokenizer.chat_template is None:
tokenizer.chat_template = SIMPLE_CHAT_TEMPLATE
if script_args.ignore_bias_buffers:
model._ddp_params_and_buffers_to_ignore = [
name for name, buffer in model.named_buffers() if buffer.dtype == torch.bool
]
dataset=load_dataset(script_args.dataset_name,
split=script_args.dataset_train_split)
dataset=dataset.select_columns(['prompt', 'chosen', 'rejected'])
trainer = CPOTrainer(
model,
args=training_args,
train_dataset=dataset,
processing_class=tokenizer,
peft_config=peft_config,
)
trainer.train()
trainer.save_model(training_args.output_dir)