Trickshotblaster commited on
Commit
a4e819a
·
1 Parent(s): 2769ffd

to the moon bois

Browse files
Files changed (3) hide show
  1. __pycache__/gpt.cpython-310.pyc +0 -0
  2. app.py +9 -5
  3. gpt.py +2 -16
__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,14 +1,18 @@
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__":
 
1
  import gradio as gr
2
  import gpt
3
 
 
 
 
 
4
  """
5
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
6
  """
7
+ demo = gr.Interface(fn=gpt.get_response, inputs=["textbox",
8
+ gr.Slider(0, 100, value=50, step=1),
9
+ gr.Slider(0.1, 2.0, value=1.0),
10
+ ], outputs="textbox", title="Mike Chat", article="""Mike is the greatest AI ever created. It was trained for about 8 hrs on my pc using fineweb-edu and open orca datasets. While it hallucinates a lot, it seems to be about on par with other lms of its size (about 160M params). Model details:
11
+ block_size: 512
12
+ n_layers: 12
13
+ n_heads: 12
14
+ d_model: 768
15
+ (Same as gpt-2 but without weight tying)""")
16
 
17
 
18
  if __name__ == "__main__":
gpt.py CHANGED
@@ -136,35 +136,21 @@ my_GPT.eval()
136
 
137
  eot = enc._special_tokens['<|endoftext|>']
138
 
139
- def get_response(in_text):
140
  prompt = "USER: " + in_text + "\nASSISTANT: "
141
  input_tokens = enc.encode(prompt)
142
  output_tokens = enc.encode(prompt)
143
- top_k = 50
144
- top_p = 0
145
  for x in range(block_size):
146
  if len(input_tokens) > block_size:
147
  input_tokens = input_tokens[1:]
148
  context_tensor = torch.tensor(input_tokens).view(1, -1).to(device)
149
 
150
  logits, loss = my_GPT(context_tensor)
151
- logits = logits[:, -1, :]
152
  if top_k > 0:
153
  # Remove all tokens with a probability less than the last token of the top-k
154
  indices_to_remove = logits < torch.topk(logits, top_k, dim=1)[0][..., -1, None]
155
  logits[indices_to_remove] = float("-inf")
156
- if top_p > 0.0:
157
- sorted_logits, sorted_indices = torch.sort(logits, descending=True)
158
- cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)
159
-
160
- # Remove tokens with cumulative probability above the threshold
161
- sorted_indices_to_remove = cumulative_probs > top_p
162
- # Shift the indices to the right to keep also the first token above the threshold
163
- sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
164
- sorted_indices_to_remove[..., 0] = 0
165
-
166
- indices_to_remove = sorted_indices[sorted_indices_to_remove]
167
- logits[indices_to_remove] = float("-inf")
168
  probs = F.softmax(logits, dim=-1)
169
  result = torch.multinomial(probs, num_samples=1).item()
170
  if result == eot:
 
136
 
137
  eot = enc._special_tokens['<|endoftext|>']
138
 
139
+ def get_response(in_text, top_k=50, temperature=1):
140
  prompt = "USER: " + in_text + "\nASSISTANT: "
141
  input_tokens = enc.encode(prompt)
142
  output_tokens = enc.encode(prompt)
 
 
143
  for x in range(block_size):
144
  if len(input_tokens) > block_size:
145
  input_tokens = input_tokens[1:]
146
  context_tensor = torch.tensor(input_tokens).view(1, -1).to(device)
147
 
148
  logits, loss = my_GPT(context_tensor)
149
+ logits = logits[:, -1, :] / temperature
150
  if top_k > 0:
151
  # Remove all tokens with a probability less than the last token of the top-k
152
  indices_to_remove = logits < torch.topk(logits, top_k, dim=1)[0][..., -1, None]
153
  logits[indices_to_remove] = float("-inf")
 
 
 
 
 
 
 
 
 
 
 
 
154
  probs = F.softmax(logits, dim=-1)
155
  result = torch.multinomial(probs, num_samples=1).item()
156
  if result == eot: