MacBook ProでOpenELMを試してみる
Appleが公開した「オープンソースの効率的言語モデルのファミリー」らしいOpenELM。
mlx-lmを使用して、OpenELM-270M-Instructモデルを試してみます。
試したマシンは、MacBook Pro M3 Proチップ、メモリ18GBです。
1. 準備
venv構築
python3 -m venv openelm
cd $_
source bin/activate
パッケージのインストール
pip install mlx-lm
2. 流し込むコード
サンプルを参考にして作成したコードがこちら。
from mlx_lm import load, generate
model, tokenizer = load("mlx-community/OpenELM-270M-instruct")
def q(
user_query: str,
history: str=None
) -> str:
prompt=""
if history:
prompt=history
prompt+=user_query
#
response = generate(
model,
tokenizer,
prompt=prompt,
verbose=True,
max_tokens=512,
temp=0.0,
repetition_penalty=3.2
)
return prompt + response
3. 試してみる
では聞いてみましょう。
>>> history = q("ドラえもんとは")
==========
Prompt: ドラえもんとは
、å½¼女のæ情を調べることができます。
「ç§たちによって見つかりやしい気持ちだ」―(1928年代)ニューヨザク州大学生松村美子さん,写真:アイ・フォロワン/AFP/Getty Images
日本語版画像サウショット | NIKKOR Lenses for Japan (Nikkor lens catalogue): Nikkor Corporation Ltd. / AFP/Getty Images
新型コV-19発生中国é²衛局表示明らã今月30号以内期間全体地区へ行われなく自治制度再開性実装可能化研究会上任長官高田智雄氏向法院求め合意作成書列出来源公布した記者報道社Aichi Media Co.,Ltd.主張下一次展开時点
==========
Prompt: 115.357 tokens-per-sec
Generation: 174.886 tokens-per-sec
文字化けしていますね。英語で聞いてみましょう。
>>> history = q("Doraemon is ")
==========
Prompt: Doraemon is
10 years old, and it's time for a new generation.
The anime adaptation of the popular manga series by Keiichiro Tamaki has just been announced as part of Netflix' s "Doraemon: The Next Generation" lineup. This marks the first live-action installment in that franchise since its debut on TV screens in 1995. It will premiere this fall alongside another original animated feature from Studio Ghibli titled Ponyo!
Inspired by Japanese children's books written by Yukiyoshi Toriya (Alice Through The Looking Glass), which were adapted into movies starring Kazuki Hiraishi (Hellsing) and Masashi Konogu (Ghost In The Shell), Doraemon follows three young heroines named Rarity ("Rosie"), Squirtle ("Sparklez") and Digimon World boss Lapis Lovegood who must navigate their way through dangerous lands filled with evil monsters led by powerful villains known as Mewtwo, Megalon and Galarian Darkrai. Along the way they uncover clues to help them defeat these foes before facing off against rival forces intent on destroying human civilization.
Tamaki originally conceived of adapting his beloved story when he was still working at Toei Animation back in the day. He says about creating the show during those early days, "I wanted to tell stories based on my childhood experiences growing up in Japan." While some fans may not be too thrilled about seeing familiar characters return, others are excited to see what changes have been made within the animation department.
While many expectations remain high heading into Doraemon's release, there isn't much doubt that studio Ghibli knows how to deliver quality entertainment. Their previous works include films like Alice Through The looking Glass, Cinderella Mania, Chiroulette!, My Neighbor Totoro, Labyrinth Lord, Monster Squad, Spiral Chronicles, Wishes For Tomorrow and more recently DreamWorks Classics' Mulan and Beauty & The Beast.
==========
Prompt: 37.095 tokens-per-sec
Generation: 169.620 tokens-per-sec
Googleで翻訳した結果がこちら。
ふむ、なんか楽しそう。
4. まとめ
RTX 4090(24GB)では270Mで推論速度は50.63 トークン/秒でした。M3 Proですと174.886トークン/秒ですから、比較すると約3.4倍の速度です。