训练的lora文件支持导出为diffusers可用的safetensor格式吗?
如题,训练的lora文件支持导出为diffusers可用的safetensor格式吗?
我们已经在努力避免分化开源生态,flux 的 lora 训练脚本中已经支持通过参数 --align_to_opensource_format 来将 lora 文件的格式转换为其他开源项目中通用的格式,您可以提供您所需的格式,我们会晚点适配。
我们已经在努力避免分化开源生态,flux 的 lora 训练脚本中已经支持通过参数 --align_to_opensource_format 来将 lora 文件的格式转换为其他开源项目中通用的格式,您可以提供您所需的格式,我们会晚点适配。
麻烦问下,这个支持kolors模型吗?
我们已经在努力避免分化开源生态,flux 的 lora 训练脚本中已经支持通过参数 --align_to_opensource_format 来将 lora 文件的格式转换为其他开源项目中通用的格式,您可以提供您所需的格式,我们会晚点适配。
需要支持一下sdxl以及sd用于适配comfyui中使用lora.
可以通过下面代码将训练得到的kolors的lora权重转换为diffusers可以加载的ckpt格式。测试没有问题
`## 加载safetensors和state_dict import torch torch.cuda.set_device(0)
加载lora checkpoint查看config
lora_ckpt_path = "训练得到的lora权重" state_dict = torch.load(lora_ckpt_path, map_location=lambda storage, loc:storage.cuda(0))
safetensors 类型lora加载
from safetensors import safe_open #safetensor_lora = safe_open("/data1/bianjr/projects/hf-models/kolors_lora/pytorch_lora_weights.safetensors", framework="pt", device=1) state_new_key_list = [] num = 0 with safe_open("lrzjason/Kolors_depth_lora", framework="pt", device=0) as f:## 从huggingface下载diffusers可以加载的lora权重 for k in f.keys(): print(k) state_new_key_list.append(k)## 得到和diffusers同样的key #print(f.get_tensor(k).shape) num = num + 1 print(num)
state_tensor_list = [] for key,value in state_dict.items(): state_tensor_list.append(value)
new_state_dict = dict(zip(state_new_key_list, state_new_value_list)) torch.save(new_state_dict, "lora_diffusion_pipe.pth")
##测试
diffusers kolorspipeline 加载lora测试
import torch torch.cuda.set_device(0) from diffusers import KolorsPipeline model_id = "kolors模型"
pipe = KolorsPipeline.from_pretrained( model_id, torch_dtype=torch.float16, ).to("cuda") pipe.load_lora_weights("上面保存得到lora所在目录", weight_name="lora_diffusion_pipe.pth", adapter_name="kolors_lora")`
我们已经在努力避免分化开源生态,flux 的 lora 训练脚本中已经支持通过参数 --align_to_opensource_format 来将 lora 文件的格式转换为其他开源项目中通用的格式,您可以提供您所需的格式,我们会晚点适配。
可以将训练的kolors的lora模型转成safetensors格式吗?
可以通过下面代码将训练得到的kolors的lora权重转换为diffusers可以加载的ckpt格式。测试没有问题
`## 加载safetensors和state_dict import torch torch.cuda.set_device(0)
加载lora checkpoint查看config
lora_ckpt_path = "训练得到的lora权重" state_dict = torch.load(lora_ckpt_path, map_location=lambda storage, loc:storage.cuda(0))
safetensors 类型lora加载
from safetensors import safe_open #safetensor_lora = safe_open("/data1/bianjr/projects/hf-models/kolors_lora/pytorch_lora_weights.safetensors", framework="pt", device=1) state_new_key_list = [] num = 0 with safe_open("lrzjason/Kolors_depth_lora", framework="pt", device=0) as f:## 从huggingface下载diffusers可以加载的lora权重 for k in f.keys(): print(k) state_new_key_list.append(k)## 得到和diffusers同样的key #print(f.get_tensor(k).shape) num = num + 1 print(num)
state_tensor_list = [] for key,value in state_dict.items(): state_tensor_list.append(value)
new_state_dict = dict(zip(state_new_key_list, state_new_value_list)) torch.save(new_state_dict, "lora_diffusion_pipe.pth")
##测试
diffusers kolorspipeline 加载lora测试
import torch torch.cuda.set_device(0) from diffusers import KolorsPipeline model_id = "kolors模型"
pipe = KolorsPipeline.from_pretrained( model_id, torch_dtype=torch.float16, ).to("cuda") pipe.load_lora_weights("上面保存得到lora所在目录", weight_name="lora_diffusion_pipe.pth", adapter_name="kolors_lora")`
这边的kolors提供的lora训练方式是基于lightning保存的ckpt格式,和你说的完全不是一个东西。
可以通过下面代码将训练得到的kolors的lora权重转换为diffusers可以加载的ckpt格式。测试没有问题
`## 加载safetensors和state_dict import torch torch.cuda.set_device(0)
加载lora checkpoint查看config
lora_ckpt_path = "训练得到的lora权重" state_dict = torch.load(lora_ckpt_path, map_location=lambda storage, loc:storage.cuda(0))
safetensors 类型lora加载
from safetensors import safe_open #safetensor_lora = safe_open("/data1/bianjr/projects/hf-models/kolors_lora/pytorch_lora_weights.safetensors", framework="pt", device=1) state_new_key_list = [] num = 0 with safe_open("lrzjason/Kolors_depth_lora", framework="pt", device=0) as f:## 从huggingface下载diffusers可以加载的lora权重 for k in f.keys(): print(k) state_new_key_list.append(k)## 得到和diffusers同样的key #print(f.get_tensor(k).shape) num = num + 1 print(num)
state_tensor_list = [] for key,value in state_dict.items(): state_tensor_list.append(value)
new_state_dict = dict(zip(state_new_key_list, state_new_value_list)) torch.save(new_state_dict, "lora_diffusion_pipe.pth")
##测试
diffusers kolorspipeline 加载lora测试
import torch torch.cuda.set_device(0) from diffusers import KolorsPipeline model_id = "kolors模型"
pipe = KolorsPipeline.from_pretrained( model_id, torch_dtype=torch.float16, ).to("cuda") pipe.load_lora_weights("上面保存得到lora所在目录", weight_name="lora_diffusion_pipe.pth", adapter_name="kolors_lora")`
这边的kolors提供的lora训练方式是基于lightning保存的ckpt格式,和你说的完全不是一个东西。
可以通过下面代码将训练得到的kolors的lora权重转换为diffusers可以加载的ckpt格式。测试没有问题 `## 加载safetensors和state_dict import torch torch.cuda.set_device(0)
加载lora checkpoint查看config
lora_ckpt_path = "训练得到的lora权重" state_dict = torch.load(lora_ckpt_path, map_location=lambda storage, loc:storage.cuda(0))
safetensors 类型lora加载
from safetensors import safe_open #safetensor_lora = safe_open("/data1/bianjr/projects/hf-models/kolors_lora/pytorch_lora_weights.safetensors", framework="pt", device=1) state_new_key_list = [] num = 0 with safe_open("lrzjason/Kolors_depth_lora", framework="pt", device=0) as f:## 从huggingface下载diffusers可以加载的lora权重 for k in f.keys(): print(k) state_new_key_list.append(k)## 得到和diffusers同样的key #print(f.get_tensor(k).shape) num = num + 1 print(num) state_tensor_list = [] for key,value in state_dict.items(): state_tensor_list.append(value) new_state_dict = dict(zip(state_new_key_list, state_new_value_list)) torch.save(new_state_dict, "lora_diffusion_pipe.pth") ##测试
diffusers kolorspipeline 加载lora测试
import torch torch.cuda.set_device(0) from diffusers import KolorsPipeline model_id = "kolors模型" pipe = KolorsPipeline.from_pretrained( model_id, torch_dtype=torch.float16, ).to("cuda") pipe.load_lora_weights("上面保存得到lora所在目录", weight_name="lora_diffusion_pipe.pth", adapter_name="kolors_lora")`
这边的kolors提供的lora训练方式是基于lightning保存的ckpt格式,和你说的完全不是一个东西。
可以通过下面代码将训练得到的kolors的lora权重转换为diffusers可以加载的ckpt格式。测试没有问题 `## 加载safetensors和state_dict import torch torch.cuda.set_device(0)
加载lora checkpoint查看config
lora_ckpt_path = "训练得到的lora权重" state_dict = torch.load(lora_ckpt_path, map_location=lambda storage, loc:storage.cuda(0))
safetensors 类型lora加载
from safetensors import safe_open #safetensor_lora = safe_open("/data1/bianjr/projects/hf-models/kolors_lora/pytorch_lora_weights.safetensors", framework="pt", device=1) state_new_key_list = [] num = 0 with safe_open("lrzjason/Kolors_depth_lora", framework="pt", device=0) as f:## 从huggingface下载diffusers可以加载的lora权重 for k in f.keys(): print(k) state_new_key_list.append(k)## 得到和diffusers同样的key #print(f.get_tensor(k).shape) num = num + 1 print(num) state_tensor_list = [] for key,value in state_dict.items(): state_tensor_list.append(value) new_state_dict = dict(zip(state_new_key_list, state_new_value_list)) torch.save(new_state_dict, "lora_diffusion_pipe.pth") ##测试
diffusers kolorspipeline 加载lora测试
import torch torch.cuda.set_device(0) from diffusers import KolorsPipeline model_id = "kolors模型" pipe = KolorsPipeline.from_pretrained( model_id, torch_dtype=torch.float16, ).to("cuda") pipe.load_lora_weights("上面保存得到lora所在目录", weight_name="lora_diffusion_pipe.pth", adapter_name="kolors_lora")`
这边的kolors提供的lora训练方式是基于lightning保存的ckpt格式,和你说的完全不是一个东西。
上面的代码将这边基于lightning得到的权重文件可以转换为diffusers可以直接加载的格式,只不过不是safetensors格式,已经经过多次测试没有问题了