Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/text-generation/run_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ def __call__(self, parser, namespace, values, option_string=None):
default="none",
help="Run multi card with the specified distributed strategy. Choices are 'tp' for Tensor Parallel Strategy or 'none'.",
)
parser.add_argument(
"--load_cp",
action="store_true",
help="Whether to load model from hugging face checkpoint.",
)

args = parser.parse_args()

Expand Down
11 changes: 11 additions & 0 deletions examples/text-generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ def setup_model(args, model_dtype, model_kwargs, logger):
model = AutoModelForCausalLM.from_pretrained(
args.model_name_or_path, torch_dtype=model_dtype, quantization_config=quantization_config, **model_kwargs
)
elif args.load_cp:
from neural_compressor.torch.quantization import load
model = load(
model_name_or_path=args.model_name_or_path,
format="huggingface",
device="hpu",
**model_kwargs
)
else:
if args.assistant_model is not None:
assistant_model = AutoModelForCausalLM.from_pretrained(
Expand Down Expand Up @@ -638,6 +646,9 @@ def initialize_model(args, logger):
"token": args.token,
"trust_remote_code": args.trust_remote_code,
}
if args.load_cp:
model_kwargs["torch_dtype"] = torch.bfloat16

if args.trust_remote_code:
logger.warning("`trust_remote_code` is set, there is no guarantee this model works properly and it may fail")

Expand Down