transformers
e249605d - Require `trust_remote_code` to run a local-directory `custom_generate` (#46483)

Commit
7 hours ago
Require `trust_remote_code` to run a local-directory `custom_generate` (#46483) Require trust_remote_code to run a local-directory custom_generate load_custom_generate runs a repository's custom_generate/generate.py via get_class_in_module (exec_module). It is gated by trust_remote_code for Hub repos, but a local directory was treated as trusted (has_local_code = os.path.exists(pretrained_model_name_or_path)), so generate(custom_generate='<local dir>') executed the repo's code with no opt-in. from_pretrained already requires trust_remote_code for custom modeling code that lives in a local repo; align custom_generate with that by treating its code as remote regardless of where it is loaded from. Add a regression test. The existing local-directory test already passes trust_remote_code=True, so it is unaffected. Co-authored-by: LinZiyu <221020063@fzu.edu.cn>
Author
Parents
Loading