Trickshotblaster commited on
Commit
2769ffd
·
1 Parent(s): 4aec55c
Files changed (3) hide show
  1. __pycache__/gpt.cpython-310.pyc +0 -0
  2. app.py +2 -10
  3. gpt.py +23 -4
__pycache__/gpt.cpython-310.pyc CHANGED
Binary files a/__pycache__/gpt.cpython-310.pyc and b/__pycache__/gpt.cpython-310.pyc differ
 
app.py CHANGED
@@ -1,22 +1,14 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  import gpt
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
 
10
- def respond(
11
- message
12
- ):
13
- return gpt.get_response(message)
14
 
15
 
16
  """
17
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
18
  """
19
- demo = gr.Interface(fn=respond, inputs="textbox", outputs="textbox")
20
 
21
 
22
  if __name__ == "__main__":
 
1
  import gradio as gr
 
2
  import gpt
 
 
 
 
3
 
4
 
5
+ print(gpt.get_response("test"))
 
 
 
6
 
7
 
8
  """
9
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
10
  """
11
+ demo = gr.Interface(fn=gpt.get_response, inputs="textbox", outputs="textbox")
12
 
13
 
14
  if __name__ == "__main__":
gpt.py CHANGED
@@ -103,17 +103,35 @@ class GPT(nn.Module):
103
  return logits, loss
104
 
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  block_size = 512
107
  n_layers = 12
108
  n_heads = 12
109
  d_model = 768
110
 
111
- torch.set_float32_matmul_precision('high')
112
 
113
  my_GPT = GPT(enc.n_vocab, block_size, n_layers, n_heads, d_model, dropout=0.1) #enc.n_vocab
114
  my_GPT = my_GPT.to(device)
115
- my_GPT = torch.compile(my_GPT)
116
- my_GPT.load_state_dict(torch.load('latest_model_finetune.pth', map_location=torch.device('cpu')))
 
117
  my_GPT.eval()
118
 
119
  eot = enc._special_tokens['<|endoftext|>']
@@ -153,5 +171,6 @@ def get_response(in_text):
153
  break
154
  input_tokens.append(result)
155
  output_tokens.append(result)
 
156
 
157
- return enc.decode(output_tokens)
 
103
  return logits, loss
104
 
105
 
106
+ def load_compiled_model_state_dict(model, state_dict_path):
107
+ # Load the state dict
108
+ state_dict = torch.load(state_dict_path, map_location=torch.device('cpu'))
109
+
110
+ # Create a new state dict without the '_orig_mod.' prefix
111
+ new_state_dict = {}
112
+ for key, value in state_dict.items():
113
+ if key.startswith('_orig_mod.'):
114
+ new_key = key[len('_orig_mod.'):]
115
+ new_state_dict[new_key] = value
116
+ else:
117
+ new_state_dict[key] = value
118
+
119
+ # Load the new state dict into the model
120
+ model.load_state_dict(new_state_dict)
121
+ return model
122
+
123
  block_size = 512
124
  n_layers = 12
125
  n_heads = 12
126
  d_model = 768
127
 
128
+ torch.set_float32_matmul_precision('medium')
129
 
130
  my_GPT = GPT(enc.n_vocab, block_size, n_layers, n_heads, d_model, dropout=0.1) #enc.n_vocab
131
  my_GPT = my_GPT.to(device)
132
+ #my_GPT = torch.compile(my_GPT, mode='reduce-overhead')
133
+ my_GPT = load_compiled_model_state_dict(my_GPT, 'latest_model_finetune.pth')
134
+ #my_GPT.load_state_dict(torch.load('latest_model_finetune.pth', map_location=torch.device('cpu')))
135
  my_GPT.eval()
136
 
137
  eot = enc._special_tokens['<|endoftext|>']
 
171
  break
172
  input_tokens.append(result)
173
  output_tokens.append(result)
174
+ yield enc.decode(output_tokens)
175
 
176
+ yield enc.decode(output_tokens)