Views
No views yet
meta-llama/Meta-Llama-3.1-8B-Instruct for clinical question answering. The adapter encourages explicit chain-of-thought reasoning so the model walks through diagnostic steps before giving a final answer.r=16, alpha=16, dropout=0.0)FreedomIntelligence/medical-o1-reasoning-SFT (English split with Question, Complex_CoT, Response fields)Please provide an appropriate response based on the instruction and the specific question given below.
Before answering, please think carefully about the question and demonstrate a step-by-step reasoning process to ensure the logic and accuracy of your response.
### Instruction:
You are a medical expert proficient in clinical reasoning, diagnosis, and treatment planning.
Please answer the medical question below.
### Question:
{Question}
### Answer:
<think>
{Complex_CoT}
</think>
{Response}<think> tags are optional but help separate the reasoning trace from the final answer.1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3
4base_model = "meta-llama/Meta-Llama-3.1-8B-Instruct"
5adapter_id = "your-username/medical-llm-reasoning-lora" # replace with this repo ID
6
7quant_cfg = BitsAndBytesConfig(load_in_8bit=True)
8model = AutoModelForCausalLM.from_pretrained(
9 base_model,
10 quantization_config=quant_cfg,
11 device_map="auto",
12 trust_remote_code=True,
13)
14tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
15if tokenizer.pad_token is None:
16 tokenizer.pad_token = tokenizer.eos_token
17
18model = PeftModel.from_pretrained(model, adapter_id)
19
20prompt = """Please provide an appropriate response based on the instruction and the question.
21Instruction: You are a medical expert proficient in clinical reasoning.
22Question: A patient has a persistent cough, hemoptysis, low-grade fever, and night sweats. What is the most likely diagnosis?
23Answer:
24"""
25
26inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
27outputs = model.generate(
28 **inputs,
29 max_new_tokens=256,
30 eos_token_id=tokenizer.eos_token_id,
31 temperature=0.7,
32 top_p=0.9,
33)
34print(tokenizer.decode(outputs[0], skip_special_tokens=True))