Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
LLaMA-Factory
Commits
84987715
Commit
84987715
authored
Apr 07, 2025
by
chenych
Browse files
update to v0.9.2
parent
317a82e2
Changes
58
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
125 additions
and
43 deletions
+125
-43
src/llamafactory/train/test_utils.py
src/llamafactory/train/test_utils.py
+4
-3
src/llamafactory/train/trainer_utils.py
src/llamafactory/train/trainer_utils.py
+1
-0
src/llamafactory/train/tuner.py
src/llamafactory/train/tuner.py
+6
-2
src/llamafactory/webui/locales.py
src/llamafactory/webui/locales.py
+22
-0
tests/data/processor/test_feedback.py
tests/data/processor/test_feedback.py
+2
-3
tests/data/processor/test_pairwise.py
tests/data/processor/test_pairwise.py
+2
-3
tests/data/processor/test_supervised.py
tests/data/processor/test_supervised.py
+9
-8
tests/data/processor/test_unsupervised.py
tests/data/processor/test_unsupervised.py
+2
-3
tests/data/test_converter.py
tests/data/test_converter.py
+14
-0
tests/data/test_loader.py
tests/data/test_loader.py
+56
-0
tests/e2e/test_train.py
tests/e2e/test_train.py
+0
-1
tests/model/model_utils/test_checkpointing.py
tests/model/model_utils/test_checkpointing.py
+0
-1
tests/model/model_utils/test_visual.py
tests/model/model_utils/test_visual.py
+7
-14
tests/model/test_freeze.py
tests/model/test_freeze.py
+0
-1
tests/model/test_full.py
tests/model/test_full.py
+0
-1
tests/model/test_lora.py
tests/model/test_lora.py
+0
-1
tests/model/test_pissa.py
tests/model/test_pissa.py
+0
-1
tests/train/test_sft_trainer.py
tests/train/test_sft_trainer.py
+0
-1
No files found.
src/llamafactory/train/test_utils.py
View file @
84987715
...
@@ -26,10 +26,11 @@ from ..model import load_model, load_tokenizer
...
@@ -26,10 +26,11 @@ from ..model import load_model, load_tokenizer
if
TYPE_CHECKING
:
if
TYPE_CHECKING
:
from
datasets
import
Dataset
from
peft
import
LoraModel
from
peft
import
LoraModel
from
transformers
import
PreTrainedModel
from
transformers
import
PreTrainedModel
from
..data.data_utils
import
DatasetModule
def
compare_model
(
model_a
:
"torch.nn.Module"
,
model_b
:
"torch.nn.Module"
,
diff_keys
:
Sequence
[
str
]
=
[])
->
None
:
def
compare_model
(
model_a
:
"torch.nn.Module"
,
model_b
:
"torch.nn.Module"
,
diff_keys
:
Sequence
[
str
]
=
[])
->
None
:
state_dict_a
=
model_a
.
state_dict
()
state_dict_a
=
model_a
.
state_dict
()
...
@@ -101,12 +102,12 @@ def load_reference_model(
...
@@ -101,12 +102,12 @@ def load_reference_model(
return
model
return
model
def
load_
train_
dataset
(
**
kwargs
)
->
"Dataset"
:
def
load_dataset
_module
(
**
kwargs
)
->
"Dataset
Module
"
:
model_args
,
data_args
,
training_args
,
_
,
_
=
get_train_args
(
kwargs
)
model_args
,
data_args
,
training_args
,
_
,
_
=
get_train_args
(
kwargs
)
tokenizer_module
=
load_tokenizer
(
model_args
)
tokenizer_module
=
load_tokenizer
(
model_args
)
template
=
get_template_and_fix_tokenizer
(
tokenizer_module
[
"tokenizer"
],
data_args
)
template
=
get_template_and_fix_tokenizer
(
tokenizer_module
[
"tokenizer"
],
data_args
)
dataset_module
=
get_dataset
(
template
,
model_args
,
data_args
,
training_args
,
kwargs
[
"stage"
],
**
tokenizer_module
)
dataset_module
=
get_dataset
(
template
,
model_args
,
data_args
,
training_args
,
kwargs
[
"stage"
],
**
tokenizer_module
)
return
dataset_module
[
"train_dataset"
]
return
dataset_module
def
patch_valuehead_model
()
->
None
:
def
patch_valuehead_model
()
->
None
:
...
...
src/llamafactory/train/trainer_utils.py
View file @
84987715
...
@@ -617,6 +617,7 @@ def get_swanlab_callback(finetuning_args: "FinetuningArguments") -> "TrainerCall
...
@@ -617,6 +617,7 @@ def get_swanlab_callback(finetuning_args: "FinetuningArguments") -> "TrainerCall
experiment_name
=
finetuning_args
.
swanlab_run_name
,
experiment_name
=
finetuning_args
.
swanlab_run_name
,
mode
=
finetuning_args
.
swanlab_mode
,
mode
=
finetuning_args
.
swanlab_mode
,
config
=
{
"Framework"
:
"🦙LlamaFactory"
},
config
=
{
"Framework"
:
"🦙LlamaFactory"
},
logdir
=
finetuning_args
.
swanlab_logdir
,
)
)
return
swanlab_callback
return
swanlab_callback
...
...
src/llamafactory/train/tuner.py
View file @
84987715
...
@@ -86,6 +86,9 @@ def _training_function(config: Dict[str, Any]) -> None:
...
@@ -86,6 +86,9 @@ def _training_function(config: Dict[str, Any]) -> None:
def
run_exp
(
args
:
Optional
[
Dict
[
str
,
Any
]]
=
None
,
callbacks
:
Optional
[
List
[
"TrainerCallback"
]]
=
None
)
->
None
:
def
run_exp
(
args
:
Optional
[
Dict
[
str
,
Any
]]
=
None
,
callbacks
:
Optional
[
List
[
"TrainerCallback"
]]
=
None
)
->
None
:
args
=
read_args
(
args
)
args
=
read_args
(
args
)
if
"-h"
in
args
or
"--help"
in
args
:
get_train_args
(
args
)
ray_args
=
get_ray_args
(
args
)
ray_args
=
get_ray_args
(
args
)
callbacks
=
callbacks
or
[]
callbacks
=
callbacks
or
[]
if
ray_args
.
use_ray
:
if
ray_args
.
use_ray
:
...
@@ -182,6 +185,7 @@ def export_model(args: Optional[Dict[str, Any]] = None) -> None:
...
@@ -182,6 +185,7 @@ def export_model(args: Optional[Dict[str, Any]] = None) -> None:
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
warning_rank0
(
f
"Cannot save tokenizer, please copy the files manually:
{
e
}
."
)
logger
.
warning_rank0
(
f
"Cannot save tokenizer, please copy the files manually:
{
e
}
."
)
with
open
(
os
.
path
.
join
(
model_args
.
export_dir
,
"Modelfile"
),
"w"
,
encoding
=
"utf-8"
)
as
f
:
ollama_modelfile
=
os
.
path
.
join
(
model_args
.
export_dir
,
"Modelfile"
)
with
open
(
ollama_modelfile
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
template
.
get_ollama_modelfile
(
tokenizer
))
f
.
write
(
template
.
get_ollama_modelfile
(
tokenizer
))
logger
.
info_rank0
(
f
"
Saved o
llama modelfile
to
{
model_args
.
export_dir
}
.
"
)
logger
.
info_rank0
(
f
"
O
llama modelfile
saved in
{
ollama_modelfile
}
"
)
src/llamafactory/webui/locales.py
View file @
84987715
...
@@ -1894,6 +1894,28 @@ LOCALES = {
...
@@ -1894,6 +1894,28 @@ LOCALES = {
"info"
:
"クラウド版またはオフライン版 SwanLab を使用します。"
,
"info"
:
"クラウド版またはオフライン版 SwanLab を使用します。"
,
},
},
},
},
"swanlab_logdir"
:
{
"en"
:
{
"label"
:
"SwanLab log directory"
,
"info"
:
"The log directory for SwanLab."
,
},
"ru"
:
{
"label"
:
"SwanLab 로그 디렉토리"
,
"info"
:
"SwanLab의 로그 디렉토리."
,
},
"zh"
:
{
"label"
:
"SwanLab 日志目录"
,
"info"
:
"SwanLab 的日志目录。"
,
},
"ko"
:
{
"label"
:
"SwanLab 로그 디렉토리"
,
"info"
:
"SwanLab의 로그 디렉토리."
,
},
"ja"
:
{
"label"
:
"SwanLab ログ ディレクトリ"
,
"info"
:
"SwanLab のログ ディレクトリ。"
,
},
},
"cmd_preview_btn"
:
{
"cmd_preview_btn"
:
{
"en"
:
{
"en"
:
{
"value"
:
"Preview command"
,
"value"
:
"Preview command"
,
...
...
tests/data/processor/test_feedback.py
View file @
84987715
...
@@ -20,7 +20,7 @@ from datasets import load_dataset
...
@@ -20,7 +20,7 @@ from datasets import load_dataset
from
transformers
import
AutoTokenizer
from
transformers
import
AutoTokenizer
from
llamafactory.extras.constants
import
IGNORE_INDEX
from
llamafactory.extras.constants
import
IGNORE_INDEX
from
llamafactory.train.test_utils
import
load_
train_
dataset
from
llamafactory.train.test_utils
import
load_dataset
_module
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
...
@@ -36,7 +36,6 @@ TRAIN_ARGS = {
...
@@ -36,7 +36,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
8192
,
"cutoff_len"
:
8192
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
@@ -45,7 +44,7 @@ TRAIN_ARGS = {
...
@@ -45,7 +44,7 @@ TRAIN_ARGS = {
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
def
test_feedback_data
(
num_samples
:
int
):
def
test_feedback_data
(
num_samples
:
int
):
train_dataset
=
load_
train_
dataset
(
**
TRAIN_ARGS
)
train_dataset
=
load_dataset
_module
(
**
TRAIN_ARGS
)
[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"kto_en_demo"
,
split
=
"train"
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"kto_en_demo"
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
...
tests/data/processor/test_pairwise.py
View file @
84987715
...
@@ -21,7 +21,7 @@ from datasets import load_dataset
...
@@ -21,7 +21,7 @@ from datasets import load_dataset
from
transformers
import
AutoTokenizer
from
transformers
import
AutoTokenizer
from
llamafactory.extras.constants
import
IGNORE_INDEX
from
llamafactory.extras.constants
import
IGNORE_INDEX
from
llamafactory.train.test_utils
import
load_
train_
dataset
from
llamafactory.train.test_utils
import
load_dataset
_module
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
...
@@ -37,7 +37,6 @@ TRAIN_ARGS = {
...
@@ -37,7 +37,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
8192
,
"cutoff_len"
:
8192
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
@@ -55,7 +54,7 @@ def _convert_sharegpt_to_openai(messages: List[Dict[str, str]]) -> List[Dict[str
...
@@ -55,7 +54,7 @@ def _convert_sharegpt_to_openai(messages: List[Dict[str, str]]) -> List[Dict[str
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
def
test_pairwise_data
(
num_samples
:
int
):
def
test_pairwise_data
(
num_samples
:
int
):
train_dataset
=
load_
train_
dataset
(
**
TRAIN_ARGS
)
train_dataset
=
load_dataset
_module
(
**
TRAIN_ARGS
)
[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"dpo_en_demo"
,
split
=
"train"
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"dpo_en_demo"
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
...
tests/data/processor/test_supervised.py
View file @
84987715
...
@@ -20,7 +20,7 @@ from datasets import load_dataset
...
@@ -20,7 +20,7 @@ from datasets import load_dataset
from
transformers
import
AutoTokenizer
from
transformers
import
AutoTokenizer
from
llamafactory.extras.constants
import
IGNORE_INDEX
from
llamafactory.extras.constants
import
IGNORE_INDEX
from
llamafactory.train.test_utils
import
load_
train_
dataset
from
llamafactory.train.test_utils
import
load_dataset
_module
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
...
@@ -36,7 +36,6 @@ TRAIN_ARGS = {
...
@@ -36,7 +36,6 @@ TRAIN_ARGS = {
"finetuning_type"
:
"full"
,
"finetuning_type"
:
"full"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
8192
,
"cutoff_len"
:
8192
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
@@ -45,7 +44,7 @@ TRAIN_ARGS = {
...
@@ -45,7 +44,7 @@ TRAIN_ARGS = {
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
def
test_supervised_single_turn
(
num_samples
:
int
):
def
test_supervised_single_turn
(
num_samples
:
int
):
train_dataset
=
load_
train_
dataset
(
dataset_dir
=
"ONLINE"
,
dataset
=
TINY_DATA
,
**
TRAIN_ARGS
)
train_dataset
=
load_dataset
_module
(
dataset_dir
=
"ONLINE"
,
dataset
=
TINY_DATA
,
**
TRAIN_ARGS
)
[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
TINY_DATA
,
split
=
"train"
)
original_data
=
load_dataset
(
TINY_DATA
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
@@ -64,7 +63,9 @@ def test_supervised_single_turn(num_samples: int):
...
@@ -64,7 +63,9 @@ def test_supervised_single_turn(num_samples: int):
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
8
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
8
])
def
test_supervised_multi_turn
(
num_samples
:
int
):
def
test_supervised_multi_turn
(
num_samples
:
int
):
train_dataset
=
load_train_dataset
(
dataset_dir
=
"REMOTE:"
+
DEMO_DATA
,
dataset
=
"system_chat"
,
**
TRAIN_ARGS
)
train_dataset
=
load_dataset_module
(
dataset_dir
=
"REMOTE:"
+
DEMO_DATA
,
dataset
=
"system_chat"
,
**
TRAIN_ARGS
)[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
@@ -75,9 +76,9 @@ def test_supervised_multi_turn(num_samples: int):
...
@@ -75,9 +76,9 @@ def test_supervised_multi_turn(num_samples: int):
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
4
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
4
])
def
test_supervised_train_on_prompt
(
num_samples
:
int
):
def
test_supervised_train_on_prompt
(
num_samples
:
int
):
train_dataset
=
load_
train_
dataset
(
train_dataset
=
load_dataset
_module
(
dataset_dir
=
"REMOTE:"
+
DEMO_DATA
,
dataset
=
"system_chat"
,
train_on_prompt
=
True
,
**
TRAIN_ARGS
dataset_dir
=
"REMOTE:"
+
DEMO_DATA
,
dataset
=
"system_chat"
,
train_on_prompt
=
True
,
**
TRAIN_ARGS
)
)
[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
@@ -89,9 +90,9 @@ def test_supervised_train_on_prompt(num_samples: int):
...
@@ -89,9 +90,9 @@ def test_supervised_train_on_prompt(num_samples: int):
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
4
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
4
])
def
test_supervised_mask_history
(
num_samples
:
int
):
def
test_supervised_mask_history
(
num_samples
:
int
):
train_dataset
=
load_
train_
dataset
(
train_dataset
=
load_dataset
_module
(
dataset_dir
=
"REMOTE:"
+
DEMO_DATA
,
dataset
=
"system_chat"
,
mask_history
=
True
,
**
TRAIN_ARGS
dataset_dir
=
"REMOTE:"
+
DEMO_DATA
,
dataset
=
"system_chat"
,
mask_history
=
True
,
**
TRAIN_ARGS
)
)
[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
...
tests/data/processor/test_unsupervised.py
View file @
84987715
...
@@ -19,7 +19,7 @@ import pytest
...
@@ -19,7 +19,7 @@ import pytest
from
datasets
import
load_dataset
from
datasets
import
load_dataset
from
transformers
import
AutoTokenizer
from
transformers
import
AutoTokenizer
from
llamafactory.train.test_utils
import
load_
train_
dataset
from
llamafactory.train.test_utils
import
load_dataset
_module
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
...
@@ -39,7 +39,6 @@ TRAIN_ARGS = {
...
@@ -39,7 +39,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
8192
,
"cutoff_len"
:
8192
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
@@ -48,7 +47,7 @@ TRAIN_ARGS = {
...
@@ -48,7 +47,7 @@ TRAIN_ARGS = {
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
@
pytest
.
mark
.
parametrize
(
"num_samples"
,
[
16
])
def
test_unsupervised_data
(
num_samples
:
int
):
def
test_unsupervised_data
(
num_samples
:
int
):
train_dataset
=
load_
train_
dataset
(
**
TRAIN_ARGS
)
train_dataset
=
load_dataset
_module
(
**
TRAIN_ARGS
)
[
"train_dataset"
]
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
ref_tokenizer
=
AutoTokenizer
.
from_pretrained
(
TINY_LLAMA
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
original_data
=
load_dataset
(
DEMO_DATA
,
name
=
"system_chat"
,
split
=
"train"
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
indexes
=
random
.
choices
(
range
(
len
(
original_data
)),
k
=
num_samples
)
...
...
tests/data/test_converter.py
View file @
84987715
# Copyright 2025 the LlamaFactory team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
llamafactory.data
import
Role
from
llamafactory.data
import
Role
from
llamafactory.data.converter
import
get_dataset_converter
from
llamafactory.data.converter
import
get_dataset_converter
from
llamafactory.data.parser
import
DatasetAttr
from
llamafactory.data.parser
import
DatasetAttr
...
...
tests/data/test_loader.py
0 → 100644
View file @
84987715
# Copyright 2025 the LlamaFactory team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
from
llamafactory.train.test_utils
import
load_dataset_module
DEMO_DATA
=
os
.
getenv
(
"DEMO_DATA"
,
"llamafactory/demo_data"
)
TINY_LLAMA
=
os
.
getenv
(
"TINY_LLAMA"
,
"llamafactory/tiny-random-Llama-3"
)
TINY_DATA
=
os
.
getenv
(
"TINY_DATA"
,
"llamafactory/tiny-supervised-dataset"
)
TRAIN_ARGS
=
{
"model_name_or_path"
:
TINY_LLAMA
,
"stage"
:
"sft"
,
"do_train"
:
True
,
"finetuning_type"
:
"full"
,
"template"
:
"llama3"
,
"dataset"
:
TINY_DATA
,
"dataset_dir"
:
"ONLINE"
,
"cutoff_len"
:
8192
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
}
def
test_load_train_only
():
dataset_module
=
load_dataset_module
(
**
TRAIN_ARGS
)
assert
dataset_module
.
get
(
"train_dataset"
)
is
not
None
assert
dataset_module
.
get
(
"eval_dataset"
)
is
None
def
test_load_val_size
():
dataset_module
=
load_dataset_module
(
val_size
=
0.1
,
**
TRAIN_ARGS
)
assert
dataset_module
.
get
(
"train_dataset"
)
is
not
None
assert
dataset_module
.
get
(
"eval_dataset"
)
is
not
None
def
test_load_eval_data
():
dataset_module
=
load_dataset_module
(
eval_dataset
=
TINY_DATA
,
**
TRAIN_ARGS
)
assert
dataset_module
.
get
(
"train_dataset"
)
is
not
None
assert
dataset_module
.
get
(
"eval_dataset"
)
is
not
None
tests/e2e/test_train.py
View file @
84987715
...
@@ -32,7 +32,6 @@ TRAIN_ARGS = {
...
@@ -32,7 +32,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"dataset_dir"
:
"REMOTE:"
+
DEMO_DATA
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1
,
"cutoff_len"
:
1
,
"overwrite_cache"
:
False
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"per_device_train_batch_size"
:
1
,
"per_device_train_batch_size"
:
1
,
"max_steps"
:
1
,
"max_steps"
:
1
,
...
...
tests/model/model_utils/test_checkpointing.py
View file @
84987715
...
@@ -33,7 +33,6 @@ TRAIN_ARGS = {
...
@@ -33,7 +33,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"ONLINE"
,
"dataset_dir"
:
"ONLINE"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1024
,
"cutoff_len"
:
1024
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
...
tests/model/model_utils/test_visual.py
View file @
84987715
...
@@ -20,23 +20,16 @@ from llamafactory.hparams import FinetuningArguments, ModelArguments
...
@@ -20,23 +20,16 @@ from llamafactory.hparams import FinetuningArguments, ModelArguments
from
llamafactory.model.adapter
import
init_adapter
from
llamafactory.model.adapter
import
init_adapter
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"freeze_vision_tower"
,
(
False
,
True
))
"freeze_vision_tower,freeze_multi_modal_projector,train_mm_proj_only"
,
@
pytest
.
mark
.
parametrize
(
"freeze_multi_modal_projector"
,
(
False
,
True
))
[
@
pytest
.
mark
.
parametrize
(
"freeze_language_model"
,
(
False
,
True
))
(
False
,
False
,
False
),
def
test_visual_full
(
freeze_vision_tower
:
bool
,
freeze_multi_modal_projector
:
bool
,
freeze_language_model
:
bool
):
(
False
,
True
,
False
),
(
True
,
False
,
False
),
(
True
,
True
,
False
),
(
True
,
False
,
True
),
],
)
def
test_visual_full
(
freeze_vision_tower
:
bool
,
freeze_multi_modal_projector
:
bool
,
train_mm_proj_only
:
bool
):
model_args
=
ModelArguments
(
model_name_or_path
=
"Qwen/Qwen2-VL-2B-Instruct"
)
model_args
=
ModelArguments
(
model_name_or_path
=
"Qwen/Qwen2-VL-2B-Instruct"
)
finetuning_args
=
FinetuningArguments
(
finetuning_args
=
FinetuningArguments
(
finetuning_type
=
"full"
,
finetuning_type
=
"full"
,
freeze_vision_tower
=
freeze_vision_tower
,
freeze_vision_tower
=
freeze_vision_tower
,
freeze_multi_modal_projector
=
freeze_multi_modal_projector
,
freeze_multi_modal_projector
=
freeze_multi_modal_projector
,
train_mm_proj_only
=
train_mm_proj_only
,
freeze_language_model
=
freeze_language_model
,
)
)
config
=
AutoConfig
.
from_pretrained
(
model_args
.
model_name_or_path
)
config
=
AutoConfig
.
from_pretrained
(
model_args
.
model_name_or_path
)
with
torch
.
device
(
"meta"
):
with
torch
.
device
(
"meta"
):
...
@@ -49,10 +42,10 @@ def test_visual_full(freeze_vision_tower: bool, freeze_multi_modal_projector: bo
...
@@ -49,10 +42,10 @@ def test_visual_full(freeze_vision_tower: bool, freeze_multi_modal_projector: bo
elif
"visual.merger"
in
name
:
elif
"visual.merger"
in
name
:
assert
param
.
requires_grad
!=
freeze_multi_modal_projector
assert
param
.
requires_grad
!=
freeze_multi_modal_projector
else
:
else
:
assert
param
.
requires_grad
!=
train_mm_proj_only
assert
param
.
requires_grad
!=
freeze_language_model
@
pytest
.
mark
.
parametrize
(
"freeze_vision_tower"
,
[
False
,
True
]
)
@
pytest
.
mark
.
parametrize
(
"freeze_vision_tower"
,
(
False
,
True
)
)
def
test_visual_lora
(
freeze_vision_tower
:
bool
):
def
test_visual_lora
(
freeze_vision_tower
:
bool
):
model_args
=
ModelArguments
(
model_name_or_path
=
"Qwen/Qwen2-VL-2B-Instruct"
)
model_args
=
ModelArguments
(
model_name_or_path
=
"Qwen/Qwen2-VL-2B-Instruct"
)
finetuning_args
=
FinetuningArguments
(
finetuning_type
=
"lora"
,
freeze_vision_tower
=
freeze_vision_tower
)
finetuning_args
=
FinetuningArguments
(
finetuning_type
=
"lora"
,
freeze_vision_tower
=
freeze_vision_tower
)
...
...
tests/model/test_freeze.py
View file @
84987715
...
@@ -30,7 +30,6 @@ TRAIN_ARGS = {
...
@@ -30,7 +30,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"ONLINE"
,
"dataset_dir"
:
"ONLINE"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1024
,
"cutoff_len"
:
1024
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
...
tests/model/test_full.py
View file @
84987715
...
@@ -30,7 +30,6 @@ TRAIN_ARGS = {
...
@@ -30,7 +30,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"ONLINE"
,
"dataset_dir"
:
"ONLINE"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1024
,
"cutoff_len"
:
1024
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
...
tests/model/test_lora.py
View file @
84987715
...
@@ -42,7 +42,6 @@ TRAIN_ARGS = {
...
@@ -42,7 +42,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"ONLINE"
,
"dataset_dir"
:
"ONLINE"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1024
,
"cutoff_len"
:
1024
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
...
tests/model/test_pissa.py
View file @
84987715
...
@@ -34,7 +34,6 @@ TRAIN_ARGS = {
...
@@ -34,7 +34,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"ONLINE"
,
"dataset_dir"
:
"ONLINE"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1024
,
"cutoff_len"
:
1024
,
"overwrite_cache"
:
True
,
"output_dir"
:
"dummy_dir"
,
"output_dir"
:
"dummy_dir"
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"fp16"
:
True
,
"fp16"
:
True
,
...
...
tests/train/test_sft_trainer.py
View file @
84987715
...
@@ -38,7 +38,6 @@ TRAIN_ARGS = {
...
@@ -38,7 +38,6 @@ TRAIN_ARGS = {
"dataset_dir"
:
"ONLINE"
,
"dataset_dir"
:
"ONLINE"
,
"template"
:
"llama3"
,
"template"
:
"llama3"
,
"cutoff_len"
:
1024
,
"cutoff_len"
:
1024
,
"overwrite_cache"
:
False
,
"overwrite_output_dir"
:
True
,
"overwrite_output_dir"
:
True
,
"per_device_train_batch_size"
:
1
,
"per_device_train_batch_size"
:
1
,
"max_steps"
:
1
,
"max_steps"
:
1
,
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment