Skip to content

Fix ApiBuilder in from_pretrained to use env variables #1778

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

Closed
wants to merge 1 commit into from

Conversation

vdebergue
Copy link

Bug

Using Tokenizer::from_pretrained does not download the tokenizer into the HF_HOME folder.
Instead it will download it in the user home cache directory.

Fix

Use env variable to load the ApiBuilder so it will read HF_HOME variable.
Currently they are ignored and the default cache location is used $HOME/.cache/huggingface

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Not super familiar with API builder, if no evn var is defined I am guessing this is equivalent right? It won't just error out instead?

@vdebergue
Copy link
Author

yes, without env it will fallback to the default and will be equivalent to ApiBuilder::new()

@@ -59,7 +59,7 @@ pub fn from_pretrained<S: AsRef<str>>(
.into());
}

let mut builder = ApiBuilder::new();
let mut builder = ApiBuilder::from_env();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let mut builder = ApiBuilder::from_env();
let mut builder = ApiBuilder::from_env("HF_HOME");

should we not set that?

Copy link
Author

Choose a reason for hiding this comment

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

from_env does not take any parameter: https://github.com/huggingface/hf-hub/blob/main/src/api/sync.rs#L242 and the name of the env variables are already set in the code

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh shit okay, I was looking at https://docs.rs/env_logger/latest/env_logger/struct.Builder.html#method.from_env, thanks for the heads up

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ArthurZucker
Copy link
Collaborator

Can you run cargo clippy!

@ArthurZucker
Copy link
Collaborator

Sorry found #1737 which was opened sooner!

@vdebergue
Copy link
Author

closing then, thanks !

@vdebergue vdebergue closed this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants