Views
No views yet
1%%capture
2# Installs Unsloth, Xformers (Flash Attention) and all other packages!
3!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
4!pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes
5
6from unsloth import FastLanguageModel
7import torch
8
9# Define the dtype you want to use
10dtype = torch.float16 # Example: using float16 for lower memory usage
11
12# Set load_in_4bit to True or False depending on your requirements
13load_in_4bit = True # Or False if you don't want to load in 4-bit
14
15# Verify the model name is correct and exists on Hugging Face Model Hub
16model_name = "skkjodhpur/Meta-Llama-3.1-8B-Unsloth-2x-faster-finetuning-GGUF-by-skk"
17# Check if the model exists, if not, you may need to adjust the model name
18!curl -s https://huggingface.co/{model_name}/resolve/main/config.json | jq .
19
20model, tokenizer = FastLanguageModel.from_pretrained(
21 model_name = model_name,
22 max_seq_length = 2048,
23 dtype = dtype,
24 load_in_4bit = load_in_4bit,
25)
26FastLanguageModel.for_inference(model) # Enable native 2x faster inference
27
28# prompt = You MUST copy from above!
29
30prompt = """Below is an tools that describes a task, paired with an query that provides further context. Write a answers that appropriately completes the request.
31
32### tools:
33{}
34
35### query:
36{}
37
38### answers:
39{}"""
40
41inputs = tokenizer(
42[
43 prompt.format(
44 '[{"name": "live_giveaways_by_type", "description": "Retrieve live giveaways from the GamerPower API based on the specified type.", "parameters": {"type": {"description": "The type of giveaways to retrieve (e.g., game, loot, beta).", "type": "str", "default": "game"}}}]', # instruction
45 "Where can I find live giveaways for beta access and games?", # input
46 "", # output - leave this blank for generation!
47 )
48], return_tensors = "pt").to("cuda")
49
50from transformers import TextStreamer
51text_streamer = TextStreamer(tokenizer)
52_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128)