python diffusers StableDiffusionXLPipeline 离线使用

编程入门 行业动态 更新时间:2024-10-25 05:21:29

python diffusers StableDiffusionXLPipeline <a href=https://www.elefans.com/category/jswz/34/1767604.html style=离线使用"/>

python diffusers StableDiffusionXLPipeline 离线使用

  

下载sd_xl_base_1.0.safetensors

我这下载后放到项目 models 里

model_path = "./models/v1-5-pruned-emaonly.safetensors"
# model_path = "./models/v1-5-pruned.safetensors"
# modelId = "runwayml/stable-diffusion-v1-5"
if Util.isMac():# from_single_filepipe = StableDiffusionPipeline.from_single_file(model_path, original_config_file='./models/v1-inference.yaml', cache_dir='./cache/', use_safetensors=True)pipe = pipe.to("mps")pipe.enable_attention_slicing()
else:pipe = StableDiffusionPipeline.from_single_file(model_path, torch_dtype=torch.float16, use_safetensors=True)pipe.to("cuda")pipe.enable_model_cpu_offload()pipe.enable_attention_slicing()

修改package

Diffusers 里代码写死了会访问 huggingface,需要手工改掉

import sysconfig; def repalceStringInFile(srcStr, dstStr, filePath):# Read in the filewith open(filePath, 'r') as file:filedata = file.read()# Replace the target stringfiledata = filedata.replace(srcStr, dstStr)# Write the file out againwith open(filePath, 'w') as file:file.write(filedata)sitedir=sysconfig.get_paths()["purelib"]
ckPtFilePath=f"{sitedir}/diffusers/pipelines/stable_diffusion/convert_from_ckpt.py"
print(ckPtFilePath)srcStr=".yaml"
dstStr="http://xxxxxx/github/CompVis_stable-diffusion_main_configs_stable-diffusion_v1-inference.yaml"repalceStringInFile(srcStr, dstStr, ckPtFilePath)srcStr=".yaml"
dstStr="http://xxxxxx/github/Stability-AI_stablediffusion_main_configs_stable-diffusion_v2-inference-v.yaml"
repalceStringInFile(srcStr, dstStr, ckPtFilePath)srcStr=".yaml"
dstStr="http://xxxxxx/github/Stability-AI_generative-models_main_configs_inference_sd_xl_base.yaml"
repalceStringInFile(srcStr, dstStr, ckPtFilePath)srcStr=".yaml"
dstStr="http://xxxxxx/github/Stability-AI_generative-models_main_configs_inference_sd_xl_refiner.yaml"
repalceStringInFile(srcStr, dstStr, ckPtFilePath)ckPtFilePath=f"{sitedir}/diffusers/loaders.py"
print(ckPtFilePath)
srcStr="text_encoder=text_encoder,\n            vae=vae,"
dstStr="text_encoder=text_encoder,\n            local_files_only=True,\n            vae=vae,"
repalceStringInFile(srcStr, dstStr, ckPtFilePath)ckPtFilePath=f"{sitedir}/diffusers/pipelines/stable_diffusion/convert_from_ckpt.py"
print(ckPtFilePath)
srcStr="has_projection=True, **config_kwargs"
dstStr="has_projection=True, local_files_only=local_files_only, **config_kwargs"
repalceStringInFile(srcStr, dstStr, ckPtFilePath)

http://xxxxxx 需要自己下载github里的文件,找地方放,然后替换链接

local_files_only是让取本地缓存,这个缓存在当前用户文件夹下

ubuntu

/home/fxbox/.cache/huggingface/hub

mac

/Users/linzhiji/.cache/huggingface/hub

把能翻墙的机器里的缓存,拷贝到不能翻墙的机器里

参考:

Stable Diffusion 图像生成 攻略三 - 知乎

更多推荐

python diffusers StableDiffusionXLPipeline 离线使用

本文发布于:2024-02-25 22:05:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1700439.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:离线   python   diffusers   StableDiffusionXLPipeline

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!