見出し画像

llama2.mojoを試す

超高速にllama2が推論できるというllama2.mojoなるものが登場したらしいので、早速試してみた。今朝はtokenizer.binがなくて試せなかったが、さっき見たら2時間前にtokenizer.binが追加されていた。

早速ためしてみる。
まずはデフォルトの15M版のstories

$ mojo llama2.mojo
num hardware threads:  36  SIMD vector width:  16
checkpoint size:  60816028
<s>
Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red ball in the sky. It was the sun! She thought it was so pretty.
Lily wanted to play with the ball, but it was too high up in the sky. She tried to jump and reach it, but she couldn't. Then, she had an idea. She would use a stick to knock the ball down.
Lily found a stick and tried to hit the ball. But the stick was too short. She tried again and again, but she couldn't reach it. She felt sad.
Suddenly, a kind man came by and saw Lily. He asked her what was wrong. Lily told him about the ball. The man smiled and said, "I have a useful idea!" He took out a long stick and used it to knock the ball down. Lily was so happy! She thanked the man and they played together in the sunshine.
<s>
Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red
achieved tok/s:  192.7437641723356

速い。192トークン/秒
できあがった物語を翻訳してみる

昔々、リリーという名前の小さな女の子がいました。彼女は太陽の光の下で外で遊ぶのが大好きでした。ある日、彼女は空に大きな赤い球を見つけました。それは太陽でした!彼女はそれがとてもきれいだと思いました。
リリーはボールで遊びたかったのですが、ボールは空の上にありすぎました。彼女はジャンプしてそこに到達しようとしましたが、できませんでした。そこで彼女はアイデアを思いつきました。彼女は棒を使ってボールを倒しました。
リリーはスティックを見つけてボールを打とうとしました。しかし、スティックが短すぎました。彼女は何度も何度も試みましたが、到達できませんでした。彼女は悲しくなった。
突然、親切な男性がやって来て、リリーに会いました。彼は彼女に何が問題なのか尋ねた。リリーは彼にボールについて話しました。その男は微笑んで、「役に立つアイデアがあるよ!」と言いました。彼は長い棒を取り出して、それを使ってボールを倒しました。リリーさんはとても嬉しかったです!彼女はその男に感謝し、二人は太陽の光の下で一緒に遊びました。
<s>
昔々、リリーという名前の小さな女の子がいました。彼女は太陽の光の下で外で遊ぶのが大好きでした。ある日、彼女は大きな、赤いものを見ました。

次に、110M版のstoriesを試してみる。

$ mojo llama2.mojo
num hardware threads:  36  SIMD vector width:  16
checkpoint size:  438381596
<s>
Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red apple on a tree. She wanted to eat it, but it was too high up.
Lily asked her friend, a little bird, "Can you help me get the apple?"
The bird said, "Sure, I can fly up and get it for you."
The bird flew up to the apple and pecked it off the tree. Lily was so happy and took a big bite. But then, she saw a bug on the apple. She didn't like bugs, so she threw the apple away.
Later that day, Lily's mom asked her to help with the laundry. Lily saw a shirt that was too big for her. She asked her mom, "Can you make it fit me?"
Her mom said, "Yes, I can make it fit you."
Lily was happy that her shirt would fit her. She learned that sometimes things don't fit, but there is always a way to make them fit.
<s>
Once upon a time, there was a little girl named Lily
achieved tok/s:  25.749772796122386

これでも25トークン/秒とまあまあ速い。

昔々、リリーという名前の小さな女の子がいました。彼女は太陽の光の下で外で遊ぶのが大好きでした。ある日、彼女は木の上に大きな赤いリンゴを見つけました。彼女はそれを食べたかったが、高すぎた。
リリーは友達の小鳥に「リンゴを取るのを手伝ってくれませんか?」と尋ねました。
鳥は「もちろん、飛んで行って捕まえることができます。」と言いました。
鳥はリンゴに飛んでいき、木からリンゴをつつきました。リリーはとても喜んで、たくさん食べました。しかしその後、彼女はリンゴに虫がいるのを見つけました。彼女は虫が嫌いだったので、リンゴを捨てました。
その日遅く、リリーの母親は彼女に洗濯を手伝うように頼んだ。リリーは自分には大きすぎるシャツを見ました。彼女は母親に「私に合うように作ってくれませんか?」と尋ねました。
彼女のお母さんは、「はい、あなたに合うように作ってあげますよ」と言いました。
リリーは自分のシャツが自分にぴったりだと喜んでいました。彼女は、物事が合わないこともありますが、必ず合うようにする方法があることを学びました。
<s>
昔々、リリーという名の小さな女の子がいました。

棒でりんごを取ろうとする原始人的な話から、小鳥の友達にお願いするという話にバージョンアップした。

これ、GPU使ってないのかな。使ってなさそうに見えるが
GPUなしでこのスピードで生成できるのはすごいな。まあモデルが十分小さいけど。llama2.cのところでも触れられているが、ドメインを十分絞れば小さいモデルでもかなりいい結果が出るのだそう。