Fine-tuned Qwen3-0.6B for Medical Reasoning

This repository contains a fine-tuned version of the Qwen/Qwen3-0.6B model using LoRA (Low-Rank Adaptation) on the FreedomIntelligence/medical-o1-reasoning-SFT dataset.

Model Description

This model has been fine-tuned to improve its reasoning capabilities in the medical domain, specifically for medical question-answering tasks that involve complex chains of thought. It leverages the Qwen3-0.6B architecture and benefits from 4-bit quantization using bitsandbytes for efficient training and inference.

Training Details

  • Base Model: Qwen/Qwen3-0.6B
  • Fine-tuning Method: LoRA (PEFT)
  • Dataset: FreedomIntelligence/medical-o1-reasoning-SFT
  • Quantization: 4-bit with bnb_4bit_quant_type="fp4"
  • Epochs: 1
  • Batch Size: 4
  • Learning Rate: 2e-05
  • Max Sequence Length: 256

How to Use

To use this fine-tuned model, you can load it with the transformers and peft libraries.

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
from peft import PeftModel

# Your Hugging Face repository name
repo_name = "devesh1011/qwen-medical-reasoning"

# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(repo_name, trust_remote_code=True)
if tokenizer.pad_token is None:
    tokenizer.pad_token = tokenizer.eos_token

# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-0.6B",
    torch_dtype=torch.float16,
    device_map="auto",
    trust_remote_code=True
)

# Load PEFT (LoRA) adapter
model = PeftModel.from_pretrained(base_model, repo_name)

# Optional: Merge LoRA into base for full inference model
# model = model.merge_and_unload()
# model.save_pretrained("./qwen_finetuned_merged")
# tokenizer.save_pretrained("./qwen_finetuned_merged")

# Setup generation pipeline
generator = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    torch_dtype=torch.float16
)

# Example inference (matching training prompt format)
prompt = """<|im_start|>user
Question: What is the primary cause of type 1 diabetes?
<|im_end|>
<|im_start|>assistant
"""
output = generator(
    prompt,
    do_sample=True,
    temperature=0.7,
    top_p=0.9,
    pad_token_id=tokenizer.eos_token_id,
    eos_token_id=tokenizer.eos_token_id,
    repetition_penalty=1.1,
    max_new_tokens=200 # Limit output length for demonstration
)

print("Generated Response:")
# Extract only the assistant's response part after the prompt
response_text = output[0]['generated_text'][len(prompt):].strip()
# Remove any trailing <|im_end|> if present
if response_text.endswith("<|im_end|>"):
    response_text = response_text[:-len("<|im_end|>")].strip()
print(response_text)
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for devesh1011/qwen-medical-reasoning

Finetuned
Qwen/Qwen3-0.6B
Adapter
(481)
this model