File size: 1,243 Bytes
322906a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
language:
- ko
pipeline_tag: text-generation
---
## Prompt Tempalte
It follows Alpaca format.
```
### 질문: {instruction}
### 답변: {output}
```
### Implementation Code
```
import troch
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.fron_pretrained("Ja3ck/Mistral-instruct-IPO-Y24-v1", return_dict=True, torch_dtype=torch.bfloat16, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("Ja3ck/Mistral-instruct-IPO-Y24-v1", use_fast=True)
tokenizer.pad_token = tokenizer.unk_token
tokenizer.pad_token_id = tokenizer.unk_token_id
tokenizer.padding_side = "left"

def gen(x):
  x_ = f"### 질문: {x.strip()} ### 답변: "
  inputs = tokenizer(x_, return_tensor='pt')
  input_ids = inputs['input_ids'].cuda()
  generation_output = model.generate(
      pad_token_id = tokenizer.pad_token_id,
      temperature=0.1,
      top_p=1,
      top_k=50,
      num_beams=1,
      repetition_penalty=1.13,
      do_sample=True,
    ),
    return_dict_in_generate=True,
    output_scores=True,
    max_new_tokens=1024
  )
  for seq in generation_output.sequences:
    output = tokenizer.decode(seq)
    print(output.split("### 답변: ")[1].strip())

gen("안녕하세요?")
```