Views
No views yet
Qwen/Qwen3-32B model using a medical reasoning dataset (FreedomIntelligence/medical-o1-reasoning-SFT) with 4-bit quantization for memory-efficient training.1pip install -U datasets accelerate peft trl bitsandbytes
2pip install -U transformers
3pip install huggingface_hub[hf_xet]export HF_TOKEN=your_huggingface_tokenBitsAndBytesConfig for efficient memory usage.FreedomIntelligence/medical-o1-reasoning-SFT (first 500 samples).Here is the training notebook: Fine_tuning_Qwen-3-32B
Qwen/Qwen3-32Bnvidia-smi check is included).Below is an instruction that describes a task, paired with an input that provides further context.
Write a response that appropriately completes the request.
Before answering, think carefully about the question and create a step-by-step chain of thoughts to ensure a logical and accurate response.
### Instruction:
You are a medical expert with advanced knowledge in clinical reasoning, diagnostics, and treatment planning.
Please answer the following medical question.
### Question:
{}
### Response:
<think>
{}
</think>
{}1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# Base model (original model from Meta)
6base_model_id = "Qwen/Qwen3-32B"
7
8# Your fine-tuned LoRA adapter repository
9lora_adapter_id = "kingabzpro/Qwen-3-32B-Medical-Reasoning"
10
11# Load the model in 4-bit
12bnb_config = BitsAndBytesConfig(
13 load_in_4bit=True,
14 bnb_4bit_use_double_quant=False,
15 bnb_4bit_quant_type="nf4",
16 bnb_4bit_compute_dtype=torch.bfloat16,
17)
18
19# Load base model
20base_model = AutoModelForCausalLM.from_pretrained(
21 base_model_id,
22 device_map="auto",
23 torch_dtype=torch.bfloat16,
24 quantization_config=bnb_config,
25 trust_remote_code=True,
26)
27
28# Attach the LoRA adapter
29model = PeftModel.from_pretrained(
30 base_model,
31 lora_adapter_id,
32 device_map="auto",
33 trust_remote_code=True,
34)
35
36# Load tokenizer
37tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
38
39# Inference example
40prompt = """Below is an instruction that describes a task, paired with an input that provides further context.
41Write a response that appropriately completes the request.
42Before answering, think carefully about the question and create a step-by-step chain of thoughts to ensure a logical and accurate response.
43
44### Instruction:
45You are a medical expert with advanced knowledge in clinical reasoning, diagnostics, and treatment planning.
46Please answer the following medical question.
47
48### Question:
49What is the initial management for a patient presenting with diabetic ketoacidosis (DKA)?
50
51### Response:
52<think>
53"""
54
55inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
56outputs = model.generate(**inputs, max_new_tokens=1200)
57response = tokenizer.decode(outputs[0], skip_special_tokens=True)
58
59print(response)
60
61
62