INNER CODE UNIT · Python
tokenize
CerebriumAI/examples · 1-getting-started/2-using-cerebrium-secrets/main.py:57
def tokenize(prompt, cutoff_len, add_eos_token=True):
print("tokenizing: ", prompt)
return tokenizer(
prompt,
truncation=True,
max_length=cutoff_len,
padding=False,
return_tensors="pt",
)
def generate(params: Item):
print("Placing prompt in template")
prompt_input = tokenize(prompt=params.prompt, cutoff_len=params.cutoff_len)
input_ids = prompt_input["input_ids"]
input_ids = input_ids.to(base_model.device)
print("Setting up generation config")