Text Generation
Transformers
Safetensors
Thai
qwen3
medical
rag
citation
question-answering
thai
conversational
text-generation-inference
Instructions to use ThaiLLM/ThaiLLM-8B-SFT-IQ with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ThaiLLM/ThaiLLM-8B-SFT-IQ with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ThaiLLM/ThaiLLM-8B-SFT-IQ") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ThaiLLM/ThaiLLM-8B-SFT-IQ") model = AutoModelForCausalLM.from_pretrained("ThaiLLM/ThaiLLM-8B-SFT-IQ", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ThaiLLM/ThaiLLM-8B-SFT-IQ with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ThaiLLM/ThaiLLM-8B-SFT-IQ" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ThaiLLM/ThaiLLM-8B-SFT-IQ", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ThaiLLM/ThaiLLM-8B-SFT-IQ
- SGLang
How to use ThaiLLM/ThaiLLM-8B-SFT-IQ with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ThaiLLM/ThaiLLM-8B-SFT-IQ" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ThaiLLM/ThaiLLM-8B-SFT-IQ", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ThaiLLM/ThaiLLM-8B-SFT-IQ" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ThaiLLM/ThaiLLM-8B-SFT-IQ", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ThaiLLM/ThaiLLM-8B-SFT-IQ with Docker Model Runner:
docker model run hf.co/ThaiLLM/ThaiLLM-8B-SFT-IQ
Update training script for ThaiLLM-8B-SFT-IQ
#2
by TONKKrongyuth - opened
README.md
CHANGED
|
@@ -75,6 +75,63 @@ The model is fine-tuned from **ThaiLLM-8B-SFT** using supervised fine-tuning (SF
|
|
| 75 |
| Batch size | 8 |
|
| 76 |
|
| 77 |
Training data consists of Thai medical question–answer pairs with context grounding and citation supervision.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
---
|
| 80 |
|
|
|
|
| 75 |
| Batch size | 8 |
|
| 76 |
|
| 77 |
Training data consists of Thai medical question–answer pairs with context grounding and citation supervision.
|
| 78 |
+
- **Training Script**
|
| 79 |
+
- ```bash
|
| 80 |
+
model_base, tokenizer = FastLanguageModel.from_pretrained(
|
| 81 |
+
base_model,
|
| 82 |
+
max_seq_length=max_seq,
|
| 83 |
+
load_in_4bit=True,
|
| 84 |
+
load_in_8bit=False,
|
| 85 |
+
full_finetuning=False,
|
| 86 |
+
device_map = "balanced",
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
model = FastLanguageModel.get_peft_model(
|
| 90 |
+
model_base,
|
| 91 |
+
r=r,
|
| 92 |
+
lora_alpha=r, # Set lora_alpha = r
|
| 93 |
+
lora_dropout=0,
|
| 94 |
+
bias="none",
|
| 95 |
+
target_modules=[
|
| 96 |
+
"q_proj", "k_proj", "v_proj", "o_proj",
|
| 97 |
+
"gate_proj", "up_proj", "down_proj"
|
| 98 |
+
],
|
| 99 |
+
use_gradient_checkpointing="unsloth",
|
| 100 |
+
random_state=seed,
|
| 101 |
+
use_rslora=False,
|
| 102 |
+
loftq_config=None,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
trainer = SFTTrainer(
|
| 106 |
+
model=model,
|
| 107 |
+
tokenizer=tokenizer,
|
| 108 |
+
train_dataset=train_ds,
|
| 109 |
+
dataset_num_proc=4,
|
| 110 |
+
args=SFTConfig(
|
| 111 |
+
dataset_text_field="text",
|
| 112 |
+
per_device_train_batch_size=2,
|
| 113 |
+
gradient_accumulation_steps=8,
|
| 114 |
+
gradient_checkpointing = True,
|
| 115 |
+
warmup_ratio=0.1,
|
| 116 |
+
warmup_steps=5,
|
| 117 |
+
# max_steps = 1000, # If max_steps is set → ignore num_train_epochs
|
| 118 |
+
num_train_epochs=3, # Epoch ..
|
| 119 |
+
learning_rate=args.learning_rate,
|
| 120 |
+
logging_steps=1,
|
| 121 |
+
optim="adamw_8bit",
|
| 122 |
+
weight_decay=0.01,
|
| 123 |
+
lr_scheduler_type="cosine",
|
| 124 |
+
fp16=not torch.cuda.is_bf16_supported(),
|
| 125 |
+
bf16=torch.cuda.is_bf16_supported(),
|
| 126 |
+
seed=args.seed,
|
| 127 |
+
report_to=["tensorboard"],
|
| 128 |
+
output_dir=f"{paths['log_path']}",
|
| 129 |
+
logging_dir=f"{paths['log_path']}",
|
| 130 |
+
),
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
trainer.train()
|
| 134 |
+
```
|
| 135 |
|
| 136 |
---
|
| 137 |
|