【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 FluxPipeline

access_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 power

prompt = "'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")

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值