LH-Tech-AI commited on
Commit
b215b7c
·
verified ·
1 Parent(s): b311fc4

Update chat.py

Browse files
Files changed (1) hide show
  1. chat.py +11 -4
chat.py CHANGED
@@ -2,11 +2,12 @@ import torch
2
  import tiktoken
3
  from model import GPTConfig, GPT
4
 
 
5
  ckpt_path = '/home/user/350m_SmaLLMPro_Final/SmaLLMPro_iter_1500.pt'
6
  device = 'cuda'
7
  enc = tiktoken.get_encoding("gpt2")
8
 
9
- print("Loading SmaLLMPro model checkpoint...")
10
  checkpoint = torch.load(ckpt_path, map_location=device)
11
  gptconf = GPTConfig(**checkpoint['model_args'])
12
  model = GPT(gptconf)
@@ -23,7 +24,7 @@ model.to(device)
23
  print(f"Model {ckpt_path} ready!\n")
24
 
25
  def run_chat():
26
- print("--- SmaLLMPro Chatbot (Type 'exit' to leave) ---")
27
 
28
  while True:
29
  user_input = input("You: ")
@@ -37,10 +38,16 @@ def run_chat():
37
  print("SmaLLMPro: ", end="", flush=True)
38
  with torch.no_grad():
39
  with torch.amp.autocast(device_type='cuda', dtype=torch.bfloat16):
40
- y = model.generate(x, max_New_tokens=256, temperature=0.4, top_k=25)
 
41
  full_text = enc.decode(y[0].tolist())
42
 
43
- response = full_text.split("Response:\n")[-1].split("<|endoftext|>")[0].strip()
 
 
 
 
 
44
  print(response + "\n")
45
 
46
  if __name__ == "__main__":
 
2
  import tiktoken
3
  from model import GPTConfig, GPT
4
 
5
+ # --- Config ---
6
  ckpt_path = '/home/user/350m_SmaLLMPro_Final/SmaLLMPro_iter_1500.pt'
7
  device = 'cuda'
8
  enc = tiktoken.get_encoding("gpt2")
9
 
10
+ print("Loading SmaLLMPro...")
11
  checkpoint = torch.load(ckpt_path, map_location=device)
12
  gptconf = GPTConfig(**checkpoint['model_args'])
13
  model = GPT(gptconf)
 
24
  print(f"Model {ckpt_path} ready!\n")
25
 
26
  def run_chat():
27
+ print("--- SmaLLMPro Chatbot (Type 'exit' to quit) ---")
28
 
29
  while True:
30
  user_input = input("You: ")
 
38
  print("SmaLLMPro: ", end="", flush=True)
39
  with torch.no_grad():
40
  with torch.amp.autocast(device_type='cuda', dtype=torch.bfloat16):
41
+ y = model.generate(x, max_new_tokens=500, temperature=0.65, top_k=25)
42
+
43
  full_text = enc.decode(y[0].tolist())
44
 
45
+ if "Response:\n" in full_text:
46
+ response = full_text.split("Response:\n")[-1]
47
+ else:
48
+ response = full_text
49
+
50
+ response = response.split("<|endoftext|>")[0].split("Instruction:")[0].strip()
51
  print(response + "\n")
52
 
53
  if __name__ == "__main__":