WebEssentz commited on
Commit
4ddd95f
·
verified ·
1 Parent(s): 5258e9e

Add one-click inference example

Browse files
Files changed (1) hide show
  1. inference_example.py +22 -0
inference_example.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # How to run Hyperion-DeepSpace-218M
3
+ # pip install torch transformers
4
+
5
+ import torch
6
+ from transformers import GPT2TokenizerFast
7
+
8
+ # Load model (you need the full code from the training script too — paste the full architecture above)
9
+ # For now, people can just load the .pth and run with the original code
10
+
11
+ tokenizer = GPT2TokenizerFast.from_pretrained("gpt2")
12
+ tokenizer.pad_token = tokenizer.eos_token
13
+
14
+ # Quick generation function (copy-paste the SuperLearningLM class first!)
15
+ def chat(prompt, max_length=200, temperature=0.8):
16
+ input_ids = tokenizer.encode(prompt, return_tensors="pt").cuda()
17
+ with torch.no_grad():
18
+ output = model.generate(input_ids, max_length=max_length, temperature=temperature)
19
+ return tokenizer.decode(output[0], skip_special_tokens=True)
20
+
21
+ # Example
22
+ print(chat("Once upon a time"))