PerRing commited on
Commit
7568f64
β€’
1 Parent(s): f4dfaa7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -26
README.md CHANGED
@@ -39,44 +39,37 @@ llama3.2-3Bκ°€ λ‚˜μ™”λŠ”λ° ν•œκ΅­μ–΄κ°€ 포함 μ•ˆλ˜μ—ˆλ‹€κ΅¬?? 이번 Bllosso
39
 
40
 
41
  ```python
42
- import torch
43
- from transformers import AutoTokenizer, AutoModelForCausalLM
44
 
45
  model_id = 'Bllossom/llama-3.2-Korean-Bllossom-3B'
46
-
47
  tokenizer = AutoTokenizer.from_pretrained(model_id)
48
- model = AutoModelForCausalLM.from_pretrained(
49
- model_id,
50
- torch_dtype=torch.bfloat16,
51
- device_map="auto",
52
  )
 
53
  instruction = "μ² μˆ˜κ°€ 20개의 연필을 가지고 μžˆμ—ˆλŠ”λ° μ˜ν¬κ°€ μ ˆλ°˜μ„ κ°€μ Έκ°€κ³  λ―Όμˆ˜κ°€ 남은 5개λ₯Ό κ°€μ Έκ°”μœΌλ©΄ μ² μˆ˜μ—κ²Œ 남은 μ—°ν•„μ˜ κ°―μˆ˜λŠ” λͺ‡κ°œμΈκ°€μš”?"
54
 
55
  messages = [
56
  {"role": "user", "content": f"{instruction}"}
57
  ]
58
 
59
- input_ids = tokenizer.apply_chat_template(
60
- messages,
61
- add_generation_prompt=True,
62
- return_tensors="pt"
63
- ).to(model.device)
64
-
65
- terminators = [
66
- tokenizer.convert_tokens_to_ids("<|end_of_text|>"),
67
- tokenizer.convert_tokens_to_ids("<|eot_id|>")
68
- ]
69
-
70
- outputs = model.generate(
71
- input_ids,
72
- max_new_tokens=1024,
73
- eos_token_id=terminators,
74
- do_sample=True,
75
- temperature=0.6,
76
- top_p=0.9
77
  )
78
 
79
- print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
80
  ```
81
  ```
82
  μ² μˆ˜κ°€ 20개의 연필을 가지고 μžˆμ—ˆκ³  μ˜ν¬κ°€ μ ˆλ°˜μ„ κ°€μ Έκ°€λ©΄, μ˜ν¬κ°€ κ°€μ Έκ°„ μ—°ν•„μ˜ κ°―μˆ˜λŠ” 20 / 2 = 10κ°œμž…λ‹ˆλ‹€.
 
39
 
40
 
41
  ```python
42
+ from llama_cpp import Llama
43
+ from transformers import AutoTokenizer
44
 
45
  model_id = 'Bllossom/llama-3.2-Korean-Bllossom-3B'
 
46
  tokenizer = AutoTokenizer.from_pretrained(model_id)
47
+ model = Llama(
48
+ model_path='llama-3.2-Korean-Bllossom-3B-gguf-Q4_K_M.gguf'
 
 
49
  )
50
+
51
  instruction = "μ² μˆ˜κ°€ 20개의 연필을 가지고 μžˆμ—ˆλŠ”λ° μ˜ν¬κ°€ μ ˆλ°˜μ„ κ°€μ Έκ°€κ³  λ―Όμˆ˜κ°€ 남은 5개λ₯Ό κ°€μ Έκ°”μœΌλ©΄ μ² μˆ˜μ—κ²Œ 남은 μ—°ν•„μ˜ κ°―μˆ˜λŠ” λͺ‡κ°œμΈκ°€μš”?"
52
 
53
  messages = [
54
  {"role": "user", "content": f"{instruction}"}
55
  ]
56
 
57
+ prompt = tokenizer.apply_chat_template(
58
+ messages,
59
+ tokenize = False,
60
+ add_generation_prompt=True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  )
62
 
63
+ generation_kwargs = {
64
+ "max_tokens":512,
65
+ "stop":["<|eot_id|>"],
66
+ "echo":True,
67
+ "top_p":0.9,
68
+ "temperature":0.6,
69
+ }
70
+
71
+ resonse_msg = model(prompt, **generation_kwargs)
72
+ print(resonse_msg['choices'][0]['text'][len(prompt):])
73
  ```
74
  ```
75
  μ² μˆ˜κ°€ 20개의 연필을 가지고 μžˆμ—ˆκ³  μ˜ν¬κ°€ μ ˆλ°˜μ„ κ°€μ Έκ°€λ©΄, μ˜ν¬κ°€ κ°€μ Έκ°„ μ—°ν•„μ˜ κ°―μˆ˜λŠ” 20 / 2 = 10κ°œμž…λ‹ˆλ‹€.