Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --trust_remote_code for text generation examples #870

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -260,6 +260,11 @@ def setup_parser(parser):
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(
"--trust_remote_code",
action="store_true",
help="Whether or not to allow for custom models defined on the Hub in their own modeling files.",
)
args = parser.parse_args()

if args.torch_compile:
Expand Down
3 changes: 3 additions & 0 deletions examples/text-generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def setup_tokenizer(args, model):
tokenizer_kwargs = {
"revision": args.model_revision,
"token": args.token,
"trust_remote_code": args.trust_remote_code,
}
if args.bad_words is not None or args.force_words is not None:
tokenizer_kwargs["add_prefix_space"] = True
Expand Down Expand Up @@ -349,6 +350,7 @@ def setup_generation_config(args, model, tokenizer):
generation_config.use_flash_attention = args.use_flash_attention
generation_config.flash_attention_recompute = args.flash_attention_recompute
generation_config.flash_attention_causal_mask = args.flash_attention_causal_mask
generation_config.trust_remote_code = args.trust_remote_code
return generation_config


Expand All @@ -370,6 +372,7 @@ def initialize_model(args, logger):
model_kwargs = {
"revision": args.model_revision,
"token": args.token,
"trust_remote_code": args.trust_remote_code,
}
if args.disk_offload:
model_kwargs["device_map"] = "auto"
Expand Down
Loading