huggingface.js icon indicating copy to clipboard operation
huggingface.js copied to clipboard

Updated gated models snippet

Open gary149 opened this issue 1 year ago • 22 comments

For gated models add a comment on how to create the token + update the code snippet to include the token (edit: as a placeholder)

image

gary149 avatar Jun 19 '24 10:06 gary149

hmm not include the token, but mention to do huggingface-cli login instead

julien-c avatar Jun 19 '24 10:06 julien-c

cc @osanseviero

julien-c avatar Jun 19 '24 10:06 julien-c

I agree with a mention to huggingface-cli login

pcuenca avatar Jun 19 '24 10:06 pcuenca

and btw the error message if not logged in should already prompt you to huggingface-cli login

julien-c avatar Jun 19 '24 10:06 julien-c

and btw the error message if not logged in should already prompt you to huggingface-cli login

let me know, I can create an issue on transformers

mishig25 avatar Jun 19 '24 10:06 mishig25

btw it should work with diffusers too

gary149 avatar Jun 19 '24 10:06 gary149

i meant it must already be the case AFAIK

julien-c avatar Jun 19 '24 10:06 julien-c

and yes it's not library specific

julien-c avatar Jun 19 '24 10:06 julien-c

on transformers:

/usr/local/lib/python3.10/dist-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(

OSError: You are trying to access a gated repo.
Make sure to have access to it at https://huggingface.co/meta-llama/Meta-Llama-3-8B.
401 Client Error. (Request ID: Root=1-6672b9e2-4e7561551ca6a7d17bd1e5a8;718527cf-0693-4b8f-ad60-8a60fb2cf76c)

Cannot access gated repo for url https://huggingface.co/meta-llama/Meta-Llama-3-8B/resolve/main/config.json.
Access to model meta-llama/Meta-Llama-3-8B is restricted. You must be authenticated to access it.

mishig25 avatar Jun 19 '24 10:06 mishig25

on diffusers:

HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/models/stabilityai/stable-diffusion-3-medium

The above exception was the direct cause of the following exception:

GatedRepoError                            Traceback (most recent call last)
GatedRepoError: 401 Client Error. (Request ID: Root=1-6672ba64-6d0027fd0aff7b1b00e1e485;ea7fdd17-c3a6-4c4f-b0a2-e6d37f3b5a6f)

Cannot access gated repo for url https://huggingface.co/api/models/stabilityai/stable-diffusion-3-medium.
Access to model stabilityai/stable-diffusion-3-medium is restricted. You must be authenticated to access it.

The above exception was the direct cause of the following exception:

OSError                                   Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/diffusers/pipelines/pipeline_utils.py](https://localhost:8080/#) in download(cls, pretrained_model_name, **kwargs)
   1546             else:
   1547                 # 2. we forced `local_files_only=True` when `model_info` failed
-> 1548                 raise EnvironmentError(
   1549                     f"Cannot load model {pretrained_model_name}: model is not cached locally and an error occurred"
   1550                     " while trying to fetch metadata from the Hub. Please check out the root cause in the stacktrace"

OSError: Cannot load model stabilityai/stable-diffusion-3-medium: model is not cached locally and an error occurred while trying to fetch metadata from the Hub. Please check out the root cause in the stacktrace above.

mishig25 avatar Jun 19 '24 11:06 mishig25

Ok, so maybe we add Please log in using "huggingface-cli login" or similar mechanism to that error message:

Access to model stabilityai/stable-diffusion-3-medium is restricted. You must be authenticated to access it. then?

(i think that error string is in moon)

julien-c avatar Jun 19 '24 11:06 julien-c

but orthogonally, i'm ok to add a huggingface-cli login command to the snippets as discussed in https://github.com/huggingface/huggingface.js/issues/765#issuecomment-2178338707

julien-c avatar Jun 19 '24 11:06 julien-c

oh and btw maybe let's also start to add brew install huggingface-cli on the line before as a good easy way to install it?

(cc @Wauplin too)

EDIT: what's an easy alternative for Windows?

julien-c avatar Jun 19 '24 11:06 julien-c

pip install huggingface_hub or pip install --upgrade huggingface_hub would be the only way AFAIK for Windows atm.

Vaibhavs10 avatar Jun 19 '24 11:06 Vaibhavs10

Ah yeah here is the authentication string prompt: https://github.com/huggingface/moon-landing/blob/19a45f022a771c9f1b045c95e072122982513514/server/lib/Auth.ts#L930

Vaibhavs10 avatar Jun 19 '24 11:06 Vaibhavs10

For windows I can help on having a winget install path https://github.com/microsoft/winget-cli

mfuntowicz avatar Jun 19 '24 14:06 mfuntowicz

would it be winget install huggingface-cli?

julien-c avatar Jun 19 '24 14:06 julien-c

Tentatively yes - this or HuggingFace.Cli I think there is a short and long reference(s)

mfuntowicz avatar Jun 19 '24 15:06 mfuntowicz

@mfuntowicz I'm not knowledgeable on winget specifically but please let me know if I can be of any assistance packaging huggingface-cli :)

Wauplin avatar Jun 26 '24 16:06 Wauplin

Is "huggingface-cli login" the recommended way to login for transformers.js? For example, if an "Error: Forbidden access to file" error is received. There are no JS functions provided to log in with an HF_TOKEN?

goldingdamien avatar Oct 19 '24 07:10 goldingdamien

Hello @goldingdamien! For transformers.js, I think you need to follow these steps (server environments): https://huggingface.co/docs/transformers.js/en/guides/private

pcuenca avatar Oct 19 '24 11:10 pcuenca

@pcuenca Thank you. Yes, that was the first issue. I also had to request access. Going to the link in the error directly made that clear. Regards.

goldingdamien avatar Oct 19 '24 13:10 goldingdamien