File size: 3,572 Bytes
35e7279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
license: llama3
---

- Foundation Model [Bllossom 8B](https://huggingface.co/MLP-KTLim/llama-3-Korean-Bllossom-8B)
- datasets  
  -  [jojo0217/korean_safe_conversation](https://huggingface.co/datasets/jojo0217/korean_safe_conversation)

# Usage for Transformers 
```python

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

BASE_MODEL = "sh2orc/Llama-3-Korean-8B"

model = AutoModelForCausalLM.from_pretrained(BASE_MODEL,
    torch_dtype=torch.bfloat16,
    attn_implementation="flash_attention_2", 
    device_map="cuda:0")

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = 'right'

instruction = 'ν• λΆ€ 결제 λŒ€ν•΄μ„œ μ„€λͺ…ν•΄μ€˜'

pipe = pipeline("text-generation", 
                model=model, 
                tokenizer=tokenizer, 
                max_new_tokens=1024)

messages = [
    {"role": "user", "content": instruction},
]

prompt = pipe.tokenizer.apply_chat_template(
        messages, 
        tokenize=False, 
        add_generation_prompt=True
)

outputs = pipe(
    prompt,
    do_sample=True,
    temperature=0.8,
    top_k=10,
    top_p=0.9,
    add_special_tokens=True,
    eos_token_id = [ 
        pipe.tokenizer.eos_token_id,
        pipe.tokenizer.convert_tokens_to_ids("<|eot_id|>")
    ]
)

print(outputs[0]['generated_text'][len(prompt):])
print(outputs[0]['generated_text'][len(prompt):])
```

# Result
<pre>

ν• λΆ€ μš”κΈˆμ€ 물건을 μ‚΄ λ•Œ, κ·Έ 값을 일정 κΈ°κ°„ λ™μ•ˆ λ‚˜λˆ μ„œ μ§€λΆˆν•˜λŠ” λ°©μ‹μž…λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 50λ§Œμ›μ§œλ¦¬ μ œν’ˆμ„ 10κ°œμ›” ν• λΆ€λ‘œ κ΅¬λ§€ν•œλ‹€λ©΄, 각 λ‹¬λ§ˆλ‹€ 5λ§Œμ›μ”© 10κ°œμ›”μ΄ λ™μ•ˆ μ§€λΆˆν•˜κ²Œ λ©λ‹ˆλ‹€. μ΄λ•Œ, ν• λΆ€ μš”κΈˆμ€ 일정 κΈ°κ°„ λ™μ•ˆ 이자 없이 물건을 μ‚¬μš©ν•  수 μžˆλŠ” 이점이 μžˆμ§€λ§Œ, λ™μ‹œμ— μ—°μ²΄λ£Œκ°€ 뢀과될 수 있으며, 채무가 λ°œμƒν•˜κ²Œ λ©λ‹ˆλ‹€. λ”°λΌμ„œ, ν• λΆ€λ₯Ό μ‚¬μš©ν•  λ•ŒλŠ” μžμ‹ μ˜ μž¬μ • μƒνƒœμ™€ ꡬ맀할 물건을 잘 κ³ λ €ν•΄μ•Ό ν•©λ‹ˆλ‹€.

</pre>




# Usage for VLLM
```python
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer, pipeline

BASE_MODEL = "sh2orc/Llama-3-Korean-8B"

llm = LLM(model=BASE_MODEL)

tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = 'right'

instruction = 'μΉ΄λ“œ ν• λΆ€ κ²°μ œμ— λŒ€ν•΄μ„œ μ•Œλ €μ€˜'

messages = [
    {
      "role": "system",
      "content": "당신은 ν›Œλ₯­ν•œ AI λΉ„μ„œμž…λ‹ˆλ‹€. You are a great AI assistant."
    },
    {
      "role": "user",
      "content": instruction
    }, 
]


prompt_message = tokenizer.apply_chat_template(
        messages, 
        tokenize=False, 
        add_generation_prompt=True,
)

eos_token_id = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>")]

outputs = llm.generate(prompt_message, SamplingParams(stop_token_ids=eos_token_id, temperature=0.6, top_p=0.8,max_tokens=4096))

for output in outputs:
    propt = output.prompt
    generated_text = output.outputs[0].text
    print(generated_text)

```


# Result
<pre>

μΉ΄λ“œ ν• λΆ€ κ²°μ œλŠ” κ²°μ œν•  κΈˆμ•‘μ„ 일정 κΈ°κ°„ λ™μ•ˆ λ‚˜λˆ μ„œ κ°šλŠ” λ°©μ‹μœΌλ‘œ, μΉ΄λ“œμ‚¬μ— μ˜ν•΄ λŒ€μΆœλœ κΈˆμ•‘μ„ κ°šλŠ” κ²ƒμž…λ‹ˆλ‹€. μΉ΄λ“œ ν• λΆ€ κ²°μ œλŠ” μΌμ •ν•œ κΈ°κ°„ λ™μ•ˆ μƒν™˜ν•  수 μžˆλŠ” κΈˆμ•‘μ„ μ„ νƒν•˜μ—¬ κ²°μ œν•  수 있으며, 이 κ³Όμ •μ—μ„œ 이자λ₯Ό μ§€λΆˆν•΄μ•Ό ν•©λ‹ˆλ‹€. μΉ΄λ“œ ν• λΆ€ κ²°μ œλŠ” μΌμ‹œλΆˆ κ²°μ œλ³΄λ‹€ μœ λ¦¬ν•  수 μžˆμ§€λ§Œ, 이자λ₯Ό μ§€λΆˆν•΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ— λΉ„μš©μ΄ μ¦κ°€ν•©λ‹ˆλ‹€.

</pre>