{"id":29275604,"url":"https://github.com/thiraput01/qwenmed","last_synced_at":"2025-07-05T06:40:40.539Z","repository":{"id":300442279,"uuid":"1006188197","full_name":"Thiraput01/QwenMed","owner":"Thiraput01","description":"Qwen3 fine-tuned on medical datasets with reasoning data","archived":false,"fork":false,"pushed_at":"2025-06-21T18:28:04.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-21T18:34:49.365Z","etag":null,"topics":["llm","parameter-efficient-fine-tuning","unsloth"],"latest_commit_sha":null,"homepage":"https://huggingface.co/Thiraput01/QwenMed-1.7B-Reasoning","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Thiraput01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-21T17:31:41.000Z","updated_at":"2025-06-21T18:28:07.000Z","dependencies_parsed_at":"2025-06-21T18:45:10.642Z","dependency_job_id":null,"html_url":"https://github.com/Thiraput01/QwenMed","commit_stats":null,"previous_names":["thiraput01/qwenmed"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Thiraput01/QwenMed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thiraput01%2FQwenMed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thiraput01%2FQwenMed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thiraput01%2FQwenMed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thiraput01%2FQwenMed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thiraput01","download_url":"https://codeload.github.com/Thiraput01/QwenMed/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thiraput01%2FQwenMed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263698519,"owners_count":23497910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llm","parameter-efficient-fine-tuning","unsloth"],"created_at":"2025-07-05T06:40:33.600Z","updated_at":"2025-07-05T06:40:40.533Z","avatar_url":"https://github.com/Thiraput01.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QwenMed\n\nQwenMed is a Large Language Model (LLM) fine-tuned on the Qwen3-1.7B model using Unsloth for QLoRA for medical question answering.\n\n---\n\n## Features\n\n* **Medical Question Answering**: Provides responses to medical queries.\n* **Reasoning Capability**: Can generate detailed thought processes (Chain-of-Thought) before providing a concise answer.\n* **Efficient Fine-tuning**: Unsloth library for PEFT.\n* **Hugging Face Integration**: Models are pushed to and loaded from Hugging Face Hub.\n\n\n## Usage\nThe `notebooks/QwenMed_inference.ipynb` notebook demonstrates how to load the model and perform inference. \nYou can switch between non-thinking and reasoning modes to observe different response styles.\n\n**For Non-Thinking**\n```python\nfrom unsloth import FastLanguageModel\nimport torch\nfrom transformers import TextStreamer\n\nmodel, tokenizer = FastLanguageModel.from_pretrained(\n    model_name = \"Thiraput01/QwenMed-1.7B-Reasoning\",\n    max_seq_length = 2048,\n    load_in_4bit = True,\n)\n\nmessages = [\n    {\"role\" : \"user\", \"content\" : \"I'm having chest pain, what could be the cause?\"}\n]\ntext = tokenizer.apply_chat_template(\n    messages,\n    tokenize = False,\n    add_generation_prompt = True,\n    enable_thinking = False, # Disable thinking\n)\n\n_ = model.generate(\n    **tokenizer(text, return_tensors = \"pt\").to(\"cuda\"),\n    max_new_tokens = 256,\n    temperature = 0.7, top_p = 0.8, top_k = 20,\n    streamer = TextStreamer(tokenizer, skip_prompt = True),\n)\n```\n\n\n**For Thinking (Reasoning) inference**\n```python\nfrom unsloth import FastLanguageModel\nimport torch\nfrom transformers import TextStreamer\n\nmodel, tokenizer = FastLanguageModel.from_pretrained(\n    model_name = \"Thiraput01/QwenMed-1.7B-Reasoning\",\n    max_seq_length = 2048,\n    load_in_4bit = True,\n)\n\nmessages = [\n    {\"role\" : \"user\", \"content\" : \"I'm having a headace, what do you think?\"}\n]\ntext = tokenizer.apply_chat_template(\n    messages,\n    tokenize = False,\n    add_generation_prompt = True,\n    enable_thinking = True, # Enable thinking\n)\n\n_ = model.generate(\n    **tokenizer(text, return_tensors = \"pt\").to(\"cuda\"),\n    max_new_tokens = 2048,\n    temperature = 0.6, top_p = 0.95, top_k = 20,\n    streamer = TextStreamer(tokenizer, skip_prompt = True),\n)\n```\n\n\n# Training\nThe `notebooks/QwenMed_train.ipynb` notebook provides the process for fine-tuning the QwenMed model.\n\n\n# Dataset Used\n\n- [FreedomIntelligence/medical-o1-reasoning-SFT](https://huggingface.co/datasets/FreedomIntelligence/medical-o1-reasoning-SFT)\n- [Laurent1/MedQuad-MedicalQnADataset_128tokens_max](https://huggingface.co/datasets/Laurent1/MedQuad-MedicalQnADataset_128tokens_max)\n\n\n# Training Configuration\n- Base Model: `unsloth/Qwen3-1.7B-unsloth-bnb-4bit`\n- Epochs: `2`\n- Learning Rate: `5e-5`\n- Scheduler: `CosineAnnealingLR`\n- LoRA Parameters: `r=32, alpha=64`\n- Batch Size: `2`\n- Gradient Accumulation Steps = `8`\n\n\n# Results\n**Training results**\n\n![train](https://raw.githubusercontent.com/Thiraput01/QwenMed/main/result/train_graph.png)\n\n**Validation results**\n\n![eval](https://raw.githubusercontent.com/Thiraput01/QwenMed/main/result/eval_graph.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiraput01%2Fqwenmed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiraput01%2Fqwenmed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiraput01%2Fqwenmed/lists"}