Views
No views yet
1# Installs Unsloth, Xformers (Flash Attention) and all other packages!
2!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
3!pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes1from unsloth import FastLanguageModel
2model, tokenizer = FastLanguageModel.from_pretrained(
3 model_name = "MouezYazidi/PyMistral-7b-Genius_LoRA",
4 max_seq_length = 2048,
5 dtype = None,
6 load_in_4bit = True,
7)
8FastLanguageModel.for_inference(model) # Enable native 2x faster inference
9
10alpaca_prompt = """Below is an instruction describing a task, along with an input providing additional context. Your task is to generate a clear, concise, and accurate Python code response that fulfills the given request.
11
12### Instruction:
13{}
14
15### Input:
16{}
17
18### Response:
19{}"""
20
21inputs = tokenizer(
22[
23 alpaca_prompt.format(
24 "", # instruction
25 """Write a Python function that generates and prints the first n rows of Pascal's Triangle. Ensure the function accepts a positive integer n as input and produces the rows in a well-formatted structure (e.g., lists within a list or as strings). If you use any external libraries, make sure to explicitly import them in your code.""", # input
26 "", # output - leave this blank for generation!
27 )
28], return_tensors = "pt").to("cuda")
29
30from transformers import TextStreamer
31text_streamer = TextStreamer(tokenizer)
32_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 512)1
2The Outout is:
3
4<s> Below is an instruction describing a task, along with an input providing additional context. Your task is to generate a clear, concise, and accurate Python code response that fulfills the given request.
5
6### Instruction:
7
8
9### Input:
10Write a Python function that generates and prints the first n rows of Pascal's Triangle. Ensure the function accepts a positive integer n as input and produces the rows in a well-formatted structure (e.g., lists within a list or as strings). If you use any external libraries, make sure to explicitly import them in your code.
11
12### Response:
13def pascal_triangle(n):
14 triangle = [[1]]
15 for i in range(1, n):
16 row = [1]
17 for j in range(1, i):
18 row.append(triangle[i-1][j-1] + triangle[i-1][j])
19 row.append(1)
20 triangle.append(row)
21 return triangle
22
23print(pascal_triangle(5))</s>
24