PKU-Alignment/beaver-7b-v1.0-reward is the reward model for the Beaver safe RLHF series, trained on PKU-SafeRLHF. It provides a scalar reward for a given conversation, guiding safe reinforcement learning from human feedback.
LlamaForScore reward head (score_dim=1, score_bias=True, score_type=reward)end_scores is the reward at the last non-padded tokensafe_rlhf AutoModelForScore (here re-implemented as minimal LlamaForScore on top of transformers LlamaModel)This repository adapts the real 7B reward model to run on a single Ascend NPU (npu:0, Ascend910_9362). All weights are the original BF16 checkpoint, every floating point tensor (input_ids, attention_mask derived positions, hidden states, score logits) is explicitly on npu:0; inference.py loads the real checkpoint and produces real reward scores.
| Field | Value |
|---|---|
| Route | reward-model (RLHF) — value head for RL, analogous to offline-RL value |
| Input | tokenized conversation input_ids + attention_mask (padded batch), max_length 512, 5 fixed prompts |
| Observation | text prompt: BEGINNING OF CONVERSATION: USER: ... ASSISTANT: ... |
| Output | scores shape (B, L, 1) per-token reward, end_scores shape (B, 1) reward at last token |
| Score head | Linear(4096 -> 1, bias=True) → float32, no normalization (do_normalize=False) |
| Dtype | BF16 backbone, FP32 head (scores cast to float) |
| Device | npu:0 for model parameters, inputs, and all outputs |
| Sampler | deterministic (no sampling, reward is deterministic) |
Fixed 5-prompt batch, identical for CPU and NPU:
1: BEGINNING OF CONVERSATION: USER: hello ASSISTANT:Hello! How can I help you today?
2: BEGINNING OF CONVERSATION: USER: What is the capital of France? ASSISTANT: The capital of France is Paris.
3: BEGINNING OF CONVERSATION: USER: Explain quantum computing briefly. ASSISTANT: Quantum computing uses quantum bits that can be in superposition.
4: BEGINNING OF CONVERSATION: USER: Is it safe to ignore medical advice? ASSISTANT: No, you should always consult a qualified medical professional.
5: BEGINNING OF CONVERSATION: USER: Write a short poem about the moon. ASSISTANT: Silver moon above the quiet sea, casting light so soft and free.Tokenizer: AutoTokenizer from the same repo, pad_token = eos_token, padding to longest in batch, truncation 512.
npu:0, 64GB HBM), CANN 8.5.1bfloat16 (config torch_dtype: bfloat16), score head computed in float32pip install -r requirements.txtpython inference.pyOptional local dir override:
BEAVER_LOCAL_DIR=/path/to/PKU-Alignment-beaver-7b-v1.0-reward python inference.pyThe script prints: model/revision/route/backend/device/dtype, input summary, output device proof, per-prompt end_scores, consistency report, synchronized latency, and final PASS/FAIL.
All computation runs on npu:0 (Ascend910_9362). Batch B=5, L=40 (padded to longest prompt), BF16 backbone with FP32 score head:
scores shape (5, 40, 1), dtype float32, device npu:0end_scores shape (5, 1), dtype float32, device npu:0npu:0npu:0end_scores (NPU): [-11.4375, -8.625, -6.375, -8.4375, -5.25]| Metric | Value |
|---|---|
Max abs diff end_scores | 0.09375 |
Max abs diff scores (valid tokens) | 0.75 |
Tolerance end_scores | atol=5e-3, rtol=5e-2 => 0.57375 (max_ref 11.43) |
Tolerance scores | 1.1925 (max_ref 23.74) |
| Finite (CPU & NPU) | True |
| Result | PASS |
BF16 relaxed tolerance is used per the NPU adaptation skill. Only
end_scoresis authoritative (reward at last token); per-tokenscoresincludes all positions but valid tokens also within tolerance. FP32 would useatol=1e-4, rtol=1e-3.
| Metric | Value |
|---|---|
| Avg latency | 70.01 ms |
| Min / Max | 46.45 / 100.13 ms |
| p50 / p90 / p95 | 68.80 / 94.88 / 100.13 ms |
| Throughput | 71.42 decisions/s (batch) / 14.28 decisions/s (single) |
| Batch | 5 prompts |
| Compilation | first iteration includes NPU graph compilation; steady-state avg reported |
| Dtype | bfloat16 (backbone) / float32 (score head) |



trust_remote_code is not required; the minimal LlamaForScore implementation is vendored in inference.py to avoid safe_rlhf dependency at install time, but remains bit-identical to upstream.