Views
No views yet
1alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
2### Instruction:
3{}
4### Input:
5{}
6### Response:
7{}"""
8
9from transformers import TextStreamer
10def chatml(question, model):
11 inputs = tokenizer([alpaca_prompt.format(question, "", "", )], return_tensors="pt").to("cuda")
12
13 text_streamer = TextStreamer(tokenizer, skip_special_tokens=True,
14 skip_prompt=True)
15
16 return model.generate(**inputs, streamer=text_streamer,
17 max_new_tokens=512,
18 do_sample=True,
19 temperature=0.9,
20 top_p=0.5,
21 top_k=20,
22 repetition_penalty=1.1,
23 eos_token_id=tokenizer.eos_token_id,
24 use_cache=True,
25 )
26
27# Function call
28question = "Which course is related to AI and Communication at westminster?"
29x = chatml(question,model)chatml function to query the model using a formatted Alpaca-style prompt. Replace question with your query and model with your loaded Gemma-2-9b model instance to receive a response.