Siva1995 commited on
Commit
84fe83e
·
1 Parent(s): 9907b05

Update proton_code_llama_fine_tuning_using_qlora_inferencing.py

Browse files
proton_code_llama_fine_tuning_using_qlora_inferencing.py CHANGED
@@ -7,13 +7,13 @@ Original file is located at
7
  https://colab.research.google.com/drive/1snQ0jgdbZDXNuVpvryjfENfCjk8K2SE2
8
  """
9
 
10
- !pip install -q -U trl transformers accelerate git+https://github.com/huggingface/peft.git
11
- !pip install -q datasets bitsandbytes einops wandb
12
- !pip install peft
13
- !pip install --upgrade gradio
14
- !pip install sentence_transformers
15
- !pip install accelerate
16
- !pip install bitsandbytes
17
 
18
  import pandas as pd
19
  import torch
@@ -21,11 +21,14 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
21
  from peft import PeftModel, PeftConfig
22
  from sentence_transformers.util import semantic_search
23
  import requests
 
24
 
25
  model_id = "sentence-transformers/all-MiniLM-L6-v2"
26
  hf_token = "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"
27
 
28
- data = pd.read_excel('/content/sample_data/Proton Gen AI.xlsx')
 
 
29
 
30
  text_col = []
31
 
@@ -99,45 +102,45 @@ def getExamples(question):
99
  return r
100
 
101
  def prepare_prompt(query):
102
- prompt_prep = ''.join([priming_text,getExamples(query),'\n',decorator,'\n','Similar to the above examples, generate only one Proton UI for the following description:',query])
103
- return prompt_prep
104
 
105
  def generate(query):
106
- prompt_prep = prepare_prompt(query)
107
- encodings = model_tokenizer(prompt_prep, return_tensors = 'pt').to(device)
108
-
109
- with torch.inference_mode():
110
- outputs = model.generate(input_ids=encodings.input_ids,
111
  attention_mask = encodings.attention_mask,
112
  generation_config = generation_config,
113
  max_new_tokens=1000,do_sample=True)
114
-
115
- outputs = model_tokenizer.decode(outputs[0],skip_special_tokens=True,best_of=1)
116
-
117
- return outputs[outputs.find(query): ]#outputs.find('Explanation')
118
-
119
- output = generate('Create a choice type of Proton UI for choosing vegetables')
120
- print(output)
121
-
122
- import gradio as gr
123
- with gr.Blocks() as demo:
124
- gr.Markdown("****This application is built on fine-tuned on specific data on codellama 7b on 4 bit fine tuned****")
125
- gr.Markdown("**No Paid service has been leveraged**")
126
- gr.Markdown("**Type your Query Run to see the output**")
127
- with gr.Row():
128
- out = gr.Textbox()
129
- with gr.Row():
130
- inp = gr.Textbox(placeholder="Type your Question")
131
- btn = gr.Button("Run")
132
- btn.click(fn=output, inputs=inp, outputs=out)
133
- demo.launch(auth=("user", "password"),share=True)
134
-
135
- import random
136
- import gradio as gr
137
-
138
- def alternatingly_agree(message, history):
139
- output = generate(str(message))
140
- return output
141
-
142
- gr.ChatInterface(alternatingly_agree).launch()
143
 
 
7
  https://colab.research.google.com/drive/1snQ0jgdbZDXNuVpvryjfENfCjk8K2SE2
8
  """
9
 
10
+ # !pip install -q -U trl transformers accelerate git+https://github.com/huggingface/peft.git
11
+ # !pip install -q datasets bitsandbytes einops wandb
12
+ # !pip install peft
13
+ # !pip install --upgrade gradio
14
+ # !pip install sentence_transformers
15
+ # !pip install accelerate
16
+ # !pip install bitsandbytes
17
 
18
  import pandas as pd
19
  import torch
 
21
  from peft import PeftModel, PeftConfig
22
  from sentence_transformers.util import semantic_search
23
  import requests
24
+ from datasets import load_dataset
25
 
26
  model_id = "sentence-transformers/all-MiniLM-L6-v2"
27
  hf_token = "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"
28
 
29
+ # data = pd.read_excel('/content/sample_data/Proton Gen AI.xlsx')
30
+
31
+ dataset = load_dataset("Siva1995/Proton_GENAI")
32
 
33
  text_col = []
34
 
 
102
  return r
103
 
104
  def prepare_prompt(query):
105
+ prompt_prep = ''.join([priming_text,getExamples(query),'\n',decorator,'\n','Similar to the above examples, generate only one Proton UI for the following description:',query])
106
+ return prompt_prep
107
 
108
  def generate(query):
109
+ prompt_prep = prepare_prompt(query)
110
+ encodings = model_tokenizer(prompt_prep, return_tensors = 'pt').to(device)
111
+
112
+ with torch.inference_mode():
113
+ outputs = model.generate(input_ids=encodings.input_ids,
114
  attention_mask = encodings.attention_mask,
115
  generation_config = generation_config,
116
  max_new_tokens=1000,do_sample=True)
117
+
118
+ outputs = model_tokenizer.decode(outputs[0],skip_special_tokens=True,best_of=1)
119
+
120
+ return outputs[outputs.find(query): ]#outputs.find('Explanation')
121
+
122
+ # output = generate('Create a choice type of Proton UI for choosing vegetables')
123
+ # print(output)
124
+
125
+ # import gradio as gr
126
+ # with gr.Blocks() as demo:
127
+ # gr.Markdown("****This application is built on fine-tuned on specific data on codellama 7b on 4 bit fine tuned****")
128
+ # gr.Markdown("**No Paid service has been leveraged**")
129
+ # gr.Markdown("**Type your Query Run to see the output**")
130
+ # with gr.Row():
131
+ # out = gr.Textbox()
132
+ # with gr.Row():
133
+ # inp = gr.Textbox(placeholder="Type your Question")
134
+ # btn = gr.Button("Run")
135
+ # btn.click(fn=output, inputs=inp, outputs=out)
136
+ # demo.launch(auth=("user", "password"),share=True)
137
+
138
+ # import random
139
+ # import gradio as gr
140
+
141
+ # def alternatingly_agree(message, history):
142
+ # output = generate(str(message))
143
+ # return output
144
+
145
+ # gr.ChatInterface(alternatingly_agree).launch()
146