# SFT — Qwen3-4B QLoRA on UltraChat 200K (4-bit NF4 base + bf16 LoRA adapters; 7.9 GiB peak at batch 1, fits a 24 GB GPU). # Launch: PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True python scripts/training/sft.py # or: PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True torchrun --nproc_per_node=8 scripts/training/sft.py # --- Model --- model_name_or_path: Qwen/Qwen3-4B-Instruct-2507 # --- 4-bit Quantization (BitsAndBytes) --- load_in_4bit: true use_bnb_nested_quant: true # --- Dataset --- dataset: - HuggingFaceH4/ultrachat_200k@train_sft conversation_field: messages assistant_message_template: "<|im_start|>assistant\n" test_size: 0.01 # --- QLoRA (LoRA on quantized model) --- use_peft: true lora_r: 64 lora_alpha: 128 lora_target_modules: - q_proj - k_proj - v_proj - o_proj - gate_proj - up_proj - down_proj # --- Training --- per_device_train_batch_size: 1 # batch 4 packs four rows into one 16k row and peaks at 33 GB per_device_eval_batch_size: 1 num_train_epochs: 1.0 gradient_accumulation_steps: 16 gradient_checkpointing_kwargs: use_reentrant: false learning_rate: 1.0e-04 lr_scheduler_type: cosine warmup_steps: 32 # --- Sequence Length & Packing --- max_length: 4096 packing: true # --- Output --- output_dir: checkpoints/sft-qwen3-4b-ultrachat-qlora eval_strategy: steps eval_steps: 500 save_total_limit: 3 save_only_model: true # --- Logging --- logging_steps: 1 logging_first_step: true report_to: wandb # --- Data --- dataloader_num_workers: 4