Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4# Load base model
5base_model = AutoModelForCausalLM.from_pretrained(
6 "unsloth/Qwen3-1.7B-unsloth-bnb-4bit",
7 load_in_4bit=True,
8 device_map="auto"
9)
10
11# Load LoRA adapters
12model = PeftModel.from_pretrained(base_model, "path/to/lora")
13tokenizer = AutoTokenizer.from_pretrained("unsloth/Qwen3-1.7B-unsloth-bnb-4bit")
14
15# Generate
16messages = [{"role": "user", "content": "Your question here"}]
17input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
18outputs = model.generate(input_ids, max_new_tokens=256)
19print(tokenizer.decode(outputs[0], skip_special_tokens=True))1from unsloth import FastLanguageModel
2
3model, tokenizer = FastLanguageModel.from_pretrained(
4 model_name="path/to/lora",
5 max_seq_length=4096,
6 dtype=None,
7 load_in_4bit=True,
8)
9
10# For inference
11FastLanguageModel.for_inference(model)
12
13# Generate
14messages = [{"role": "user", "content": "Your question here"}]
15inputs = tokenizer.apply_chat_template(messages, tokenize=True, return_tensors="pt").to("cuda")
16outputs = model.generate(input_ids=inputs, max_new_tokens=256)
17print(tokenizer.decode(outputs[0], skip_special_tokens=True))1from unsloth import FastLanguageModel
2
3# Load model with LoRA
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name="path/to/lora",
6 max_seq_length=4096,
7 dtype=None,
8 load_in_4bit=True,
9)
10
11# Save merged 16-bit model
12model.save_pretrained_merged("merged_model", tokenizer, save_method="merged_16bit")
13
14# Or save as GGUF for llama.cpp/Ollama
15model.save_pretrained_gguf("model.gguf", tokenizer, quantization_method="q4_k_m")1@misc{qwen3_1.7b_alpaca_cleaned_lora,
2 author = {Farhan Syah},
3 title = {Qwen3-1.7B-alpaca-cleaned Fine-tuned with LoRA},
4 year = {2025},
5 note = {Fine-tuned using Unsloth: https://github.com/unslothai/unsloth},
6 howpublished = {\url{https://github.com/farhan-syah/unsloth-finetuning}}
7}