Views
No views yet
transformers >= 4.43.0 onward, you can run conversational inference using the Transformers pipeline abstraction or by leveraging the Auto classes with the generate() function.pip install --upgrade transformers.1import transformers
2import torch
3
4model_id = "atahanuz/RANDOM_Llama-3.1-8B-Instruct"
5
6pipeline = transformers.pipeline(
7 "text-generation",
8 model=model_id,
9 model_kwargs={"torch_dtype": torch.bfloat16},
10 device_map="auto",
11)
12
13messages = [
14 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
15 {"role": "user", "content": "Who are you?"},
16]
17
18outputs = pipeline(
19 messages,
20 max_new_tokens=256,
21)
22print(outputs[0]["generated_text"][-1])