Views
No views yet
1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3from peft import PeftModel
4
5# Load base model and tokenizer
6base_model = AutoModelForSequenceClassification.from_pretrained(
7 "Skywork/Skywork-Reward-V2-Llama-3.1-8B",
8 num_labels=1,
9 torch_dtype=torch.bfloat16,
10 device_map="auto"
11)
12tokenizer = AutoTokenizer.from_pretrained("Skywork/Skywork-Reward-V2-Llama-3.1-8B")
13
14# Load LoRA adapter
15model = PeftModel.from_pretrained(base_model, "kewu93/skywork-medarena-lora-v2")
16
17# Prepare input (use conversation format)
18conversation = [
19 {"role": "user", "content": "What are the symptoms of diabetes?"},
20 {"role": "assistant", "content": "Common symptoms of diabetes include frequent urination, excessive thirst, unexplained weight loss, fatigue, blurred vision, and slow-healing cuts or wounds. If you experience these symptoms, consult a healthcare provider for proper diagnosis and treatment."}
21]
22
23# Tokenize using chat template (IMPORTANT: use this format for best results)
24text = tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=False)
25inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=2048)
26
27# Get reward score
28with torch.no_grad():
29 outputs = model(**inputs)
30 reward_score = outputs.logits.squeeze().item()
31 print(f"Reward Score: {reward_score:.4f}")| Version | Accuracy | Score Margin | Training |
|---|---|---|---|
| v2 (checkpoint-504) | 61.20% | 0.8204 | 8 epochs |
| v1 (final checkpoint) | 60.60% | 0.5030 | 10 epochs |
| checkpoint-500 | 60.40% | 0.5131 | ~8 epochs |
1@misc{skywork-medarena-lora-v2,
2 title={Skywork MedArena LoRA v2: Optimal Medical Preference Learning},
3 author={kewu93},
4 year={2024},
5 url={https://huggingface.co/kewu93/skywork-medarena-lora-v2}
6}adapter_config.json: LoRA adapter configurationadapter_model.safetensors: LoRA adapter weights (optimal checkpoint)tokenizer.json, tokenizer_config.json: Tokenizer fileschat_template.jinja: Chat template for proper formatting