【diffusers 下载】access token 使用方法总结
对于特定模型下载需要采用 access token 进行验证,如下所述,但 huggingface 文档里并没有统一介绍 access token 的使用方式😂,特此记录下。
# When prompted for a password, use an access token with write permissions.
# Generate one from your settings: https://huggingface.co/settings/tokens
git clone https://huggingface.co/black-forest-labs/FLUX.1-dev
方法1
access token 作为验证时的密码
- 转到 huggingface.co/settings/tokens,创建一个具有写访问权限的新访问令牌。
- 当 git 要求您输入用户名和密码时,请使用您的用户名和访问令牌作为密码。
参考文档:https://huggingface.co/learn/ml-for-3d-course/en/unit2/hands-on-1#access-tokens
方法2
在 from_pretrained 中直接使用,如下所示。
import torch
from diffusers import FluxPipelineaccess_token = "hf_xxx"pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16, token=access_token)
pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU powerprompt = "'hello world'"
image = pipe(prompt,height=1024,width=1024,guidance_scale=3.5,num_inference_steps=28,max_sequence_length=512,generator=torch.Generator("cpu").manual_seed(0)
).images[0]
image.save("hello_world.png")