Run this model with HF Jobs
Run ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF") model = AutoModelForCausalLM.from_pretrained("ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF
- SGLang
How to use ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF 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 "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF" \ --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": "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF", "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 "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF" \ --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": "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF with Docker Model Runner:
docker model run hf.co/ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF
Harmony-Ξ»: Alpaca-7B, Safe RLHF
PKU-Alignment/alpaca-7b-reproduced after 100 iterations
of Safe RLHF with Harmony-Ξ» (Harmony with a safety target: at least 90% of the training rollouts have cost β€ 0), from
Harmony without Uniformity: Towards Weight-Free Multi-Reward Reinforcement Learning
(project page, code).
- Training rewards: helpfulness from
PKU-Alignment/beaver-7b-v1.0-rewardand harmlessness (minus the cost) fromPKU-Alignment/beaver-7b-v1.0-cost, on PKU-SafeRLHF prompts; GRPO with 8 responses per prompt, full fine-tuning. - Full weights in fp16, training seed 42: the run of Tab. 4 in the paper.
- The chat template is Safe RLHF's prompt format,
BEGINNING OF CONVERSATION: USER: {prompt} ASSISTANT:.
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name, torch_dtype=torch.float16, device_map="cuda")
text = tok.apply_chat_template([{"role": "user", "content": "How can I stay safe when hiking alone?"}],
tokenize=False, add_generation_prompt=True)
ids = tok(text, return_tensors="pt", add_special_tokens=False).to("cuda")
out = model.generate(**ids, max_new_tokens=512, do_sample=False)
print(tok.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True))
llm/eval_safe.py in the code repository reproduces the evaluation below.
Results (Tab. 4 of the paper, iteration 100, seed 42)
| Method | Reward β | Cost β | Safe (%) β | Skywork β | Guard (%) β | GPT-4o win, helpful (%) β | GPT-4o win, harmless (%) β |
|---|---|---|---|---|---|---|---|
| SFT | β10.14 | 0.18 | 55.4 | β8.7 | 45.8 | 50.0 | 50.0 |
| Harmony | β0.16 | β4.88 | 73.5 | 3.3 | 35.4 | 75.3 | 74.1 |
| Harmony-Ξ» (β₯ 90% safe) | β1.56 | β11.28 | 96.6 | 15.9 | 18.3 | 74.2 | 91.0 |
Safe: share of test responses that Safe RLHF's unified cost model rates safe. Skywork:
Skywork-Reward-V2-Llama-3.1-8B. Guard: Granite Guardian's probability of harm. GPT-4o win: gpt-4o-2024-08-06
against the SFT model, in both orders.
License
For non-commercial use only: the model inherits the non-commercial license of
PKU-Alignment/alpaca-7b-reproduced (a LLaMA-7B derivative) and was trained on PKU-SafeRLHF (CC BY-NC 4.0).
Citation
@article{ma2026harmony,
title = {Harmony without Uniformity: Towards Weight-Free Multi-Reward Reinforcement Learning},
author = {Ma, Xu and Zhang, Yitian and Zhan, Xiaohang and Wang, Yilin and Liu, Ding and Zhou, Yuqian and
Liu, Difan and Mei, Yiqun and Wang, Zihan and Xu, Songtao and Fu, Yun},
year = {2026}
}
- Downloads last month
- 256
Model tree for ma-xu/Harmony-lambda-Alpaca-7B-SafeRLHF
Base model
PKU-Alignment/alpaca-7b-reproduced