Views
No views yet
1import transformers
2import torch
3
4model_id = "VIRNECT/llama-3-Korean-8B-r-v1"
5
6pipeline = transformers.pipeline(
7 "text-generation",
8 model=model_id,
9 model_kwargs={"torch_dtype": torch.bfloat16},
10 device_map="auto",
11)
12
13pipeline.model.eval()
14
15PROMPT = '''You are a helpful AI assistant. Please answer the user's questions kindly. 당신은 유능한 AI 어시스턴트 입니다. 사용자의 질문에 대해 친절하게 답변해주세요.'''
16instruction = "화학공학이 다른 공학 분야와 어떻게 다른가요?"
17
18messages = [
19 {"role": "system", "content": f"{PROMPT}"},
20 {"role": "user", "content": f"{instruction}"}
21]
22
23prompt = pipeline.tokenizer.apply_chat_template(
24 messages,
25 tokenize=False,
26 add_generation_prompt=True
27)
28
29terminators = [
30 pipeline.tokenizer.eos_token_id,
31 pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
32]
33
34outputs = pipeline(
35 prompt,
36 max_new_tokens=2048,
37 eos_token_id=terminators,
38 do_sample=True,
39 temperature=0.6,
40 top_p=0.9
41)
42
43print(outputs[0]["generated_text"][len(prompt):])