"""Generates a text file and inserts an passkey at a random position."""
fromnumpyimportrandomasnprandom
rnd_state=nprandom.get_state()
nprandom.seed(seed)
n_garbage_prefix=nprandom.randint(0,n_garbage)
n_garbage_suffix=n_garbage-n_garbage_prefix
task_description='There is an important info hidden inside a lot of irrelevant text. Find it and memorize them. I will quiz you about the important information there.'# noqa: E501
garbage='The grass is green. The sky is blue. The sun is yellow. Here we go. There and back again.'# noqa: E501
garbage_num=n_garbage//(len(garbage)+1)+1
garbage_inf=' '.join([garbage]*garbage_num)
assertlen(garbage_inf)>=n_garbage
garbage_prefix=garbage_inf[:n_garbage_prefix]
garbage_suffix=garbage_inf[:n_garbage_suffix]
pass_key=nprandom.randint(1,50000)
information_line=f'The pass key is {pass_key}. Remember it. {pass_key} is the pass key.'# noqa: E501
final_question='What is the pass key? The pass key is'
lines=[
task_description,
garbage_prefix,
information_line,
garbage_suffix,
final_question,
]
nprandom.set_state(rnd_state)
return'\n'.join(lines),str(pass_key)
defmain(args):
"""main."""
# Load model and tokenizer
llm=LLM(model_path=args.model_path,
model_name=args.model_name,
max_session_len=args.max_tokens)
all_accuries={}
# This is a rough ratio to control the number of texts and tokens