-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
46 lines (40 loc) · 1.45 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def npsample(ozut, temp: float = 1.0, top_p_usual: float = 0.8) -> int:
import numpy as np
from scipy.special import softmax
try:
ozut = ozut.numpy()
except:
try:
ozut = ozut.cpu().numpy()
except:
ozut = np.array(ozut)
# out[self.UNKNOWN_CHAR] = -float('Inf')
# out[self.UNKNOWN_CHAR] = -float('Inf')
# turn to float if is half and cpu
probs = softmax(ozut, axis=-1)
sorted_probs = np.sort(probs)[::-1]
cumulative_probs = np.cumsum(sorted_probs)
cutoff = float(sorted_probs[np.argmax(
cumulative_probs > top_p_usual)])
probs[probs < cutoff] = 0
if temp != 1.0:
probs = pow(probs, 1.0 / temp)
probs = probs / np.sum(probs, axis=0)
mout = np.random.choice(a=len(probs), p=probs)
return mout
print(1)
from model import loadWeights
model, state = loadWeights("rwkv-tensorflow/RWKV-4-Pile-1B5-Instruct-test1-20230124.pth")
print(2)
from transformers import GPTNeoXTokenizerFast
tokenizer:GPTNeoXTokenizerFast = GPTNeoXTokenizerFast.from_pretrained("EleutherAI/gpt-neox-20b")
print(3)
prompt = tokenizer.encode("User: What is the purpose of a 3.5 inch finglslop with an attached turboencorboratator? Bot:")
for token in prompt[:-1]:
logits, state = model.forward(token,state)
print(4)
print("Loaded prompt.")
for i in range(100):
logits, state = model.forward(prompt[-1],state)
prompt = prompt+[npsample(logits)]
print(tokenizer.decode(prompt))