Views
No views yet
Qwen/Qwen3.5-4B (dense, 4B parameters, BF16)adapter_model.safetensors)1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5base_model_id = "Qwen/Qwen3.5-4B"
6adapter_id = "jamezoon/qwen3.5-4b-mcat-lora"
7
8tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
9model = AutoModelForCausalLM.from_pretrained(
10 base_model_id,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13 trust_remote_code=True,
14)
15model = PeftModel.from_pretrained(model, adapter_id)
16model.eval()
17
18messages = [
19 {
20 "role": "system",
21 "content": "You are a helpful tutor for students preparing for the MCAT. "
22 "Answer the following multiple choice question by thinking step by step, then give the answer."
23 },
24 {
25 "role": "user",
26 "content": (
27 "Passage: During a study of enzyme kinetics, researchers measured the rate of reaction "
28 "at varying substrate concentrations in the presence and absence of an inhibitor.\n\n"
29 "Question: Which of the following best describes competitive inhibition?\n"
30 "Options: A. Vmax decreases, Km unchanged "
31 "B. Vmax unchanged, Km increases "
32 "C. Both Vmax and Km decrease "
33 "D. Both Vmax and Km increase\n"
34 "Think step by step. Then respond in the format:\n"
35 "Explanation: ...\nAnswer: <one of A, B, C, D>"
36 ),
37 },
38]
39
40text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
41inputs = tokenizer(text, return_tensors="pt").to(model.device)
42with torch.no_grad():
43 output = model.generate(**inputs, max_new_tokens=512, do_sample=False)
44print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))| Hyperparameter | Value |
|---|---|
| Training steps | 546 |
| Epochs | 3 |
| Per-device batch size | 2 |
| Gradient accumulation | 4 (effective batch = 8) |
| Learning rate | 2e-5 |
| LR scheduler | Cosine |
| Warmup ratio | 0.03 |
| Max sequence length | 2048 tokens |
| Precision | BF16 |
| Optimizer | AdamW |
| Train loss (final) | 0.8092 |
| Eval loss (final) | 0.3952 |
| Parameter | Value |
|---|---|
| Rank (r) | 16 |
| Alpha (α) | 16 |
| Dropout | 0.0 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Trainable parameters | ~21.2M (0.47% of 4B) |
| Bias | none |
causal-conv1d, flash-linear-attention), GatedDeltaNet falls back to a PyTorch CPU implementation, resulting in significantly slower training (~16.8s/step vs ~6s/step for Qwen2.5-VL-7B).PYTORCH_JIT=0, TORCHDYNAMO_DISABLE=1 (nvrtc JIT unsupported on sm_121)attn_implementation="eager" (Flash Attention 3 incompatible with Blackwell)1@misc{oon2026mcat_qwen35,
2 title = {Qwen3.5-4B MCAT LoRA Adapter},
3 author = {Oon, James},
4 year = {2026},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/jamezoon/qwen3.5-4b-mcat-lora}
7}