Skip to content
Closed
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
6 changes: 6 additions & 0 deletions examples/text-generation/run_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ def __call__(self, parser, namespace, values, option_string=None):
action="store_true",
help="Whether to enable device map auto. In case no space left on cpu, weights will be offloaded to disk.",
)
parser.add_argument(
"--load_cp",
action="store_true",
help="Whether to load model from hugging face checkpoint.",
)

args = parser.parse_args()

if args.torch_compile:
Expand Down
9 changes: 9 additions & 0 deletions examples/text-generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,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.peft_model is not None:
model = peft_model(args, model_dtype, logger, **model_kwargs)
Expand Down Expand Up @@ -457,6 +465,7 @@ def initialize_model(args, logger):
model_kwargs = {
"revision": args.model_revision,
"token": args.token,
"torch_dtype": torch.bfloat16,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove if not needed

}

model = (
Expand Down