fix
This commit is contained in:
parent
4157ac2e36
commit
791badcbe1
88
lang/ja.md
88
lang/ja.md
@ -32,3 +32,91 @@ webからはatprotoを通じて実行されます。
|
||||
- https://github.com/comfyanonymous/comfyui
|
||||
- https://github.com/stability-ai/stablediffusion
|
||||
|
||||
## LoRA
|
||||
|
||||
apple siliconでLoRA(finetuning)するには`mlx_lm`を使用します。
|
||||
|
||||
```sh
|
||||
# https://ai.google.dev/gemma/docs/core/lora_tuning
|
||||
$ conda create -n finetuning python=3.12
|
||||
$ conda activate finetuning
|
||||
$ pip install mlx-lm #apple silicon
|
||||
$ ollama run llama3.2:1b
|
||||
$ echo "{ \"model\": \"https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct\", \"data\": \"https://github.com/ml-explore/mlx-examples/tree/main/lora/data\" }"|jq .
|
||||
$ model=meta-llama/Llama-3.2-1B-Instruct
|
||||
$ data=ml-explore/mlx-examples/lora/data
|
||||
$ mlx_lm.lora --train --model $model --data $data --batch-size 3
|
||||
|
||||
$ ls adapters
|
||||
$ vim Modelfile
|
||||
FROM llama3.2:1b
|
||||
ADAPTER ./adapters
|
||||
|
||||
$ ollama create ai -f ./Modelfile
|
||||
```
|
||||
|
||||
## unsloth
|
||||
|
||||
windowsでgemma3をunslothしてcustom modelを作成します。
|
||||
|
||||
```sh
|
||||
$ nvidia-smi
|
||||
$ nvcc --version
|
||||
CUDA Version: 12.8
|
||||
|
||||
$ pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
|
||||
```
|
||||
|
||||
```sh
|
||||
# https://docs.unsloth.ai/get-started/installing-+-updating/windows-installation
|
||||
$ conda create -n finetuning python=3.12
|
||||
$ conda activate finetuning
|
||||
$ conda install -c nvidia cuda cudnn
|
||||
$ ollama pull gemma3:12b
|
||||
|
||||
# pip install unsloth
|
||||
$ pip install "unsloth[windows] @ git+https://github.com/unslothai/unsloth.git"
|
||||
$ vim custom.py
|
||||
```
|
||||
|
||||
```py
|
||||
from unsloth import FastLanguageModel
|
||||
|
||||
# モデルとトークナイザーの読み込み
|
||||
model, tokenizer = FastLanguageModel.from_pretrained(
|
||||
model_name = "google/gemma-12b",
|
||||
max_seq_length = 2048,
|
||||
dtype = None,
|
||||
load_in_4bit = True,
|
||||
)
|
||||
|
||||
# LoRA設定
|
||||
model = FastLanguageModel.get_peft_model(
|
||||
model,
|
||||
r = 16,
|
||||
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj"],
|
||||
lora_alpha = 16,
|
||||
lora_dropout = 0,
|
||||
bias = "none",
|
||||
use_gradient_checkpointing = "unsloth",
|
||||
)
|
||||
|
||||
model.save_pretrained("gemma3-custom")
|
||||
|
||||
# Modelfile作成
|
||||
with open("Modelfile", "w") as f:
|
||||
f.write(f"""
|
||||
FROM gemma3:12b
|
||||
ADAPTER ./gemma3-custom
|
||||
PARAMETER temperature 0.7
|
||||
PARAMETER stop <|endoftext|>
|
||||
""")
|
||||
```
|
||||
|
||||
AI modelの名前は`ai`とします。
|
||||
|
||||
```sh
|
||||
$ ollama create ai -f .\Modelfile
|
||||
$ ollama run ai
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user