-
Notifications
You must be signed in to change notification settings - Fork 3
/
inference.py
46 lines (38 loc) · 1.33 KB
/
inference.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
from trigram_tokenizer.inference import InferencePipe
from trigram_tokenizer.logging import logger
def generate(
prompt: str,
max_tokens: int = 4,
echo: bool = False,
):
result = inference_pipe.generate(
prompt=prompt,
max_tokens=max_tokens,
echo=echo,
log_probs=10_000,
)
logger.info("#" * 50)
logger.info(f"PROMPT: {prompt}")
logger.info(f"COMPLETION: {result.completion}")
# logger.info(f"COMPLETION: {result.tokens}")
# logger.info(f"COMPLETION: {result.tokens_count_training}")
# logger.info(f"COMPLETION: {result.prompt_token_count_training}")
logger.info("#" * 50)
return result
if __name__ == "__main__":
inference_pipe = InferencePipe(
"<some checkpoint path>",
# top_word_dict="<path to some dictionary>", # collections.Counter file with some sampling-dictionary
# reduce_tokenizer_words_to=50000, # will reduce above's file to top-k frequent entries
)
# InferencePipe.tokenizer.convert_weight_for_word_edge_overweight(.8) # will downweight 'edge-trigram's - further discussed in paper
generate(
"Question: what has angelina jolie accomplished? \nAnswer: ",
max_tokens=20,
echo=False,
)
generate(
"Once upon a time",
max_tokens=64,
echo=False,
)