ShinDJ commited on
Commit
2075b89
·
verified ·
1 Parent(s): 7b297ee

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +65 -41
README.md CHANGED
@@ -65,64 +65,88 @@ The Bllossom language model is a Korean-English bilingual language model based o
65
  pip install torch transformers==4.40.0 accelerate
66
  ```
67
 
68
- ### Python code with Pipeline
69
  ```python
70
- import transformers
 
71
  import torch
72
 
73
- model_id = "Bllossom/llama-3.1-Korean-Bllossom-405B"
 
74
 
75
- pipeline = transformers.pipeline(
76
- "text-generation",
77
- model=model_id,
78
- model_kwargs={"torch_dtype": torch.bfloat16},
79
- device_map="auto",
80
- )
81
 
82
- pipeline.model.eval()
 
83
 
84
- PROMPT = '''You are a helpful AI assistant. Please answer the user's questions kindly. 당신은 유능한 AI 어시스턴트 입니다. 사용자의 질문에 대해 친절하게 답변해주세요.'''
85
- instruction = "서울의 유명한 관광 코스를 만들어줄래?"
86
 
 
 
87
  messages = [
88
- {"role": "system", "content": f"{PROMPT}"},
89
- {"role": "user", "content": f"{instruction}"}
90
- ]
91
 
92
- prompt = pipeline.tokenizer.apply_chat_template(
93
- messages,
94
- tokenize=False,
95
- add_generation_prompt=True
96
- )
97
 
98
- terminators = [
99
- pipeline.tokenizer.eos_token_id,
100
- pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
101
- ]
 
102
 
103
- outputs = pipeline(
104
- prompt,
105
- max_new_tokens=2048,
106
- eos_token_id=terminators,
107
- do_sample=True,
108
- temperature=0.6,
109
- top_p=0.9
110
- )
111
 
112
- print(outputs[0]["generated_text"][len(prompt):])
113
- ```
114
  ```
115
- # 물론이죠! 서울은 다양한 문화와 역사, 자연을 겸비한 도시로, 많은 관광 명소를 자랑합니다. 여기 서울의 유명한 관광 코스를 소개해 드릴게요.
116
 
117
- ### 코스 1: 역사와 문화 탐방
 
 
 
 
 
 
118
 
119
- 1. **경복궁**
120
- - 서울의 대표적인 궁궐로, 조선 왕조의 역사와 문화를 체험할 수 있는 곳입니다.
121
 
122
- 2. **북촌 한옥마을**
123
- - 전통 한옥이 보존된 마을로, 조선시대의 생활상을 느낄 있습니다.
 
 
 
 
 
 
 
 
 
124
 
125
- ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  ```
127
 
128
  ## Supported by
 
65
  pip install torch transformers==4.40.0 accelerate
66
  ```
67
 
68
+ ### Python code with Image
69
  ```python
70
+ from PIL import Image
71
+ from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
72
  import torch
73
 
74
+ model = LlavaNextForConditionalGeneration.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
75
+ processor = LlavaNextProcessor.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
76
 
77
+ image = Image.open('[IMAGE_PATH]').convert('RGB')
 
 
 
 
 
78
 
79
+ PROMPT=\
80
+ """You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
81
 
82
+ 당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
 
83
 
84
+
85
+ instruction = '이미지에 대해서 설명해주세요.'
86
  messages = [
87
+ {'role': 'system', 'content': f"{PROMPT}"},
88
+ {'role': 'user', 'content': f"<image>\n{instruction}"}
89
+ ]
90
 
91
+ chat_messages = processor.tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)
 
 
 
 
92
 
93
+ inputs = processor(
94
+ chat_messages,
95
+ image,
96
+ return_tensors='pt',
97
+ ).to('cuda:0')
98
 
99
+ output = model.generate(
100
+ **inputs,
101
+ max_new_tokens=1024,
102
+ )
 
 
 
 
103
 
104
+ print(processor.tokenizer.decode(output[0]))
 
105
  ```
 
106
 
107
+ ### Python code No Image
108
+ ```python
109
+ from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
110
+ import torch
111
+
112
+ model = LlavaNextForConditionalGeneration.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
113
+ processor = LlavaNextProcessor.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
114
 
115
+ with torch.no_grad():
 
116
 
117
+ PROMPT=\
118
+ """You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
119
+
120
+ 당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
121
+
122
+ instruction = '자연어처리 15주 분량 커리큘럼을 짜줘'
123
+
124
+ messages = [
125
+ {'role': 'system', 'content': f"{PROMPT}"},
126
+ {'role': 'user', 'content': f"{instruction}"}
127
+ ]
128
 
129
+ chat_messages = processor.tokenizer.apply_chat_template(
130
+ messages,
131
+ tokenize=True,
132
+ add_generation_prompt=True,
133
+ return_tensors='pt',
134
+ )
135
+
136
+ bos_token = processor.tokenizer.bos_token_id
137
+ chat_messages = torch.cat([torch.tensor([[bos_token]]),chat_messages],dim=-1).to('cuda:0')
138
+
139
+
140
+ output = model.generate(
141
+ input_ids = chat_messages,
142
+ use_cache=False,
143
+ max_new_tokens=2048,
144
+ top_p=0.9,
145
+ temperature=0.6,
146
+ do_sample=True,
147
+ )
148
+
149
+ print(processor.tokenizer.decode(output[0]))
150
  ```
151
 
152
  ## Supported by