mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2025-08-22 21:52:51 +08:00
Former-commit-id: d74244d56858d837044e5c9cea57a1b3c2ca0214
This commit is contained in:
parent
4b1ab6c83d
commit
bbc37b2880
@ -384,6 +384,8 @@ Remember to use `ASCEND_RT_VISIBLE_DEVICES` instead of `CUDA_VISIBLE_DEVICES` to
|
|||||||
|
|
||||||
If you cannot infer model on NPU devices, try setting `do_sample: false` in the configurations.
|
If you cannot infer model on NPU devices, try setting `do_sample: false` in the configurations.
|
||||||
|
|
||||||
|
Download the pre-built Docker images: [32GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/130.html) | [64GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/131.html)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Data Preparation
|
### Data Preparation
|
||||||
|
@ -357,7 +357,7 @@ pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/downl
|
|||||||
|
|
||||||
<details><summary>昇腾 NPU 用户指南</summary>
|
<details><summary>昇腾 NPU 用户指南</summary>
|
||||||
|
|
||||||
在昇腾 NPU 设备上安装 LLaMA Factory 时,需要指定额外依赖项,使用 `pip install -e ".[torch-npu,metrics]"` 命令安装。此外,还需要安装 **[Ascend CANN Toolkit and Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**,安装方法请参考[安装教程](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha002/quickstart/quickstart/quickstart_18_0004.html)或使用以下命令:
|
在昇腾 NPU 设备上安装 LLaMA Factory 时,需要指定额外依赖项,使用 `pip install -e ".[torch-npu,metrics]"` 命令安装。此外,还需要安装 **[Ascend CANN Toolkit 与 Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**,安装方法请参考[安装教程](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC2alpha002/quickstart/quickstart/quickstart_18_0004.html)或使用以下命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 请替换 URL 为 CANN 版本和设备型号对应的 URL
|
# 请替换 URL 为 CANN 版本和设备型号对应的 URL
|
||||||
@ -384,6 +384,8 @@ source /usr/local/Ascend/ascend-toolkit/set_env.sh
|
|||||||
|
|
||||||
如果遇到无法正常推理的情况,请尝试设置 `do_sample: false`。
|
如果遇到无法正常推理的情况,请尝试设置 `do_sample: false`。
|
||||||
|
|
||||||
|
下载预构建 Docker 镜像:[32GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/130.html) | [64GB](http://mirrors.cn-central-221.ovaijisuan.com/detail/131.html)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### 数据准备
|
### 数据准备
|
||||||
|
@ -20,7 +20,9 @@ import os
|
|||||||
from typing import TYPE_CHECKING, Tuple
|
from typing import TYPE_CHECKING, Tuple
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
import transformers.dynamic_module_utils
|
||||||
from transformers import InfNanRemoveLogitsProcessor, LogitsProcessorList
|
from transformers import InfNanRemoveLogitsProcessor, LogitsProcessorList
|
||||||
|
from transformers.dynamic_module_utils import get_relative_imports
|
||||||
from transformers.utils import (
|
from transformers.utils import (
|
||||||
is_torch_bf16_gpu_available,
|
is_torch_bf16_gpu_available,
|
||||||
is_torch_cuda_available,
|
is_torch_cuda_available,
|
||||||
@ -69,6 +71,9 @@ class AverageMeter:
|
|||||||
|
|
||||||
|
|
||||||
def check_dependencies() -> None:
|
def check_dependencies() -> None:
|
||||||
|
r"""
|
||||||
|
Checks the version of the required packages.
|
||||||
|
"""
|
||||||
if os.environ.get("DISABLE_VERSION_CHECK", "0").lower() in ["true", "1"]:
|
if os.environ.get("DISABLE_VERSION_CHECK", "0").lower() in ["true", "1"]:
|
||||||
logger.warning("Version checking has been disabled, may lead to unexpected behaviors.")
|
logger.warning("Version checking has been disabled, may lead to unexpected behaviors.")
|
||||||
else:
|
else:
|
||||||
@ -79,7 +84,7 @@ def check_dependencies() -> None:
|
|||||||
require_version("trl>=0.8.6", "To fix: pip install trl>=0.8.6")
|
require_version("trl>=0.8.6", "To fix: pip install trl>=0.8.6")
|
||||||
|
|
||||||
|
|
||||||
def count_parameters(model: torch.nn.Module) -> Tuple[int, int]:
|
def count_parameters(model: "torch.nn.Module") -> Tuple[int, int]:
|
||||||
r"""
|
r"""
|
||||||
Returns the number of trainable parameters and number of all parameters in the model.
|
Returns the number of trainable parameters and number of all parameters in the model.
|
||||||
"""
|
"""
|
||||||
@ -108,7 +113,7 @@ def count_parameters(model: torch.nn.Module) -> Tuple[int, int]:
|
|||||||
return trainable_params, all_param
|
return trainable_params, all_param
|
||||||
|
|
||||||
|
|
||||||
def get_current_device() -> torch.device:
|
def get_current_device() -> "torch.device":
|
||||||
r"""
|
r"""
|
||||||
Gets the current available device.
|
Gets the current available device.
|
||||||
"""
|
"""
|
||||||
@ -147,6 +152,13 @@ def get_logits_processor() -> "LogitsProcessorList":
|
|||||||
return logits_processor
|
return logits_processor
|
||||||
|
|
||||||
|
|
||||||
|
def has_tokenized_data(path: "os.PathLike") -> bool:
|
||||||
|
r"""
|
||||||
|
Checks if the path has a tokenized dataset.
|
||||||
|
"""
|
||||||
|
return os.path.isdir(path) and len(os.listdir(path)) > 0
|
||||||
|
|
||||||
|
|
||||||
def infer_optim_dtype(model_dtype: "torch.dtype") -> "torch.dtype":
|
def infer_optim_dtype(model_dtype: "torch.dtype") -> "torch.dtype":
|
||||||
r"""
|
r"""
|
||||||
Infers the optimal dtype according to the model_dtype and device compatibility.
|
Infers the optimal dtype according to the model_dtype and device compatibility.
|
||||||
@ -166,11 +178,9 @@ def is_gpu_or_npu_available() -> bool:
|
|||||||
return is_torch_npu_available() or is_torch_cuda_available()
|
return is_torch_npu_available() or is_torch_cuda_available()
|
||||||
|
|
||||||
|
|
||||||
def has_tokenized_data(path: "os.PathLike") -> bool:
|
def skip_check_imports() -> None:
|
||||||
r"""
|
if os.environ.get("FORCE_CHECK_IMPORTS", "0").lower() not in ["true", "1"]:
|
||||||
Checks if the path has a tokenized dataset.
|
transformers.dynamic_module_utils.check_imports = get_relative_imports
|
||||||
"""
|
|
||||||
return os.path.isdir(path) and len(os.listdir(path)) > 0
|
|
||||||
|
|
||||||
|
|
||||||
def torch_gc() -> None:
|
def torch_gc() -> None:
|
||||||
|
@ -19,7 +19,7 @@ from transformers import AutoConfig, AutoModelForCausalLM, AutoModelForVision2Se
|
|||||||
from trl import AutoModelForCausalLMWithValueHead
|
from trl import AutoModelForCausalLMWithValueHead
|
||||||
|
|
||||||
from ..extras.logging import get_logger
|
from ..extras.logging import get_logger
|
||||||
from ..extras.misc import count_parameters, try_download_model_from_ms
|
from ..extras.misc import count_parameters, skip_check_imports, try_download_model_from_ms
|
||||||
from .adapter import init_adapter
|
from .adapter import init_adapter
|
||||||
from .model_utils.misc import register_autoclass
|
from .model_utils.misc import register_autoclass
|
||||||
from .model_utils.mod import convert_pretrained_model_to_mod, load_mod_pretrained_model
|
from .model_utils.mod import convert_pretrained_model_to_mod, load_mod_pretrained_model
|
||||||
@ -48,6 +48,7 @@ def _get_init_kwargs(model_args: "ModelArguments") -> Dict[str, Any]:
|
|||||||
|
|
||||||
Note: including inplace operation of model_args.
|
Note: including inplace operation of model_args.
|
||||||
"""
|
"""
|
||||||
|
skip_check_imports()
|
||||||
model_args.model_name_or_path = try_download_model_from_ms(model_args)
|
model_args.model_name_or_path = try_download_model_from_ms(model_args)
|
||||||
return {
|
return {
|
||||||
"trust_remote_code": True,
|
"trust_remote_code": True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user