Model Card for Gemma-3-1B-it-Medical-LoRA

This model is a fine-tuned version of unsloth/gemma-3-1b-it-unsloth-bnb-4bit. It has been trained using TRL.

Training procedure

This model was trained with SFT.

Usage

HuggingFace Authentication

import os
from huggingface_hub import login

# Set the Hugging Face API token
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "<your_huggingface_token>"

# # Initialize API
login(os.environ.get("HUGGINGFACEHUB_API_TOKEN"))

Inference

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

device = "cuda" if torch.cuda.is_available() else "cpu"

# Define model and LoRA adapter paths
base_model_name = "google/gemma-3-1b-it"
lora_adapter_name = "danhtran2mind/Gemma-3-1B-Instruct-Vi-Medical-LoRA"

# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(base_model_name)

# Load base model with optimized settings
model = AutoModelForCausalLM.from_pretrained(
    base_model_name,
    torch_dtype=torch.float16,  # Use FP16 for efficiency
    device_map=device,
    trust_remote_code=True
)

# Apply LoRA adapter
model = PeftModel.from_pretrained(model, lora_adapter_name)

# Set model to evaluation mode
model.eval()

# Define the question
prompt = ("Khi nghi ngờ bị loét dạ dày tá tràng nên đến khoa nào "
          "tại bệnh viện để thăm khám?")

seed = 42
torch.manual_seed(seed)
if torch.cuda.is_available():
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)

messages = [{"role": "user", "content": prompt}]

text = tokenizer.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=False  # Ensure the output is a string
)

# Tokenize the input and move to device
inputs = tokenizer(text, return_tensors="pt").to(device)

# Generate response with TextStreamer
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
_ = model.generate(
    **inputs,
    max_new_tokens=2048,
    temperature=0.7,
    top_p=0.95,
    top_k=64,
    streamer=streamer
)
Nếu nghi ngờ bị loét dạ dày tá tràng, bạn nên đến phòng nội khoa của bệnh viện để thăm khám.

Framework versions

  • PEFT 0.14.0
  • TRL: 0.19.0
  • Transformers: 4.52.4
  • Pytorch: 2.6.0+cu124
  • Datasets: 3.6.0
  • Tokenizers: 0.21.1

Citations

Cite TRL as:

@misc{vonwerra2022trl,
    title        = {{TRL: Transformer Reinforcement Learning}},
    author       = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
    year         = 2020,
    journal      = {GitHub repository},
    publisher    = {GitHub},
    howpublished = {\url{https://github.com/huggingface/trl}}
}
Downloads last month
384
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for danhtran2mind/Gemma-3-1B-Instruct-Vi-Medical-LoRA

Adapter
(112)
this model

Dataset used to train danhtran2mind/Gemma-3-1B-Instruct-Vi-Medical-LoRA

Spaces using danhtran2mind/Gemma-3-1B-Instruct-Vi-Medical-LoRA 8

Collection including danhtran2mind/Gemma-3-1B-Instruct-Vi-Medical-LoRA