Views
No views yet
This model does not include a retriever and must be used with externally supplied medical documents.
| Model | Response (BLEU) | Citations (Jaccard) |
|---|---|---|
| ThaiLLM-30B | 0.406 | 0.1786 |
| ThaiLLM-8B-SFT-IQ (Medical) | 0.4331 | 0.5458 |
| Hyperparameter | Value |
|---|---|
| Learning rate | 2e-4 |
| LoRA rank | 16 |
| LoRA alpha | 16 |
| Sequence length | 4096 |
| Epochs | 3 |
| Batch size | 4 |
1llamafactory-cli train \
2 --stage sft \
3 --do_train True \
4 --model_name_or_path ${MODEL_PATH} \
5 --preprocessing_num_workers 16 \
6 --deepspeed ./examples/deepspeed/ds_z2_config.json \
7 --finetuning_type lora \
8 --template qwen3 \
9 --flash_attn auto \
10 --dataset thaillm-SFT \
11 --cutoff_len 4096 \
12 --learning_rate 2e-4 \
13 --num_train_epochs 3.0 \
14 --max_samples 100000 \
15 --per_device_train_batch_size 1 \
16 --gradient_accumulation_steps 4 \
17 --gradient_checkpointing True \
18 --gradient_checkpointing_kwargs '{"use_reentrant":false}' \
19 --lr_scheduler_type cosine \
20 --max_grad_norm 1.0 \
21 --logging_steps 5 \
22 --save_steps 100 \
23 --warmup_steps 0 \
24 --packing False \
25 --enable_thinking True \
26 --report_to tensorboard \
27 --quantization_bit 4 \
28 --output_dir "./checkpoints/ThaiLLM-30B-SFT-IQ" \
29 --overwrite_output_dir True \
30 --bf16 True \
31 --plot_loss True \
32 --trust_remote_code True \
33 --include_num_input_tokens_seen True \
34 --optim adamw_8bit \
35 --lora_rank 16 \
36 --lora_alpha 16 \
37 --upcast_layernorm True \
38 --ddp_timeout 180000000 \
39 --lora_dropout 0 \
40 --lora_target all \
41 --freeze_vision_tower True \
42 --freeze_multi_modal_projector True \
43 --use_unsloth False \
44 --seed 12341import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_name = "ThaiLLM-30B-SFT-IQ"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 device_map="auto",
10 torch_dtype=torch.bfloat16,
11)
12
13system_prompt = """\
14Answer in JSON format with citations only.
15Use only the provided medical contexts to answer the question.
16Include the fact IDs that support your answer in the following format:
17{"answer": "<ANSWER_TEXT>", "citations": ["<FACT_ID1>", "<FACT_ID2>"]}
18
19If unknown, respond with:
20{"answer": "unknown", "citations": []}
21"""
22
23question = "การบาดเจ็บจากอุบัติเหตุที่ข้อต่อขากรรไกรสามารถทำให้อาการปวดร้าวไปที่ใดเมื่อเคี้ยวอาหาร?"
24
25facts = """\
26[1] การบาดเจ็บจากอุบัติเหตุที่ข้อต่อขากรรไกรสามารถทำให้ปวดร้าวไปที่หูเมื่อเคี้ยวอาหาร
27[2] ข้อต่อขากรรไกรอักเสบ (TMJ) สามารถทำให้ปวดบริเวณใกล้ติ่งหูและร้าวไปที่หูเมื่อเคี้ยวอาหาร
28"""
29
30prompt = f"""{system_prompt}
31
32Question:
33{question}
34
35Facts:
36{facts}
37"""
38
39inputs = tokenizer.apply_chat_template(
40 [{"role": "user", "content": prompt}],
41 add_generation_prompt=True,
42 return_tensors="pt",
43).to(model.device)
44
45with torch.inference_mode():
46 outputs = model.generate(
47 inputs,
48 max_new_tokens=256,
49 do_sample=False,
50 temperature=0.0,
51 )
52
53generated = outputs[0, inputs.shape[-1]:]
54print(tokenizer.decode(generated, skip_special_tokens=True))