当前位置:   article > 正文

python diffusers StableDiffusionXLPipeline 离线使用_v1-5-pruned-emaonly.safetensors 下载

v1-5-pruned-emaonly.safetensors 下载

  

下载sd_xl_base_1.0.safetensors

https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main

我这下载后放到项目 models 里

  1. model_path = "./models/v1-5-pruned-emaonly.safetensors"
  2. # model_path = "./models/v1-5-pruned.safetensors"
  3. # modelId = "runwayml/stable-diffusion-v1-5"
  4. if Util.isMac():
  5. # from_single_file
  6. pipe = StableDiffusionPipeline.from_single_file(model_path, original_config_file='./models/v1-inference.yaml', cache_dir='./cache/', use_safetensors=True)
  7. pipe = pipe.to("mps")
  8. pipe.enable_attention_slicing()
  9. else:
  10. pipe = StableDiffusionPipeline.from_single_file(model_path, torch_dtype=torch.float16, use_safetensors=True)
  11. pipe.to("cuda")
  12. pipe.enable_model_cpu_offload()
  13. pipe.enable_attention_slicing()

修改package

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

  1. import sysconfig;
  2. def repalceStringInFile(srcStr, dstStr, filePath):
  3. # Read in the file
  4. with open(filePath, 'r') as file:
  5. filedata = file.read()
  6. # Replace the target string
  7. filedata = filedata.replace(srcStr, dstStr)
  8. # Write the file out again
  9. with open(filePath, 'w') as file:
  10. file.write(filedata)
  11. sitedir=sysconfig.get_paths()["purelib"]
  12. ckPtFilePath=f"{sitedir}/diffusers/pipelines/stable_diffusion/convert_from_ckpt.py"
  13. print(ckPtFilePath)
  14. srcStr="https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
  15. dstStr="http://xxxxxx/github/CompVis_stable-diffusion_main_configs_stable-diffusion_v1-inference.yaml"
  16. repalceStringInFile(srcStr, dstStr, ckPtFilePath)
  17. srcStr="https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml"
  18. dstStr="http://xxxxxx/github/Stability-AI_stablediffusion_main_configs_stable-diffusion_v2-inference-v.yaml"
  19. repalceStringInFile(srcStr, dstStr, ckPtFilePath)
  20. srcStr="https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_base.yaml"
  21. dstStr="http://xxxxxx/github/Stability-AI_generative-models_main_configs_inference_sd_xl_base.yaml"
  22. repalceStringInFile(srcStr, dstStr, ckPtFilePath)
  23. srcStr="https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_refiner.yaml"
  24. dstStr="http://xxxxxx/github/Stability-AI_generative-models_main_configs_inference_sd_xl_refiner.yaml"
  25. repalceStringInFile(srcStr, dstStr, ckPtFilePath)
  26. ckPtFilePath=f"{sitedir}/diffusers/loaders.py"
  27. print(ckPtFilePath)
  28. srcStr="text_encoder=text_encoder,\n vae=vae,"
  29. dstStr="text_encoder=text_encoder,\n local_files_only=True,\n vae=vae,"
  30. repalceStringInFile(srcStr, dstStr, ckPtFilePath)
  31. ckPtFilePath=f"{sitedir}/diffusers/pipelines/stable_diffusion/convert_from_ckpt.py"
  32. print(ckPtFilePath)
  33. srcStr="has_projection=True, **config_kwargs"
  34. dstStr="has_projection=True, local_files_only=local_files_only, **config_kwargs"
  35. repalceStringInFile(srcStr, dstStr, ckPtFilePath)

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

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

ubuntu

/home/fxbox/.cache/huggingface/hub

mac

/Users/linzhiji/.cache/huggingface/hub

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

参考:

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/396468
推荐阅读
相关标签
  

闽ICP备14008679号