当前位置: 首页 > news >正文

Diffusers

一、diffusers版本>=0.32.0时,模型量化问题

1、bitsandbytes,运行正常但是采样速度变慢

需要下载对应分支pip install git+https://github.com/BenjaminBossan/peft@fix-low-cpu-mem-usage-bnb-8bit

transformer_8bit = FluxTransformer2DModel.from_pretrained(
"black-forest-labs/FLUX.1-dev",
subfolder="transformer",
quantization_config=DiffusersBitsAndBytesConfig(load_in_8bit=True),
torch_dtype=torch.bfloat16,
)
pipe = FluxPipeline.from_pretrained(
"black-forest-labs/FLUX.1-dev",
transformer=transformer_8bit,
torch_dtype=torch.bfloat16,
).to("cuda")

pipe.load_lora_weights(
hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"),
adapter_name="hyper-sd"
)
pipe.set_adapters("hyper-sd", adapter_weights=0.125)

2、optimum,导入lora时存在问题,待解决

Traceback (most recent call last):
File "/home/iv/anaconda3/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/home/iv/anaconda3/lib/python3.10/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/IVAlgoHTTP/app.py", line 112, in process_data
IVmodelHandle.loadModel()
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/IVAlgoHTTP/algos/BaseModel.py", line 28, in loadModel
self.model = GlobalConfig.get_model()
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/IVAlgoHTTP/algos/GlobalConfig.py", line 76, in get_model
modelHandler = model()
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/IVAlgoHTTP/algos/FluxTxt2Img/Flux_txt2img.py", line 145, in __init__
self.pipe.load_lora_weights(hf_hub_download("Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design", "FLUX-dev-lora-Logo-Design.safetensors"), adapter_name="logo")
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/66v/lib/python3.10/site-packages/diffusers/loaders/lora_pipeline.py", line 1559, in load_lora_weights
transformer_lora_state_dict = self._maybe_expand_lora_state_dict(
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/66v/lib/python3.10/site-packages/diffusers/loaders/lora_pipeline.py", line 2085, in _maybe_expand_lora_state_dict
base_weight_param = transformer_state_dict[base_param_name]
KeyError: 'single_transformer_blocks.0.attn.to_k.weight._data'

二、某些lora加载失败

解决办法:diffusers版本过低,升级diffusers

Traceback (most recent call last):
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/IVAlgoHTTP-test/algos/AnystyleImg2Img/newfilter.py", line 1042, in <module>
model = AnyStyleImg2ImgModel()
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/IVAlgoHTTP-test/algos/AnystyleImg2Img/newfilter.py", line 725, in __init__
self.model.pipline.pipe.load_lora_weights(load_file(os.path.join(self.model_root, self.config['SDXL'][self.default_style]['lora_repo'][0]), device=self.device), adapter_name="mix_lora")
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/venv310/lib/python3.10/site-packages/diffusers/loaders/lora.py", line 1255, in load_lora_weights
self.load_lora_into_text_encoder(
File "/home/iv/Algo_new/LouHaijie/IVAlgoHTTP/venv310/lib/python3.10/site-packages/diffusers/loaders/lora.py", line 555, in load_lora_into_text_encoder
rank[rank_key] = text_encoder_lora_state_dict[rank_key].shape[1]
KeyError: 'text_model.encoder.layers.0.self_attn.out_proj.lora_B.weight'

三、如何在diffusers0.31.0版本使用flux-redux

1、安装diffuser0.31.0版本,基础模型的pipeline的类和方法都从该库中调用;

2、从github上安装diffusers0.32.0-release版本,flux-redux的类的方法都从该库中调用;

3、修改diffusers0.32.0-release库:

diffusers/pipelines/pipeline_utils.py:from diffusers import 修改为from [当前库名] import;

4、修改diffusers0.31.0库:diffusers/models/attention_processor.py:

hidden_states = F.scaled_dot_product_attention(query, key, value, dropout_p=0.0, is_causal=False)
修改为:
hidden_states = F.scaled_dot_product_attention(
query, key, value, attn_mask=attention_mask, dropout_p=0.0, is_causal=False)

四、diffusers版本为0.31.0时,使用optimum量化,输出图片为噪声

修改optimum/quanto/tensor/weights/qbytes.py.

and torch.cuda.get_device_capability(data.device)[0] >= 8

and torch.cuda.get_device_capability(data.device)[0] >= 20

修改后:

if (
qtype == qtypes["qfloat8_e4m3fn"]
and activation_qtype is None
and scale.dtype in [torch.float16, torch.bfloat16]
and len(size) == 2
and (data.device.type == "cuda" and torch.version.cuda)
and axis == 0
and torch.cuda.get_device_capability(data.device)[0] >= 8
):
out_features, in_features = size
if (
in_features >= 64
and out_features >= 64
and (
(in_features % 64 == 0 and out_features % 128 == 0)
or (in_features % 128 == 0 and out_features % 64 == 0)
)
):
return MarlinF8QBytesTensor(qtype, axis, size, stride, data, scale, requires_grad)

五、diffusers要同时设两个lora权重时,有一个不生效果

可能是设权重的方式错了:

错误方式:

self.pipe.set_adapters([LoraA], adapter_weights=[A])

self.pipe.set_adapters([LoraB], adapter_weights=[B])

正确方式:

self.pipe.set_adapters([LoraA, LoraB], adapter_weights=[A, B])

http://www.jsqmd.com/news/1309166/

相关文章:

  • AAA企业资信等级证书哪里办?线上申请方法 - 跑政通
  • Qwen2.5-1.5B模型的LoRA微调-SmoothW8A6量化-vLLM推理部署-Http服务API-并发测试流程
  • 单片机毕设项目:基于 STM32 实时电压速度距离检测小车设计 基于 PID 闭环调速的自主导航智能小车研究(017401)
  • OpenWiki vs 传统文档:Agent-as-a-Judge驱动的知识库有何不同?
  • 5步完成本地AI模型配置:PotPlayer字幕翻译插件终极指南
  • 告别腾讯游戏卡顿:ACE-Guard限制器让你的电脑重获新生
  • VMware虚拟机安装Windows 10系统 超详细图文教程
  • 【亲测免费】 ra2web.github.io:网页红井测试版一键部署
  • Parchment核心组件详解:Blot树与DOM平行世界的无缝交互
  • 终极指南:使用FinBERT构建金融情感分析系统
  • 2026深圳香港订造傢俬,看展厅别只看样板间 - 行业百科测评
  • 图论-Floyd算法学习笔记
  • 椰林海鲜码头味道正宗吗? - 晚香时候
  • 深入理解react-native-meteor内部原理:响应式数据与DDP客户端实现
  • PostgreSQL DBA 应该掌握的 100 条命令
  • 为什么你的MacBook电池损耗快?Charge Limiter帮你解决充电过度问题
  • ComfyUI-BrushNet终极探索指南:3步掌握AI图像精准修复与编辑技术
  • 90天打造高效开源协作团队:从个人项目到社区驱动的实战路径
  • ArcGIS从入门到精通——点、线、面要素输入、编辑
  • 青岛黄金回收亲身实测:避坑必看!正规回收门店挑选+交易流程 - 一日一测评
  • 三步将小爱音箱改造成AI助手:终极智能家居升级指南
  • plc三层电梯+报告12(设计源文件+万字报告+讲解)(支持资料、图片参考_相关定制)_
  • 一段会议录音是怎样变成文字和纪要的?
  • DLX终极实战指南:构建私有化翻译API服务器的完整解决方案
  • 椰林海鲜码头食材新鲜吗? - 松梢月冷
  • 一人食经济:社区面馆如何把“一个人吃饭“做成默认场景
  • 椰林海鲜码头环境干净吗? - 晚香时候
  • 市面上专业的混流风机厂商哪家专业
  • AMD Ryzen调试神器SMUDebugTool:5步掌握处理器底层调校的完整指南
  • 1企业资信等级证书怎么办?在线办理教程 - 跑政通