LINE が HuggingFace Hub で公開している日本語言語モデル japanese-large-lm を M1 Mac で動かしてみました。
まずは、HuggingFace Hub の line-corporatin/japanese-large-lm-3.6b からダウンロードします。
Apple シリコンは CUDA に対応していないため、サンプルのコードをそのまま実行すると次のエラーが発生してしまいます。
AssertionError: Torch not compiled with CUDA enabled
そこで、pipline に渡す device 引数を 0 から ‘mps’ に変更します。
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device="mps")
しかし、今度は次のエラーが発生してしまいます。
RuntimeError: MPS does not support cumsum op with int64 input
MPS で実行するには、PyTorch のバージョンが 2.0.1 ではまだ未対応なようです。そこで、Nightly バージョンの PyTorch と Torchvision をインストールします。
% pip uninstall torch torchvision
% pip install --upgrade --no-deps --force-reinstall --pre --index-url https://download.pytorch.org/whl/nightly/cpu torch torchvision
それでも次のメッセージが表示されますが、実行結果はされます。
You are using the legacy behaviour of the <class 'transformers.models.t5.tokenization_t5.T5Tokenizer'>. This means that tokens that come after special tokens will not be properly handled. We recommend you to read the related pull request available at https://github.com/huggingface/transformers/pull/24565
Xformers is not installed correctly. If you want to use memory_efficient_attention to accelerate training use the following command to install Xformers
pip install xformers.
Tokenizer に Legacy が使われているようなので、tokenizer の引数に legacy=False を追加します。
tokenizer = AutoTokenizer.from_pretrained("line-corporation/japanese-large-lm-3.6b", use_fast=False, legacy=False)
しかし、次のメッセージは残ります。
Xformers is not installed correctly. If you want to use memory_efficient_attention to accelerate training use the following command to install Xformers
pip install xformers.
xformers をインストールするように指示されるのですが、インストール時に次のエラーがでます。
ModuleNotFoundError: No module named 'torch'
note: This error originates from a subprocess, and is likely not a problem with pip.
まあ、実行結果が得られているので、とりあえずはこれで OK かな。
コメントする