Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyouga committed Aug 9, 2024
1 parent c87023d commit 86f7099
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,10 @@ docker exec -it llamafactory bash

<details><summary>Details about volume</summary>

- hf_cache: Utilize Hugging Face cache on the host machine. Reassignable if a cache already exists in a different directory.
- data: Place datasets on this dir of the host machine so that they can be selected on LLaMA Board GUI.
- output: Set export dir to this location so that the merged result can be accessed directly on the host machine.
- `hf_cache`: Utilize Hugging Face cache on the host machine. Reassignable if a cache already exists in a different directory.
- `ms_cache`: Similar to Hugging Face cache but for ModelScope users.
- `data`: Place datasets on this dir of the host machine so that they can be selected on LLaMA Board GUI.
- `output`: Set export dir to this location so that the merged result can be accessed directly on the host machine.

</details>

Expand Down
7 changes: 4 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,10 @@ docker exec -it llamafactory bash

<details><summary>数据卷详情</summary>

- hf_cache:使用宿主机的 Hugging Face 缓存文件夹,允许更改为新的目录。
- data:宿主机中存放数据集的文件夹路径。
- output:将导出目录设置为该路径后,即可在宿主机中访问导出后的模型。
- `hf_cache`:使用宿主机的 Hugging Face 缓存文件夹,允许更改为新的目录。
- `ms_cache`:类似 Hugging Face 缓存文件夹,为 ModelScope 用户提供。
- `data`:宿主机中存放数据集的文件夹路径。
- `output`:将导出目录设置为该路径后,即可在宿主机中访问导出后的模型。

</details>

Expand Down
5 changes: 5 additions & 0 deletions examples/extras/pissa/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

python scripts/pissa_init.py \
--model_name_or_path meta-llama/Meta-Llama-3-8B-Instruct \
--output_dir models/llama3-8b-pissa
4 changes: 2 additions & 2 deletions scripts/cal_lr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def calculate_lr(
dataset_dir: str = "data",
template: str = "default",
cutoff_len: int = 1024, # i.e. maximum input length during training
is_mistral: bool = False, # mistral model uses a smaller learning rate,
is_mistral_or_gemma: bool = False, # mistral and gemma models opt for a smaller learning rate,
packing: bool = False,
):
r"""
Expand Down Expand Up @@ -84,7 +84,7 @@ def calculate_lr(
valid_ratio = valid_tokens / total_tokens
batch_valid_len = batch_max_len * valid_ratio
lr = BASE_LR * math.sqrt(batch_valid_len / BASE_BS) # lr ~ sqrt(batch_size)
lr = lr / 6.0 if is_mistral else lr
lr = lr / 6.0 if is_mistral_or_gemma else lr
print(
"Optimal learning rate is {:.2e} for valid ratio% {:.2f} and effective batch size {:.2f}".format(
lr, valid_ratio * 100, batch_valid_len
Expand Down
6 changes: 3 additions & 3 deletions scripts/llama_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import json
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

import fire
import torch
Expand Down Expand Up @@ -47,8 +47,8 @@ def block_expansion(
model_name_or_path: str,
output_dir: str,
num_expand: int,
shard_size: Optional[str] = "2GB",
save_safetensors: Optional[bool] = False,
shard_size: str = "2GB",
save_safetensors: bool = True,
):
r"""
Performs block expansion for LLaMA, Mistral, Qwen1.5 or Yi models.
Expand Down
7 changes: 5 additions & 2 deletions scripts/llamafy_baichuan2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json
import os
from collections import OrderedDict
from typing import Any, Dict, Optional
from typing import Any, Dict

import fire
import torch
Expand Down Expand Up @@ -86,7 +86,10 @@ def save_config(input_dir: str, output_dir: str):


def llamafy_baichuan2(
input_dir: str, output_dir: str, shard_size: Optional[str] = "2GB", save_safetensors: Optional[bool] = False
input_dir: str,
output_dir: str,
shard_size: str = "2GB",
save_safetensors: bool = True,
):
r"""
Converts the Baichuan2-7B model in the same format as LLaMA2-7B.
Expand Down
7 changes: 5 additions & 2 deletions scripts/llamafy_qwen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json
import os
from collections import OrderedDict
from typing import Any, Dict, Optional
from typing import Any, Dict

import fire
import torch
Expand Down Expand Up @@ -139,7 +139,10 @@ def save_config(input_dir: str, output_dir: str, torch_dtype: str):


def llamafy_qwen(
input_dir: str, output_dir: str, shard_size: Optional[str] = "2GB", save_safetensors: Optional[bool] = False
input_dir: str,
output_dir: str,
shard_size: str = "2GB",
save_safetensors: bool = False,
):
r"""
Converts the Qwen models in the same format as LLaMA2.
Expand Down
2 changes: 1 addition & 1 deletion scripts/pissa_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
def quantize_pissa(
model_name_or_path: str,
output_dir: str,
pissa_iter: int = 4,
pissa_iter: int = 16,
lora_alpha: int = None,
lora_rank: int = 16,
lora_dropout: float = 0,
Expand Down

0 comments on commit 86f7099

Please sign in to comment.