Skip to content

Add HF_TRUST_REMOTE_CODE environment variable #78

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

Merged
merged 10 commits into from
Aug 9, 2024

Conversation

alvarobartt
Copy link
Member

Description

As flagged by Changyu Zhu from Google, there was no way of setting trust_remote_code=True when loading a model from the Hugging Face Hub that requires remote code execution; whilst for Text Generation Inference (TGI) is indeed possible via the TRUST_REMOTE_CODE environment variable (as per https://huggingface.co/docs/text-generation-inference/en/basic_tutorials/safety).

This PR adds the HF_TRUST_REMOTE_CODE environment variable in order to be able to set it for transformers, sentence-transformers, and diffusers pipelines. Additionally, this PR also fixes the **kwargs propagation for both sentence-transformers and diffusers. Finally, this PR also updates the README.md accordingly as of the HF_TRUST_REMOTE_CODE addition, while also fixing some typos and aligning the formatting.

Note

As of the recent merges within #76 and #77, the version in setup.py has also been bumped to 0.4.1 to include all those changes and generate the wheel accordingly. So on, once this PR is merged, the version in the main branch should point to 0.4.2.dev0 instead.

The `strtobool` had to be defined within `huggingface_inference_toolkit`
since it's deprecated and removed from `distutils` from Python 3.10
onwards.
@alvarobartt alvarobartt added the enhancement New feature or request label Aug 8, 2024
@alvarobartt alvarobartt self-assigned this Aug 8, 2024
Copy link
Contributor

@oOraph oOraph left a comment

Choose a reason for hiding this comment

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

LGTM, question: under the hood, this trust_remote_code bypasses security flags like weights_only=True in pytorch and stuff right ? (allowing for arbitrary pickle loading)

Where do you intend to activate it ? In one of your hf endpoints using a custom env variable ? (just want to make sure we do not activate it by default there :) )

@alvarobartt
Copy link
Member Author

LGTM, question: under the hood, this trust_remote_code bypasses security flags like weights_only=True in pytorch and stuff right ? (allowing for arbitrary pickle loading)
Where do you intend to activate it ? In one of your hf endpoints using a custom env variable ? (just want to make sure we do not activate it by default there :) )

It's indeed disabled by default, and explicitly enabled on the user's side if desired; to basically load models that live within the Hub repository instead of directly being supported / integrated within transformers i.e. custom modeling. And the use case for this is when users run a job in either Vertex AI or GKE using our custom DLCs, as the PyTorch Inference DLC is running huggingface_inference_toolkit under the hood, so that users can load models such as https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct 🤗

P.S. Thanks for the review!

@alvarobartt alvarobartt force-pushed the trust-remote-code-env branch from 9cb211b to c9384c2 Compare August 8, 2024 10:15
@alvarobartt
Copy link
Member Author

To add more context to this PR, it's updated here huggingface/Google-Cloud-Containers#64

@alvarobartt alvarobartt merged commit d9ae3d9 into main Aug 9, 2024
0 of 6 checks passed
@alvarobartt alvarobartt deleted the trust-remote-code-env branch August 9, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants