Update README.md
Browse files
README.md
CHANGED
@@ -3,4 +3,60 @@ license: mit
|
|
3 |
pipeline_tag: text-generation
|
4 |
metrics:
|
5 |
- accuracy
|
6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
pipeline_tag: text-generation
|
4 |
metrics:
|
5 |
- accuracy
|
6 |
+
---
|
7 |
+
|
8 |
+
# code
|
9 |
+
|
10 |
+
|
11 |
+
from unsloth import FastLanguageModel
|
12 |
+
import torch
|
13 |
+
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
|
14 |
+
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
|
15 |
+
load_in_4bit = True
|
16 |
+
|
17 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
18 |
+
model_name = "rohansb10/python_code_gen_using_llama-3.1_8b", # YOUR MODEL YOU USED FOR TRAINING
|
19 |
+
max_seq_length = max_seq_length,
|
20 |
+
dtype = dtype,
|
21 |
+
load_in_4bit = load_in_4bit,
|
22 |
+
)
|
23 |
+
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
24 |
+
|
25 |
+
# alpaca_prompt = You MUST copy from above!
|
26 |
+
|
27 |
+
alpaca_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.
|
28 |
+
|
29 |
+
### Instruction:
|
30 |
+
{}
|
31 |
+
|
32 |
+
### Input:
|
33 |
+
{}
|
34 |
+
|
35 |
+
### Response:
|
36 |
+
{}"""
|
37 |
+
|
38 |
+
EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN
|
39 |
+
def formatting_prompts_func(examples):
|
40 |
+
instructions = examples["instruction"]
|
41 |
+
inputs = examples["input"]
|
42 |
+
outputs = examples["output"]
|
43 |
+
texts = []
|
44 |
+
for instruction, input, output in zip(instructions, inputs, outputs):
|
45 |
+
# Must add EOS_TOKEN, otherwise your generation will go on forever!
|
46 |
+
text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
|
47 |
+
texts.append(text)
|
48 |
+
return { "text" : texts, }
|
49 |
+
|
50 |
+
inputs = tokenizer(
|
51 |
+
[
|
52 |
+
alpaca_prompt.format(
|
53 |
+
"Develop a function in Python that prints out the Pascal's triangle for a given number of rows.", # instruction
|
54 |
+
"", # input
|
55 |
+
"", # output - leave this blank for generation!
|
56 |
+
)
|
57 |
+
], return_tensors = "pt")
|
58 |
+
|
59 |
+
from transformers import TextStreamer
|
60 |
+
text_streamer = TextStreamer(tokenizer)
|
61 |
+
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128)
|
62 |
+
|