Overview

I had the opportunity to run a local LLM using mdx.jp’s 1GPU pack and Ollama, so this is a memo of the process.

https://mdx.jp/mdx1/p/guide/charge

References

I referred to the following article.

https://highreso.jp/edgehub/machinelearning/ollamainference.html

Downloading the Model

Here, we target llama3.1:70b.

After the download is complete, it becomes selectable as shown below.

Usage Example

We use the following “Shibusawa Eiichi Biographical Materials.”

https://github.com/shibusawa-dlab/lab1

Using the API

Documentation was found at the following location.

https://docs.openwebui.com/api/

Issue an API key separately from the JWT token as shown below.

Here is an execution example.

import requests
import json

text = '''六月十四日 日 晴 風ナクシテ暑気昨日ニ比シテ少ク加フルヲ覚フ
朝来少シク風邪気ナルニヨリ晏起、 八時 洗面ヲナス、後、六孫王宮ノ神官又ハ同志社員 安藤 氏等来訪ス、 十時 大阪支店長 野口 、 神戸 杉田 、 名古屋 清水 及 西京 支店長 中川 、其他 小林 、 片野 、 前原 等ノ諸氏ヲ伴ヒ 嵐山 ニ抵リ、三軒屋ニテ午飧シ、船ヲ浮ヘテ大江川《(堰)》ヲ遡ル、船中囲碁ノ興アリ、 嵐山 ノ緑葉少シク繁茂ニ過ルモ両岸ニハ山花咲乱レテ頗ル風致アリ、 午後四時 過 玉川楼 ニ帰宿ス、今朝、 尾崎 司法大臣ノ秘書 黒田 氏来ル、又、 林 和太郎 氏( 桂 氏ノ父)来話ス、 午前十時 ヨリ各支店主任ト共ニ 嵐山 ニ抵リ三軒屋ニテ午飧ス、後、大江川《(大堰川)》ニ船ヲ浮ヘ、 午後四時 帰宿ス、後、 玉川楼 ニ於テ晩飧会ヲ開ク、種々ノ余興アリ、夜 十時 散会ス、 中井 三郎兵衛 氏モ来会ス'''

APIKEY = "sk-xxxx"

url = "http://localhost:8080/api/chat/completions"
headers = {
    "Authorization": f"Bearer {APIKEY}",
    "Content-Type": "application/json"
}

thres = 300

data = {
    "model": "llama3.1:70b",
    "messages": [
        {
            "role": "user",
            "content": f"次のテキストは渋沢栄一の日記の一部です。テキストを{thres}字程度に要約してください。要約文のみを改行せずに返してください。句読点を適宜使用してください。\n\n{text}"
        }
    ]
}

response = requests.post(url, headers=headers, data=json.dumps(data))

# Display the response
print(response.status_code)
print(response.json())

As a result, the following was obtained. However, it took nearly 60 seconds for the result to be returned.

{
	'id': 'llama3.1 : 70b-44254f46-0f3f-40c1-933c-b0642d978ef2',
	 'created': 1730671173,
	 'model': 'llama3.1 : 70b',
	 'choices': [
		{
			'index': 0,
			 'logprobs': None,
			 'finish_reason': 'stop',
			 'message': {
				'content': '六月十四日は晴れで風がなくて暑かった。朝は少し風邪気がありましたが、8時に洗面をし、その後6人の王宮の神官や同志社の安藤氏などが来訪しました。その後、大阪支店長の野口氏や神戸・名古屋支店長などの諸氏と共に嵐山に着き、三軒屋で昼食を取り、船を浮かべて大江川を遡りました。船の中では囲碁をするなど楽しく過ごしました。嵐山の緑葉は少し少なくて繁茂していませんでしたが、両岸には山花が咲き乱れて風景がよかったです。午後4時すぎに玉川楼に帰宿し、その後尾崎司法大臣の秘書黒田氏や林和太郎氏(桂氏の父)が来て話をしました。午前10時から各支店主任と共に嵐山に着き、三軒屋で昼食を取り、大江川に船を浮かべて遡りました。午後4時に帰宿し、その後玉川楼で晩酌会を開き、種々の余興もありました。夜10時すぎに散会しましたが、中井三郎兵衛氏も来てくれました。',
				 'role': 'assistant'
			}
		}
	],
	 'object': 'chat.completion'
}

June 14th was sunny with no wind and it was hot. I had a slight cold in the morning, but washed my face at 8 o’clock, after which officials from the Rokusonno Shrine and Mr. Ando from Doshisha visited. Then, together with Osaka branch manager Mr. Noguchi, Kobe and Nagoya branch managers and others, we went to Arashiyama, had lunch at Sangenya, and rowed a boat up the Oi River. We enjoyed playing Go on the boat. The green foliage at Arashiyama was slightly sparse, but mountain flowers bloomed in profusion on both banks, making for beautiful scenery. We returned to Tamagawa-ro after 4 PM. Secretary Kuroda of Justice Minister Ozaki and Mr. Hayashi Wataro (father of Mr. Katsura) came to visit. From 10 AM, together with branch managers, we went to Arashiyama, had lunch at Sangenya, and rowed a boat on the Oi River. We returned at 4 PM, then held a dinner party at Tamagawa-ro with various entertainments. The gathering ended at 10 PM, with Mr. Nakai Sarobei also attending.

When changing the model to llama3.1:latest (8.0B), the result was returned in about 6 seconds.

(The 8B model output was less natural in Japanese compared to the 70B model.)

While it takes more time, the llama3.1:70b (70.6B) model seems to produce more natural Japanese.

Summary

I ran a local LLM using mdx.jp’s 1GPU pack and Ollama.

I hope this serves as a helpful reference for using local LLMs.