mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-12-16 20:00:36 +08:00
[misc] lint (#9593)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -18,8 +18,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import os
|
|
||||||
import inspect
|
import inspect
|
||||||
|
import os
|
||||||
from functools import WRAPPER_ASSIGNMENTS, partial, wraps
|
from functools import WRAPPER_ASSIGNMENTS, partial, wraps
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
|
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
|
||||||
@@ -158,9 +158,7 @@ def prepare_model_for_training(model: "PreTrainedModel", model_args: "ModelArgum
|
|||||||
and int(os.environ.get("FSDP_VERSION", "1")) == 2
|
and int(os.environ.get("FSDP_VERSION", "1")) == 2
|
||||||
):
|
):
|
||||||
model_args.use_reentrant_gc = False
|
model_args.use_reentrant_gc = False
|
||||||
logger.warning_rank0(
|
logger.warning_rank0("You are using fsdp2, `use_reentrant_gc` has been set to False.")
|
||||||
"You are using fsdp2, `use_reentrant_gc` has been set to False. "
|
|
||||||
)
|
|
||||||
|
|
||||||
if not model_args.disable_gradient_checkpointing:
|
if not model_args.disable_gradient_checkpointing:
|
||||||
if not getattr(model, "supports_gradient_checkpointing", False):
|
if not getattr(model, "supports_gradient_checkpointing", False):
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ from ..trainer_utils import create_modelcard_and_push
|
|||||||
from .metric import ComputeAccuracy, ComputeSimilarity, eval_logit_processor
|
from .metric import ComputeAccuracy, ComputeSimilarity, eval_logit_processor
|
||||||
from .trainer import CustomSeq2SeqTrainer
|
from .trainer import CustomSeq2SeqTrainer
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from transformers import Seq2SeqTrainingArguments, TrainerCallback
|
from transformers import Seq2SeqTrainingArguments, TrainerCallback
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ def pytest_configure(config):
|
|||||||
config.addinivalue_line(
|
config.addinivalue_line(
|
||||||
"markers", "require_device: test requires specific device, e.g., @pytest.mark.require_device('cuda')"
|
"markers", "require_device: test requires specific device, e.g., @pytest.mark.require_device('cuda')"
|
||||||
)
|
)
|
||||||
config.addinivalue_line(
|
config.addinivalue_line("markers", "runs_on: test requires specific device, e.g., @pytest.mark.runs_on(['cpu'])")
|
||||||
"markers", "runs_on: test requires specific device, e.g., @pytest.mark.runs_on(['cpu'])"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _handle_runs_on(items):
|
def _handle_runs_on(items):
|
||||||
@@ -64,14 +62,12 @@ def _handle_runs_on(items):
|
|||||||
if isinstance(runs_on_devices, str):
|
if isinstance(runs_on_devices, str):
|
||||||
runs_on_devices = [runs_on_devices]
|
runs_on_devices = [runs_on_devices]
|
||||||
|
|
||||||
|
|
||||||
if CURRENT_DEVICE not in runs_on_devices:
|
if CURRENT_DEVICE not in runs_on_devices:
|
||||||
item.add_marker(
|
item.add_marker(
|
||||||
pytest.mark.skip(
|
pytest.mark.skip(reason=f"test requires one of {runs_on_devices} (current: {CURRENT_DEVICE})")
|
||||||
reason=f"test requires one of {runs_on_devices} (current: {CURRENT_DEVICE})"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _handle_slow_tests(items):
|
def _handle_slow_tests(items):
|
||||||
"""Skip slow tests unless RUN_SLOW environment variable is set.
|
"""Skip slow tests unless RUN_SLOW environment variable is set.
|
||||||
|
|
||||||
|
|||||||
@@ -284,7 +284,6 @@ def test_llama4_template(use_fast: bool):
|
|||||||
pytest.param(False, marks=pytest.mark.xfail(reason="Phi-4 slow tokenizer is broken.")),
|
pytest.param(False, marks=pytest.mark.xfail(reason="Phi-4 slow tokenizer is broken.")),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu"])
|
@pytest.mark.runs_on(["cpu"])
|
||||||
def test_phi4_template(use_fast: bool):
|
def test_phi4_template(use_fast: bool):
|
||||||
prompt_str = (
|
prompt_str = (
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ INFER_ARGS = {
|
|||||||
|
|
||||||
OS_NAME = os.getenv("OS_NAME", "")
|
OS_NAME = os.getenv("OS_NAME", "")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu"])
|
@pytest.mark.runs_on(["cpu"])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"stage,dataset",
|
"stage,dataset",
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ def test_eval_template_en():
|
|||||||
{"role": "assistant", "content": "C"},
|
{"role": "assistant", "content": "C"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu"])
|
@pytest.mark.runs_on(["cpu"])
|
||||||
def test_eval_template_zh():
|
def test_eval_template_zh():
|
||||||
support_set = [
|
support_set = [
|
||||||
|
|||||||
@@ -17,13 +17,16 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
from transformers.utils import is_flash_attn_2_available
|
from transformers.utils import is_flash_attn_2_available
|
||||||
|
|
||||||
|
|
||||||
# Compatible with Transformers v4 and Transformers v5
|
# Compatible with Transformers v4 and Transformers v5
|
||||||
try:
|
try:
|
||||||
from transformers.utils import is_torch_sdpa_available
|
from transformers.utils import is_torch_sdpa_available
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
||||||
def is_torch_sdpa_available():
|
def is_torch_sdpa_available():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
from llamafactory.extras.packages import is_transformers_version_greater_than
|
from llamafactory.extras.packages import is_transformers_version_greater_than
|
||||||
from llamafactory.train.test_utils import load_infer_model
|
from llamafactory.train.test_utils import load_infer_model
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ INFER_ARGS = {
|
|||||||
"infer_dtype": "float16",
|
"infer_dtype": "float16",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu", "npu"])
|
@pytest.mark.runs_on(["cpu", "npu"])
|
||||||
@pytest.mark.skip_on_devices("npu")
|
@pytest.mark.skip_on_devices("npu")
|
||||||
def test_base():
|
def test_base():
|
||||||
@@ -36,6 +37,7 @@ def test_base():
|
|||||||
ref_model = load_reference_model(TINY_LLAMA3)
|
ref_model = load_reference_model(TINY_LLAMA3)
|
||||||
compare_model(model, ref_model)
|
compare_model(model, ref_model)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu", "npu"])
|
@pytest.mark.runs_on(["cpu", "npu"])
|
||||||
@pytest.mark.skip_on_devices("npu")
|
@pytest.mark.skip_on_devices("npu")
|
||||||
@pytest.mark.usefixtures("fix_valuehead_cpu_loading")
|
@pytest.mark.usefixtures("fix_valuehead_cpu_loading")
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ INFER_ARGS = {
|
|||||||
"infer_dtype": "float16",
|
"infer_dtype": "float16",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu", "npu"])
|
@pytest.mark.runs_on(["cpu", "npu"])
|
||||||
def test_full_train():
|
def test_full_train():
|
||||||
model = load_train_model(**TRAIN_ARGS)
|
model = load_train_model(**TRAIN_ARGS)
|
||||||
@@ -50,6 +51,7 @@ def test_full_train():
|
|||||||
assert param.requires_grad is True
|
assert param.requires_grad is True
|
||||||
assert param.dtype == torch.float32
|
assert param.dtype == torch.float32
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu", "npu"])
|
@pytest.mark.runs_on(["cpu", "npu"])
|
||||||
def test_full_inference():
|
def test_full_inference():
|
||||||
model = load_infer_model(**INFER_ARGS)
|
model = load_infer_model(**INFER_ARGS)
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ def test_lora_train_valuehead():
|
|||||||
assert torch.allclose(state_dict["v_head.summary.weight"], ref_state_dict["v_head.summary.weight"])
|
assert torch.allclose(state_dict["v_head.summary.weight"], ref_state_dict["v_head.summary.weight"])
|
||||||
assert torch.allclose(state_dict["v_head.summary.bias"], ref_state_dict["v_head.summary.bias"])
|
assert torch.allclose(state_dict["v_head.summary.bias"], ref_state_dict["v_head.summary.bias"])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu", "npu"])
|
@pytest.mark.runs_on(["cpu", "npu"])
|
||||||
@pytest.mark.skip_on_devices("npu")
|
@pytest.mark.skip_on_devices("npu")
|
||||||
def test_lora_inference():
|
def test_lora_inference():
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ def test_pissa_train():
|
|||||||
ref_model = load_reference_model(TINY_LLAMA_PISSA, TINY_LLAMA_PISSA, use_pissa=True, is_trainable=True)
|
ref_model = load_reference_model(TINY_LLAMA_PISSA, TINY_LLAMA_PISSA, use_pissa=True, is_trainable=True)
|
||||||
compare_model(model, ref_model)
|
compare_model(model, ref_model)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.runs_on(["cpu", "npu"])
|
@pytest.mark.runs_on(["cpu", "npu"])
|
||||||
@pytest.mark.xfail(reason="Known connection error.")
|
@pytest.mark.xfail(reason="Known connection error.")
|
||||||
def test_pissa_inference():
|
def test_pissa_inference():
|
||||||
|
|||||||
Reference in New Issue
Block a user