File size: 3,485 Bytes
59d3d4c
 
 
 
c488176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e9555f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c488176
7e9555f
c488176
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
base_model:
- meta-llama/Llama-3.3-70B-Instruct
---

# kishizaki-sci/Llama-3.3-70B-Instruct-AWQ-4bit-JP-EN

## モデル情報
[Llama-3.3-70B-Instruct](https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct)を[AutoAWQ](https://github.com/casper-hansen/AutoAWQ)で4bit 量子化したモデル。量子化の際のキャリブレーションデータに日本語と英語を含むデータを使用。

## 使い方
### transformers
```python
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer

tokenizer = AutoTokenizer.from_pretrained("kishizaki-sci/Llama-3.3-70B-Instruct-AWQ-4bit-JP-EN")
model = AutoModelForCausalLM.from_pretrained("kishizaki-sci/Llama-3.3-70B-Instruct-AWQ-4bit-JP-EN")
model.to("cuda")

chat = [
    {"role": "system", "content": "あなたは日本語で応答するAIチャットボットです。ユーザをサポートしてください。"},
    {"role": "user", "content": "plotly.graph_objectsを使って散布図を作るサンプルコードを書いてください。"}
]
prompt = tokenizer.apply_chat_template(
    chat,
    tokenize=False,
    add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt")
inputs = inputs.to("cuda")
streamer = TextStreamer(tokenizer)

output = model.generate(**inputs, streamer=streamer, max_new_tokens=1024)
```
このコードはA100インスタンスの[Google Colab](https://colab.research.google.com/drive/1NSWV6MMisTlN5ELN42VPMLRH9ahAfNrJ?usp=sharing)  でも動かせます。

### vLLM
```python
from vllm import LLM, SamplingParams

llm = LLM(
    model="kishizaki-sci/Llama-3.3-70B-Instruct-AWQ-4bit-JP-EN",
    tensor_parallel_size=1,
    gpu_memory_utilization=0.97,
    quantization="awq"
)
tokenizer = llm.get_tokenizer()

messages = [
    {"role": "system", "content": "あなたは日本語で応答するAIチャットボットです。ユーザをサポートしてください。"},
    {"role": "user", "content": "plotly.graph_objectsを使って散布図を作るサンプルコードを書いてください。"},
]

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

sampling_params = SamplingParams(
    temperature=0.6,
    top_p=0.9,
    max_tokens=1024
)

outputs = llm.generate(prompt, sampling_params)
print(outputs[0].outputs[0].text)
```
H100 (94GB)を1基積んだインスタンスでの実行はこちらの[notebook]()をご覧ください。

## キャリブレーションデータ
以下のデータセットから512個のデータ,プロンプトを抽出。1つのデータのトークン数は最大350制限。
-  [TFMC/imatrix-dataset-for-japanese-llm](https://huggingface.co/datasets/TFMC/imatrix-dataset-for-japanese-llm)
-  [meta-math/MetaMathQA](https://huggingface.co/datasets/meta-math/MetaMathQA)
-  [m-a-p/CodeFeedback-Filtered-Instruction](https://huggingface.co/datasets/m-a-p/CodeFeedback-Filtered-Instruction)
-  [kunishou/databricks-dolly-15k-ja](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
-  その他日本語版・英語版のwikipedia記事から作成したオリジナルデータ,有害プロンプト回避のためのオリジナルデータを使用。 

## License
[MIT License]を適用する。ただし量子化のベースモデルに適用されている[Llama 3.3 Community License Agreement](https://github.com/meta-llama/llama-models/blob/main/models/llama3_3/LICENSE)を遵守すること。