Merge branch 'main' into update_ja-docs

This commit is contained in:
Ikko Eltociear Ashimine
2023-08-28 02:42:58 +09:00
committed by GitHub
19 changed files with 2024 additions and 1073 deletions

View File

@@ -1,23 +1,23 @@
<br>
<p align="left">
<a href="README_CN.md">中文</a>&nbsp &nbsp<a href="README.md">English</a>&nbsp &nbsp日本語
</p>
<br><br>
<p align="center">
<img src="assets/logo.jpg" width="400"/>
<p>
<br>
<p align="center">
Qwen-7B <a href="https://modelscope.cn/models/qwen/Qwen-7B/summary">🤖 <a> | <a href="https://huggingface.co/Qwen/Qwen-7B">🤗</a>&nbsp Qwen-7B-Chat <a href="https://modelscope.cn/models/qwen/Qwen-7B-Chat/summary">🤖 <a>| <a href="https://huggingface.co/Qwen/Qwen-7B-Chat">🤗</a>&nbsp &nbsp<a href="https://modelscope.cn/studios/qwen/Qwen-7B-Chat-Demo/summary">Demo</a>&nbsp &nbsp<a href="https://github.com/QwenLM/Qwen-7B/blob/main/tech_memo.md">Report</a>&nbsp&nbsp | &nbsp&nbsp<a href="https://discord.gg/9bjvspyu">Discord</a>
Qwen-7B <a href="https://modelscope.cn/models/qwen/Qwen-7B/summary">🤖 <a> | <a href="https://huggingface.co/Qwen/Qwen-7B">🤗</a>&nbsp Qwen-7B-Chat <a href="https://modelscope.cn/models/qwen/Qwen-7B-Chat/summary">🤖 <a> | <a href="https://huggingface.co/Qwen/Qwen-7B-Chat">🤗</a>&nbsp | Qwen-7B-Chat-Int4 <a href="https://huggingface.co/Qwen/Qwen-7B-Chat-Int4">🤗</a>
<br>
<a href="https://qianwen-res.oss-cn-beijing.aliyuncs.com/qwen_wechat_group.PNG">WeChat</a>&nbsp&nbsp | &nbsp&nbsp<a href="https://discord.gg/z3GAxXZ9Ce">Discord</a>&nbsp&nbsp | &nbsp&nbsp<a href="https://modelscope.cn/studios/qwen/Qwen-7B-Chat-Demo/summary">Demo</a>&nbsp &nbsp<a href="https://github.com/QwenLM/Qwen-7B/blob/main/tech_memo.md">Report</a>
</p>
<br>
<p align="center">
<a href="README_CN.md">中文</a>&nbsp &nbsp<a href="README.md">English</a>&nbsp &nbsp日本語
</p>
<br><br>
<p align="right">
<p align="left">
日本語ドキュメントメンテナー: <a href="https://github.com/eltociear">Ikko Eltociear Ashimine</a>
</p>
<br><br>
<br>
私たちは、**Qwen-7B** と **Qwen-7B-Chat****🤖 ModelScope** と **🤗 Hugging Face** の両方でオープンソース化しています(上部のロゴをクリックすると、コードとチェックポイントのあるリポジトリに移動します)。このレポには、Qwen-7B の簡単な紹介と、使い方の手引き、さらに詳しい情報を提供する技術メモ [link](tech_memo.md) が含まれています。
@@ -33,6 +33,7 @@ Qwen-7B は、アリババクラウドが提唱する大規模言語モデルシ
## ニュース
* 2023.8.21 Qwen-7B-Chat 用 Int4 量子化モデル(**Qwen-7B-Chat-Int4**)をリリースしました。メモリコストは低いが、推論速度は向上している。また、ベンチマーク評価において大きな性能劣化はありません。
* 2023.8.3 Qwen-7B と Qwen-7B-Chat を ModelScope と Hugging Face で公開。また、トレーニングの詳細やモデルの性能など、モデルの詳細についてはテクニカルメモを提供しています。
## パフォーマンス
@@ -199,89 +200,62 @@ tiktoken に基づくトークナイザーは、他のトークナイザー、
## 量子化
`NF4``Int8` のモデルをロードする方法を示す例を提供します。手始めに、`bitsandbytes` が実装されていることを確認して下さい。`bitsandbytes` の要件は以下の通りになります:
### 使用方法
```
**必要条件** Python >= 3.8。Linux ディストリビューションUbuntu、MacOS など)+ CUDA > 10.0。
**注:[AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ)に基づく新しい解決策を提供し、Qwen-7B-Chat用のInt4量子化モデル[ここをクリック](https://huggingface.co/Qwen/Qwen-7B-Chat-Int4)をリリースしました。このモデルは、従来の解決策と比較して、ほぼ無損失のモデル効果を達成しつつ、メモリコストと推論速度の両方で性能が向上しています**
ここでは、量子化されたモデルを推論に使用する方法を示します。始める前に、AutoGPTQの要件を満たしていることを確認し、ソースからインストールしてください一時的にQwenのコードは最新版のPyPIパッケージではまだリリースされていません
```bash
git clone https://github.com/PanQiWei/AutoGPTQ.git && cd AutoGPTQ
pip install .
```
して、以下のコマンドを実行して `bitsandbytes` をインストールする:
```
pip install bitsandbytes
```
Windows ユーザは、[bitsandbytes-windows-webui](https://github.com/jllllll/bitsandbytes-windows-webui/releases/tag/wheels) という別のオプションを見つける必要があります。
そして、量子化の設定を `AutoModelForCausalLM.from_pretrained` に追加するだけとなります。以下の例を参照してください:
うすれば、以下のように簡単に量子化モデルを読み込むことができる。
```python
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
# NF44 ビット)の量子化設定
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type='nf4',
bnb_4bit_compute_dtype=torch.bfloat16
)
# Int88 ビット)の量子化設定
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
model = AutoModelForCausalLM.from_pretrained(
args.checkpoint_path,
device_map="cuda:0",
quantization_config=quantization_config,
max_memory=max_memory,
trust_remote_code=True,
).eval()
from auto_gptq import AutoGPTQForCausalLM
model = AutoGPTQForCausalLM.from_quantized("Qwen/Qwen-7B-Chat-Int4", device_map="auto", trust_remote_code=True, use_safetensors=True).eval()
```
この方法では、Qwen-7B を `NF4``Int8` でロードすることができ、メモリ使用量を節約できる。以下にモデル性能の関連統計量を示します。量子化により、有効性は若干低下するが、推論効率は大幅に向上し、メモリコストが削減されることがわかります。
推論を実行するには、上で示した基本的な使い方に似ているが、generation configurationを明示的に渡すことを忘れないこと
| Precision | MMLU | GPU Memory for Loading Model |
| ----------- | :------: | :---------------------------: |
| BF16 | 56.7 | 16.38G |
| Int8 | 52.8 | 10.44G |
| NF4 | 48.9 | 7.79G |
```python
from transformers import GenerationConfig
config = GenerationConfig.from_pretrained("Qwen/Qwen-7B-Chat-Int4", trust_remote_code=True)
response, history = model.chat(tokenizer, "Hi", history=None, generation_config=config)
```
注: 上表の GPU メモリ使用量プロファイリングは、シングル A100-SXM4-80G GPU、PyTorch 2.0.1、CUDA 11.8、flash attention 使用で実行されています。
### 性能
## 推論効率
ベンチマークにおけるBF16モデルとInt4モデルの性能について説明する。結果を以下に示します
| Quantization | MMLU | CEval (val) | GSM8K | Humaneval |
| ------------- | :--------: | :----------: | :----: | :--------: |
| BF16 | 53.9 | 54.2 | 41.1 | 24.4 |
| Int4 | 52.6 | 52.9 | 38.1 | 23.8 |
### 推論スピード
BF16 精度、量子化レベル Int8 または NF4 で、それぞれ2Kトークンを生成する平均推論速度を測定しました。
BF16精度とInt4の量子化レベルの下で、それぞれ2048個と8192個のトークンを生成する平均推論速度(tokens/s)を測定した。
| 量子化レベル | flash_attn による推論速度(トークン/秒) | flash_attn を使用しない場合の推論速度(トークン/秒) |
| ------ | :---------------------------: | :---------------------------: |
| BF16 (no quantization) | 30.06 | 27.55 |
| Int8 (bnb) | 7.94 | 7.86 |
| NF4 (bnb) | 21.43 | 20.37 |
| Quantization | Speed (2048 tokens) | Speed (8192 tokens) |
| ------------- | :------------------:| :------------------:|
| BF16 | 30.53 | 28.51 |
| Int4 | 45.60 | 33.83 |
詳細には、プロファイリングの設定は、1 コンテクスト・トークンで 2048 の新しいトークンを生成している。プロファイリングは、PyTorch 2.0.1CUDA 11.8 を搭載したシングル A100-SXM4-80G GPU で実行される。推論速度は生成された 2048 個のトークンの平均です。
詳細には、プロファイリングの設定は、1コンテクスト・トークンで8192個の新しいトークンを生成している。プロファイリングは、PyTorch 2.0.1CUDA 11.4を搭載したシングルA100-SXM4-80G GPUで実行される。推論速度は生成された8192個のトークンの平均です。
### GPU メモリ使用量
また、BF16 または Int8/NF4 量子化レベルの下で、2048 個のトークンをコンテキストとしてエンコードした場合および単一のトークンを生成した場合と、8192 個のトークンを生成した場合(単一のトークンをコンテキストとして生成した場合)の GPU メモリ使用量のピーク値をそれぞれプロファイリングしました。結果を以下に示す。
また、BF16またはInt4の量子化レベルで、それぞれ2048トークンをコンテキストとしてエンコードした場合および単一のトークンを生成した場合と、8192トークンを生成した場合単一のトークンをコンテキストとして生成した場合のGPUメモリ使用量のピーク値をプロファイリングしました。その結果を以下に示します。
Flash attention を使用した場合のメモリ使用量は以下の通りである:
| Quantization Level | Peak Usage for Encoding 2048 Tokens | Peak Usage for Generating 8192 Tokens |
| ------------------ | :---------------------------------: | :-----------------------------------: |
| BF16 | 18.99GB | 24.40GB |
| Int4 | 10.20GB | 15.61GB |
| 量子化レベル | 2048 トークンをエンコードする際のピーク使用量 | 8192 トークン生成のピーク使用量 |
| --- | :---: | :---: |
| BF16 | 18.11GB | 23.52GB |
| Int8 | 12.17GB | 17.60GB |
| NF4 | 9.52GB | 14.93GB |
Flash attention を使用しない場合、メモリ使用量は次のようになる:
| 量子化レベル | 2048 トークンをエンコードする際のピーク使用量 | 8192 トークン生成のピーク使用量 |
| --- | :---: | :---: |
| BF16 | 18.11GB | 24.40GB |
| Int8 | 12.18GB | 18.47GB |
| NF4 | 9.52GB | 15.81GB |
上記のスピードとメモリーのプロファイリングは、[このスクリプト](https://qianwen-res.oss-cn-beijing.aliyuncs.com/profile.py)を使って行われました。
上記のスピードとメモリーのプロファイリングは、[このスクリプト](https://qianwen-res.oss-cn-beijing.aliyuncs.com/profile.py)を使用しています。
## デモ