from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfigfrom peft import PeftModelimport torch # Base model (original model from Meta)base_model_id = "Qwen/Qwen3-32B" # Your fine-tuned LoRA adapter repositorylora_adapter_id = "kingabzpro/Qwen-3-32B-Medical-Reasoning" # Load the model in 4-bitbnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_use_double_quant=False, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16,) # Load base modelbase_model = AutoModelForCausalLM.from_pretrained( base_model_id, device_map="auto", torch_dtype=torch.bfloat16, quantization_config=bnb_config, trust_remote_code=True,) # Attach the LoRA adaptermodel = PeftModel.from_pretrained( base_model, lora_adapter_id, device_map="auto", trust_remote_code=True,) # Load tokenizertokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True) # Inference exampleprompt = """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:What is the initial management for a patient presenting with diabetic ketoacidosis (DKA)? ### Response:<think>""" inputs = tokenizer(prompt, return_tensors="pt").to(model.device)outputs = model.generate(**inputs, max_new_tokens=1200)response = tokenizer.decode(outputs[0], skip_special_tokens=True) print(response)