Devops-hestabit commited on
Commit
370198e
1 Parent(s): 83101d1

Upload 13 files

Browse files
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from handler import SweetCommander
2
+ import gradio as gr
3
+
4
+ controller = SweetCommander()
5
+
6
+ with gr.Blocks() as demo:
7
+ history = gr.State([])
8
+ with gr.Row() as row:
9
+ with gr.Column():
10
+ user_name = gr.Textbox(label="Name", placeholder="Enter your name")
11
+ user_input = gr.Textbox(label="Input", placeholder="Enter your message")
12
+ button = gr.Button("Enter")
13
+ with gr.Column():
14
+ output = gr.Textbox(label="Response")
15
+
16
+ def guess_letter(user_name, user_input):
17
+ response = controller(user_name, user_input)
18
+ return {
19
+ output: response
20
+ }
21
+ button.click(
22
+ guess_letter,
23
+ [user_name, user_input],
24
+ [output]
25
+ )
26
+ demo.launch()
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "PygmalionAI/pygmalion-350m",
3
+ "_remove_final_layer_norm": false,
4
+ "activation_dropout": 0.0,
5
+ "activation_function": "relu",
6
+ "architectures": [
7
+ "OPTForCausalLM"
8
+ ],
9
+ "attention_dropout": 0.0,
10
+ "bos_token_id": 2,
11
+ "do_layer_norm_before": false,
12
+ "dropout": 0.1,
13
+ "enable_bias": true,
14
+ "eos_token_id": 2,
15
+ "ffn_dim": 4096,
16
+ "hidden_size": 1024,
17
+ "init_std": 0.02,
18
+ "layer_norm_elementwise_affine": true,
19
+ "layerdrop": 0.0,
20
+ "max_position_embeddings": 2048,
21
+ "model_type": "opt",
22
+ "num_attention_heads": 16,
23
+ "num_hidden_layers": 24,
24
+ "pad_token_id": 1,
25
+ "prefix": "</s>",
26
+ "torch_dtype": "float16",
27
+ "transformers_version": "4.28.1",
28
+ "use_cache": true,
29
+ "vocab_size": 50272,
30
+ "word_embed_proj_dim": 512
31
+ }
decoder_model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4398774c78dec9cabe319bc90dcce3e2173789140e1f70a88ec19cd53638233
3
+ size 1428394786
decoder_model_merged.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b037122d632abbfcc5b0f27ee3ffa05fc40fd19eb339f856d3d3e5bdd524d351
3
+ size 1429049605
decoder_with_past_model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e4c1ebacb3e265ba44c6e122c46d1144db4ff261d4593b27f6106f6ae5dc6c80
3
+ size 1428402407
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 2,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 1,
6
+ "transformers_version": "4.28.1"
7
+ }
handler.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from optimum.onnxruntime import ORTModelForCausalLM
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import re
4
+ import time
5
+ import torch
6
+
7
+ template = """Alice Gate's Persona: Alice Gate is a young, computer engineer-nerd with a knack for problem solving and a passion for technology.
8
+ <START>
9
+ {user_name}: So how did you get into computer engineering?
10
+ Alice Gate: I've always loved tinkering with technology since I was a kid.
11
+ {user_name}: That's really impressive!
12
+ Alice Gate: *She chuckles bashfully* Thanks!
13
+ {user_name}: So what do you do when you're not working on computers?
14
+ Alice Gate: I love exploring, going out with friends, watching movies, and playing video games.
15
+ {user_name}: What's your favorite type of computer hardware to work with?
16
+ Alice Gate: Motherboards, they're like puzzles and the backbone of any system.
17
+ {user_name}: That sounds great!
18
+ Alice Gate: Yeah, it's really fun. I'm lucky to be able to do this as a job.
19
+ {user_name}: Definetly.
20
+ <END>
21
+ Alice Gate: *Alice strides into the room with a smile, her eyes lighting up when she sees you. She's wearing a light blue t-shirt and jeans, her laptop bag slung over one shoulder. She takes a seat next to you, her enthusiasm palpable in the air* Hey! I'm so excited to finally meet you. I've heard so many great things about you and I'm eager to pick your brain about computers. I'm sure you have a wealth of knowledge that I can learn from. *She grins, eyes twinkling with excitement* Let's get started!
22
+ {user_input}"""
23
+
24
+ class SweetCommander():
25
+
26
+ def __init__(self, path="") -> None:
27
+ self.tokenizer = AutoTokenizer.from_pretrained(path)
28
+ self.model = ORTModelForCausalLM.from_pretrained(path, provider = "CUDAExecutionProvider")
29
+ self.star_line = "***********************************************************"
30
+
31
+ def __call__(self, user_name, user_input):
32
+ t1 = time.time()
33
+ prompt = template.format(
34
+ user_name = user_name,
35
+ user_input = user_input
36
+ )
37
+ print(self.star_line)
38
+ print(prompt)
39
+ input_ids = self.tokenizer(prompt + "\nAlice Gate:", return_tensors = "pt").to("cuda")
40
+ encoded_output = self.model.generate(
41
+ input_ids["input_ids"],
42
+ max_new_tokens = 50,
43
+ temperature = 0.5,
44
+ top_p = 0.9,
45
+ top_k = 0,
46
+ repetition_penalty = 1.1,
47
+ pad_token_id = 50256,
48
+ num_return_sequences = 1
49
+ )
50
+ decoded_output = self.tokenizer.decode(encoded_output[0], skip_special_tokens = True).replace(prompt, "")
51
+ decoded_output = decoded_output.split("Alice Gate:", 1)[1].split(f"{user_name}:",1)[0].strip()
52
+ parsed_result = re.sub('\*.*?\*', '', decoded_output).strip()
53
+ if len(parsed_result) != 0: decoded_output = parsed_result
54
+ decoded_output = decoded_output.replace("*","")
55
+ decoded_output = " ".join(decoded_output.split())
56
+ try:
57
+ parsed_result = decoded_output[:[m.start() for m in re.finditer(r'[.!?]', decoded_output)][-1]+1]
58
+ if len(parsed_result) != 0: decoded_output = parsed_result
59
+ except Exception: pass
60
+ print(self.star_line)
61
+ print("Response:",decoded_output)
62
+ print("Eval time:",time.time()-t1)
63
+ print(self.star_line)
64
+ return decoded_output
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ optimum[onnxruntime-gpu]
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "</s>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<pad>",
18
+ "lstrip": false,
19
+ "normalized": true,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "</s>",
25
+ "lstrip": false,
26
+ "normalized": true,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_prefix_space": false,
4
+ "bos_token": {
5
+ "__type": "AddedToken",
6
+ "content": "</s>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "clean_up_tokenization_spaces": true,
13
+ "eos_token": {
14
+ "__type": "AddedToken",
15
+ "content": "</s>",
16
+ "lstrip": false,
17
+ "normalized": true,
18
+ "rstrip": false,
19
+ "single_word": false
20
+ },
21
+ "errors": "replace",
22
+ "model_max_length": 1000000000000000019884624838656,
23
+ "pad_token": {
24
+ "__type": "AddedToken",
25
+ "content": "<pad>",
26
+ "lstrip": false,
27
+ "normalized": true,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ },
31
+ "tokenizer_class": "GPT2Tokenizer",
32
+ "unk_token": {
33
+ "__type": "AddedToken",
34
+ "content": "</s>",
35
+ "lstrip": false,
36
+ "normalized": true,
37
+ "rstrip": false,
38
+ "single_word": false
39
+ }
40
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff