This commit is contained in:
hiyouga 2023-09-21 13:52:19 +08:00
commit e510006ed6
1 changed files with 5 additions and 2 deletions

View File

@ -13,7 +13,7 @@ from transformers import (
PreTrainedModel, PreTrainedModel,
PreTrainedTokenizerBase PreTrainedTokenizerBase
) )
from transformers.utils import check_min_version from transformers.utils import check_min_version, is_torch_npu_available
from transformers.utils.versions import require_version from transformers.utils.versions import require_version
from trl import AutoModelForCausalLMWithValueHead from trl import AutoModelForCausalLMWithValueHead
@ -215,7 +215,10 @@ def load_model_and_tokenizer(
# Prepare model for inference # Prepare model for inference
if not is_trainable: if not is_trainable:
model.requires_grad_(False) # fix all model params model.requires_grad_(False) # fix all model params
infer_dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16 # detect cuda capability if is_torch_npu_available():
infer_dtype = torch.float16
else:
infer_dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16 # detect cuda capability
model = model.to(infer_dtype) if model_args.quantization_bit is None else model model = model.to(infer_dtype) if model_args.quantization_bit is None else model
trainable_params, all_param = count_parameters(model) trainable_params, all_param = count_parameters(model)