Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する

Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する手順を紹介します。

概要

Stability AI Japan により日本語のLLMモデル、Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) が提供されました。 Text generation web UIでこのモデルを実行してみます。

手順

モデルのダウンロード

Hugging Faceのjapanese-stablelm-instruct-alpha-7bのHub (https://huggingface.co/stabilityai/japanese-stablelm-instruct-alpha-7b)にアクセスします。

Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像1

[Files and versions]のタブをクリックします。下図のページが表示されます。ファイルの一覧が表示されますので、 すべてのファイルをダウンロードします。(fp16, int8を利用しない場合は、fp16やint8のファイルは不要です。)
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像2

なお、ログインしていない場合は、ログインしてライセンス規約に同意する必要があります。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像3
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像4

Tokenizerのダウンロード

Tokenizerをダウンロードします。今回はnerdstash-tokenizer-v1を利用します。
Hugging FaceのHubのページ(https://huggingface.co/NovelAI/nerdstash-tokenizer-v1)にアクセスします。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像5

[Files and versions]のタブをクリックます。下図のページが表示されます。ファイル一覧が表示されます。special_tokens_map.json, tokenizer.model, tokenizer_config.json をダウンロードします。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像6

ファイルの配置

モデルファイルとTokenizerのファイルを以下のディレクトリに配置します。

(WebUIの配置ディレクトリ)\text-generation-webui¥models\stabilityai_japanese-stablelm-instruct-alpha-7b

Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像7

Hugging Face トークンの取得

Hugging Faceのトークンを取得します。手順はこちらの記事を参照してください。

Hugging Face ログインの設定

start_windows.bat に 次のhuggingface-cli.exe を実行するコマンドを記述し、WebUI 起動時にHugging Faceにログインした状態にします。

.\installer_files\env\Scripts\huggingface-cli.exe login --token (Hagging Faceのトークン)
補足
huggingface-cli.exe loginコマンドは1回実行するだけでよいかもしれません。(未検証)

start_windows.bat (修正後)
@echo off

@rem この行を追加
.\installer_files\env\Scripts\huggingface-cli.exe login --token hf_****************************

cd /D "%~dp0"

set PATH=%PATH%;%SystemRoot%\system32

echo "%CD%"| findstr /C:" " >nul && echo This script relies on Miniconda which can not be silently installed under a path with spaces. && goto end

@rem Check for special characters in installation path
set "SPCHARMESSAGE="WARNING: Special characters were detected in the installation path!" "         This can cause the installation to fail!""
echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~]" >nul && (
	call :PrintBigMessage %SPCHARMESSAGE%
)
set SPCHARMESSAGE=

@rem fix failed install when installing to a separate drive
set TMP=%cd%\installer_files
set TEMP=%cd%\installer_files

@rem config
set INSTALL_DIR=%cd%\installer_files
set CONDA_ROOT_PREFIX=%cd%\installer_files\conda
set INSTALL_ENV_DIR=%cd%\installer_files\env
set MINICONDA_DOWNLOAD_URL=https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Windows-x86_64.exe
set conda_exists=F

@rem figure out whether git and conda needs to be installed
call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
if "%ERRORLEVEL%" EQU "0" set conda_exists=T

@rem (if necessary) install git and conda into a contained environment
@rem download conda
if "%conda_exists%" == "F" (
	echo Downloading Miniconda from %MINICONDA_DOWNLOAD_URL% to %INSTALL_DIR%\miniconda_installer.exe

	mkdir "%INSTALL_DIR%"
	call curl -Lk "%MINICONDA_DOWNLOAD_URL%" > "%INSTALL_DIR%\miniconda_installer.exe" || ( echo. && echo Miniconda failed to download. && goto end )

	echo Installing Miniconda to %CONDA_ROOT_PREFIX%
	start /wait "" "%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%CONDA_ROOT_PREFIX%

	@rem test the conda binary
	echo Miniconda version:
	call "%CONDA_ROOT_PREFIX%\_conda.exe" --version || ( echo. && echo Miniconda not found. && goto end )
)

@rem create the installer env
if not exist "%INSTALL_ENV_DIR%" (
	echo Packages to install: %PACKAGES_TO_INSTALL%
	call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" python=3.10 || ( echo. && echo Conda environment creation failed. && goto end )
)

@rem check if conda environment was actually created
if not exist "%INSTALL_ENV_DIR%\python.exe" ( echo. && echo Conda environment is empty. && goto end )

@rem environment isolation
set PYTHONNOUSERSITE=1
set PYTHONPATH=
set PYTHONHOME=
set "CUDA_PATH=%INSTALL_ENV_DIR%"
set "CUDA_HOME=%CUDA_PATH%"

@rem activate installer env
call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end )

@rem setup installer env
call python webui.py

@rem below are functions for the script   next line skips these during normal execution
goto end

:PrintBigMessage
echo. && echo.
echo *******************************************************************
for %%M in (%*) do echo * %%~M
echo *******************************************************************
echo. && echo.
exit /b

:end
pause

WebUIの起動とモデルの読み込み

start_windows.batを実行し、WebUIを起動します。画面上部の[Model]タブをクリックします。下図の画面が表示されます。
画面左上の[Model]のドロップダウンリストボックスをクリックします。 ドロップダウンリストから"stabilityai_japanese-stablelm-instruct-alpha-7b" の項目をクリックして選択します。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像8

選択後、[trust-remote-code]のチェックボックスをクリックしてチェックをつけます。 チェック後[Model]ドロップダウンリストの右側の[Load]ボタンをクリックします。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像9

モデルの読み込みが実行されます。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像10

モデルの読み込みが成功しました。
Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像11

実行

Chat画面に切り替えて、日本語で会話をしてみます。入力に対して返答があります。 Text generation web UIで Japanese StableLM Instruct Alpha 7B (japanese-stablelm-instruct-alpha-7b) を実行する:画像12

エラーの対処

以下のエラーメッセージが表示された場合は、[trust-remote-code] にチェックがついていない場合があります。

エラーメッセージ
ValueError: Loading models\stabilityai_japanese-stablelm-instruct-alpha-7b requires you to execute the configuration file in that repo on your local machine. Make sure you have read the code there to avoid malicious use, then set the option trust_remote_code=True to remove this error.


以下のエラーが発生した場合は、Hugging Faceにログインできていないため、以下の huggingface-cli.exe コマンドを実行します。

(WebUIの配置ディレクトリ)\installer_files\env\Scripts\huggingface-cli.exe login --token (Hagging Faceのトークン)


エラーメッセージ
OSError: You are trying to access a gated repo.\nMake sure to request access at "https://huggingface.co/stabilityai/japanese-stablelm-instruct-alpha-7b" and pass a token having permission to this repo either by logging in with huggingface-cli login or by passing token=<your_token>
AuthorPortraitAlt
著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
作成日: 2023-09-20
Copyright © 1995–2025 iPentec all rights reserverd.