0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

#73 Fugaku-LLMをローカルで動作させてみた

Posted at

概要

2024年5月10日にスーパコンピュータの富岳を学習に用いた大規模言語モデルの「Fugaku-LLM」が発表されました

(https://pr.fujitsu.com/jp/news/2024/05/10.html)

今回の記事ではこの「Fugaku-LLM」をローカルマシンで動作させ、Discord上から動かしてみたいと思います

環境構築

1. Ollamaのインストール

Ollamaは大規模言語モデルををローカルで動かすためのツールです
こちらのページ( https://ollama.com/download/windows )から環境に合わせてダウンロードし、インストールします

※今回の記事ではWindows環境を前提とします

2.(必要な場合)CUDAのインストール

お使いのPCにnvidia製のGPUが搭載されている場合は、CUDAをインストールします
( https://developer.nvidia.com/cuda-downloads )

動作チェックする①

コマンドプロンプトで

ollama run nebel/fugaku-llm:13b-instruct

と入力すると自動的にFygaku-LLMのダウンロードと起動が行われます

>>> Send a message (/? for help)

このように表示されたら成功です。適当に質問をしてみて答えが返ってくるか確認しましょう

動作チェックする②

任意のブラウザでhttp://localhost:11434にアクセスし、Ollama is runningと表示されればWebAPI経由で操作することができます

Discordで動かす

基本となるコードは、以前の記事をベースとして作成します

以前のコードの//メッセージをOpenAIのAPIに渡せる形に成型するから//返信までを改修します

実装

  • 今回は192.168.1.2が割り当てられているマシンでFugaku-LLMを動作させています
  • node-fetchを用いてWebAPIを叩きます
    • ollamaのAPIのドキュメントはこちら
    //メッセージをOllamaのAPIに渡せる形に成型する
    const messages: { role: "assistant" | "user", content: string }[] = new Array();
    for (let message of messagesCollection) {
        const role = ((message[1].author.id == client.user?.id) ? "assistant" : "user");
        messages.push(
            {
                role: role,
                content: message[1].content
            }
        );
    }
    logger.debug(messages);

    const body = JSON.stringify({
        model: "fugaku-llm-13b-instruct",
        messages: messages,
        stream: false
    });

    //APIにメッセージを投げて返答を抽出
    const response = await fetch("http://192.168.1.2:11434/api/chat", {
        method: 'POST',
        body: body
    });

    const content = JSON.parse(await response.text());
    if (!content.message.content) {
        return;
    }

    //返信
    message.reply(content.message.content);

動作確認

以下のコマンドを実行し、Discord上でメッセージを送信すると、画像のように返信してくれることを確認します

$ npx ts-node ./src/main.ts

image.png

まとめ

今回は大規模言語モデルをローカルで動作させ、Discord上で操作してみました

日本で開発されたLLMということで日本語性能に期待していましたが、サイボーグを自称したりと回答としてやや不安な面があることがわかりました

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?