Views
No views yet
unsloth/Llama-3.2-3B-Instruct1!pip install -q unsloth
2
3# Install latest Unsloth
4!pip install -q --force-reinstall --no-cache-dir git+https://github.com/unslothai/unsloth.git
5
6!pip install --upgrade torchao>=0.16.0
7
8%%capture
9import os
10
11if "COLAB_" not in "".join(os.environ.keys()):
12 !pip install unsloth
13else:
14 !pip install --no-deps bitsandbytes accelerate xformers==0.0.29.post3 peft trl==0.15.2 triton cut_cross_entropy unsloth_zoo
15 !pip install sentencepiece protobuf "datasets>=3.4.1" huggingface_hub hf_transfer
16 !pip install --no-deps unsloth
17
18from unsloth import FastLanguageModel
19import torch
20
21max_seq_length = 2048
22dtype = None
23load_in_4bit = True
24
25model, tokenizer = FastLanguageModel.from_pretrained(
26 model_name = "unsloth/Llama-3.2-3B-Instruct",
27 max_seq_length = max_seq_length,
28 dtype = dtype,
29 load_in_4bit = load_in_4bit,
30)
31
32model.load_adapter("YOUR_LORA_PATH", "default")
33
34model.to("cuda")
35
36model.enable_adapters()
37
38messages = [
39 {
40 "role": "system",
41 "content": "You are a reflective assistant who is master in Bhagavad Gita for chapter 8."
42 },
43 {
44 "role": "user",
45 "content": "What does Krishna call Karma in this chapter?"
46 }
47]
48
49FastLanguageModel.for_inference(model)
50
51inputs = tokenizer.apply_chat_template(
52 messages,
53 tokenize = True,
54 add_generation_prompt = True,
55 return_tensors = "pt",
56).to("cuda")
57
58from transformers import TextStreamer
59
60text_streamer = TextStreamer(tokenizer)
61
62_ = model.generate(
63 input_ids = inputs,
64 streamer = text_streamer,
65 max_new_tokens = 2048,
66 do_sample = True,
67 temperature = 0.3,
68 top_p = 0.9
69)