ITmedia NEWS > AI+ >
ITmedia AI+ AI活用のいまが分かる

サイバーエージェントが公開した大規模言語モデルの実力を試す清水亮の「世界を変えるAI」(1/4 ページ)

» 2023年05月17日 12時10分 公開
[清水 亮ITmedia]

 5月16日、サイバーエージェントが商用利用可能な7B(68億パラメータ)の大規模言語モデルOpenCalm7Bを公開した。OpenCalm7Bは、日本語版Wikipediaと日本語版コモンクロールを学習したとされている。ライセンスはCC-BY-SA 4.0だ。

 早速その実力を試してみた。

 まずOpenCalm7Bを動かすには、TransformerをインストールしたPCで、VRAMは最低14GBくらいは必要となる。今回、筆者はV100を4基搭載したさくらインターネットの高火力サーバを利用した。

(ldm310) ubuntu@ubuntu:~$ python
Python 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> from transformers import AutoModelForCausalLM, AutoTokenizer
>>> 
>>> model = AutoModelForCausalLM.from_pretrained("cyberagent/open-calm-7b", device_map="auto", torch_dtype=torch.float16)
Downloading (…)lve/main/config.json: 100%| ■■■■■■| 611/611 [00:00<00:00, 351kB/s]
Downloading (…)model.bin.index.json: 100%|■■| 42.0k/42.0k [00:00<00:00, 281kB/s]
Downloading (…)00001-of-00002.bin";: 100%|■| 9.93G/9.93G [14:44<00:00, 11.2MB/s]
Downloading (…)00002-of-00002.bin";: 100%|■■■■■■■■■■■■■■■■■■■■■■■| 3.95G/3.95G [05:51<00:00, 11.3MB/s]
Downloading shards: 100%|■■■■■■■■■■■■■■■■■■■■■■■■| 2/2 [20:37<00:00, 618.61s/it]05:51<00:00, 11.4MB/s]
Loading checkpoint shards: 100%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 2/2 [00:09<00:00,  4.61s/it]
Downloading (…)neration_config.json: 100%|■■■■■■■■■■■■■■■■■■■■■■■■■■■| 116/116 [00:00<00:00, 58.1kB/s]
>>> tokenizer = AutoTokenizer.from_pretrained("cyberagent/open-calm-7b")
Downloading (…)okenizer_config.json: 100%|■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 323/323 [00:00<00:00, 229kB/s]
Downloading (…)/main/tokenizer.json: 100%|■■■■■■■■■■■■■■■■■■■■■■■| 3.23M/3.23M [00:00<00:00, 3.26MB/s]
Downloading (…)cial_tokens_map.json: 100%|■■■■■■■■■■■■■■■■■■■■■■■■■■■| 129/129 [00:00<00:00, 94.8kB/s]
>>> inputs = tokenizer("AIによって私達の暮らしは、", return_tensors="pt").to(model.device)

 最初にモデルをダウンロードするのに10〜20分ほどかかる。

サイバーエージェントが公開しているLLMのモデル
>>> with torch.no_grad():
...     tokens = model.generate(
...         **inputs,
...         max_new_tokens=64,
...         do_sample=True,
...         temperature=0.7,
...         pad_token_id=tokenizer.pad_token_id,
...     )
...     
... 
/home/ubuntu/anaconda3/envs/ldm310/lib/python3.10/site-packages/transformers/models/gpt_neox/modeling_gpt_neox.py:220: UserWarning: where received a uint8 condition tensor. This behavior is deprecated and will be removed in a future version of PyTorch. Use a boolean condition instead. (Triggered internally at /opt/conda/conda-bld/pytorch_1666643003845/work/aten/src/ATen/native/TensorCompare.cpp:413.)
  attn_scores = torch.where(causal_mask, attn_scores, mask_value)
>>> output = tokenizer.decode(tokens[0], skip_special_tokens=True)
>>> print(output)

 例文として掲載されていた「AIによって私達の暮らしは、」を入力した結果はこうなった。

       1|2|3|4 次のページへ

Copyright © ITmedia, Inc. All Rights Reserved.