Unsloth Studio

Unsloth StudioはWebブラウザでローカルLLMを使うための仕組みです。

インストールは、LinuxやMacではターミナルに次のように打ち込むだけです:

curl -fsSL https://unsloth.ai/install.sh | sh

すると、Macなら次のようなメッセージが現れます:

  🦥 Unsloth Studio Installer
  ────────────────────────────────────────────────────

  platform       macos
  deps           all system dependencies found
                 preserving existing environment for rollback...
                 previous environment preserved for rollback
  venv           creating Python 3.13 virtual environment
                 /Users/okumura/.unsloth/studio/unsloth_studio
  venv           using environment
                 /Users/okumura/.unsloth/studio/unsloth_studio
  gpu            none (CPU-only)
                 installing PyTorch (https://download.pytorch.org/whl/cpu)...
                 installing unsloth (this may take a few minutes)...
  setup          running unsloth studio update...

  🦥 Unsloth Studio Setup
  ────────────────────────────────────────────────────
  frontend       up to date
  deps           [====================]  9/9  finalizing
  deps           installed
  transformers   5.3.0 pre-installed
  transformers   5.5.0 pre-installed
  gpu            none (chat-only / GGUF)
                 Training and GPU inference require an NVIDIA or AMD ROCm GPU.
                 installing prebuilt llama.cpp...
                 existing install detected -- validating update
  llama.cpp      prebuilt installed and validated
                 installed release: ggml-org/llama.cpp@b9496
  ────────────────────────────────────────────────────
  Unsloth Studio Installed
  ────────────────────────────────────────────────────
  launch         unsloth studio -p 8888
                 (add -H 0.0.0.0 to allow network / cloud access)

                 Created Unsloth Studio shortcut

  Unsloth Studio installed!
  ────────────────────────────────────────────────────


  Start Unsloth Studio now? [Y/n]

ここで Y と打てばサーバが起動します。

  launch         starting Unsloth Studio...
Starting Unsloth Studio on http://127.0.0.1:8888
[OK] Frontend loaded from /Users/okumura/.unsloth/studio/unsloth_studio/lib/python3.13/site-packages/studio/frontend/dist
INFO:     Started server process [30521]
INFO:     Waiting for application startup.
Hardware detected: MLX — Apple Silicon (arm64)
INFO:     Application startup complete.
INFO:     Unsloth Studio running on http://127.0.0.1:8888 (To stop: press Ctrl+C -- on macOS, Control+C not Command+C)

🦥 Unsloth Studio is running
────────────────────────────────────────────────────
  On this machine -- open this in your browser:
    http://127.0.0.1:8888
    (same as http://localhost:8888)

  API & health:
    http://127.0.0.1:8888/api
    http://127.0.0.1:8888/api/health
────────────────────────────────────────────────────
  Tip: if you are on this computer, open http://localhost:8888/ in your browser.

  Studio is only reachable on this machine (bound to 127.0.0.1).
  To deploy and access globally:
    1. press Ctrl+C to stop Studio
    2. relaunch with:  unsloth studio -H 0.0.0.0 -p 8888
  Only do this on trusted networks -- it exposes the API on every interface.

  To stop Unsloth Studio: press Ctrl+C in this terminal.
  (On macOS this is Control+C, not Command+C.)
────────────────────────────────────────────────────

ブラウザで http://127.0.0.1:8888/ をひらけばUnsloth Studioの画面が現れます。最初はパスワードの設定を促されます。

Select model... からお好きなモデルを選んで実行してみましょう。

APIも使えるようになりました。設定の「API」で、適当なトークン名を入れ、「Create token」すると、sk-unsloth-XXXXXX のようなトークンが発行されます。これを使って、例えばEmacsのgptelであれば

(setq gptel-backend
      (gptel-make-openai "unsloth"
        :key "sk-unsloth-XXXXXX"
	:protocol "http"
	:host "localhost:8888"
	:models '((current))
	:stream t))

のように設定すれば使えます。Pythonからも

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8888/v1",
    api_key="sk-unsloth-XXXXXX",
)

response = client.chat.completions.create(
    model="current",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in response:
    print(chunk.choices[0].delta.content or "", end="")

で使えるはずです。

終了は、先ほどのターミナルで Ctrl-C を打ちます。

次に起動するには、ターミナルに次のように打ち込みます:

unsloth studio -p 8888

あるいは、他のマシンからもアクセスしたい場合は、次のように打ち込みます:

unsloth studio -H 0.0.0.0 -p 8888

いずれの場合も、コマンドの最後に & を付ければ、バックグラウンドでの起動になります。途中からバックグラウンドに切り替えたい場合は Ctrl-Z を打ってから bg と打ちます。

更新はターミナルに次のように打ち込めばいいはずです:

unsloth studio update

ところがMacではうまくいかないことがあるようで、Unslothのサポートによれば再インストールの方が確実だということです。