Views
No views yet
1!pip install -U xformers --index-url https://download.pytorch.org/whl/cu121
2!pip install "unsloth[kaggle-new] @ git+https://github.com/unslothai/unsloth.git"
3
4import os
5os.environ["WANDB_DISABLED"] = "true"1load_in_4bit = True
2from peft import AutoPeftModelForCausalLM
3from transformers import AutoTokenizer
4import torch
5alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
6
7### Instruction:
8Generate Answer of the question asked :
9
10### Input:
11{}
12
13### Response:
14{}"""
15model = AutoPeftModelForCausalLM.from_pretrained(
16 "DisgustingOzil/qalaw-mistral-model", # YOUR MODEL YOU USED FOR TRAINING
17 load_in_4bit = load_in_4bit,
18 torch_dtype=torch.float16,
19 )
20tokenizer = AutoTokenizer.from_pretrained("DisgustingOzil/qalaw-mistral-model")
21
22from unsloth import FastLanguageModel
23FastLanguageModel.for_inference(model) # Enable native 2x faster inference
24
25inputs = tokenizer(
26[
27 alpaca_prompt.format(
28 "Explain Children and Young Persons Act", # input
29 "", # output - leave this blank for generation!
30 )
31], return_tensors = "pt").to("cuda")
32outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
33tokenizer.batch_decode(outputs)
34