PixArt KSampler support
Thanks to @lawrence-cj for his help on this!
This commit is contained in:
+30
-14
@@ -3,22 +3,38 @@ List of all PixArt model types / settings
|
|||||||
"""
|
"""
|
||||||
pixart_conf = {
|
pixart_conf = {
|
||||||
"PixArtMS_XL_2": { # models/PixArtMS
|
"PixArtMS_XL_2": { # models/PixArtMS
|
||||||
"target" : "PixArtMS",
|
"target": "PixArtMS",
|
||||||
"input_size" : 1024//8,
|
"unet_config": {
|
||||||
"lewei_scale" : 2,
|
"input_size" : 1024//8,
|
||||||
"depth" : 28,
|
"lewei_scale" : 2,
|
||||||
"num_heads" : 16,
|
"depth" : 28,
|
||||||
"patch_size" : 2,
|
"num_heads" : 16,
|
||||||
"hidden_size" : 1152,
|
"patch_size" : 2,
|
||||||
|
"hidden_size" : 1152,
|
||||||
|
},
|
||||||
|
"sampling_settings": {
|
||||||
|
"beta_schedule" : "sqrt_linear",
|
||||||
|
"linear_start" : 0.0001,
|
||||||
|
"linear_end" : 0.02,
|
||||||
|
"timesteps" : 1000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"PixArt_XL_2": { # models/PixArt
|
"PixArt_XL_2": { # models/PixArt
|
||||||
"target" : "PixArt",
|
"target": "PixArt",
|
||||||
"input_size" : 512//8,
|
"unet_config": {
|
||||||
"lewei_scale" : 1,
|
"input_size" : 512//8,
|
||||||
"depth" : 28,
|
"lewei_scale" : 1,
|
||||||
"num_heads" : 16,
|
"depth" : 28,
|
||||||
"patch_size" : 2,
|
"num_heads" : 16,
|
||||||
"hidden_size" : 1152,
|
"patch_size" : 2,
|
||||||
|
"hidden_size" : 1152,
|
||||||
|
},
|
||||||
|
"sampling_settings": {
|
||||||
|
"beta_schedule" : "sqrt_linear",
|
||||||
|
"linear_start" : 0.0001,
|
||||||
|
"linear_end" : 0.02,
|
||||||
|
"timesteps" : 1000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-6
@@ -13,6 +13,14 @@ class EXM_PixArt(comfy.supported_models_base.BASE):
|
|||||||
unet_extra_config = {}
|
unet_extra_config = {}
|
||||||
latent_format = comfy.latent_formats.SD15
|
latent_format = comfy.latent_formats.SD15
|
||||||
|
|
||||||
|
def __init__(self, model_conf):
|
||||||
|
self.model_target = model_conf.get("target")
|
||||||
|
self.unet_config = model_conf.get("unet_config", {})
|
||||||
|
self.sampling_settings = model_conf.get("sampling_settings", {})
|
||||||
|
self.latent_format = self.latent_format()
|
||||||
|
# UNET is handled by extension
|
||||||
|
self.unet_config["disable_unet_model_creation"] = True
|
||||||
|
|
||||||
def model_type(self, state_dict, prefix=""):
|
def model_type(self, state_dict, prefix=""):
|
||||||
return comfy.model_base.ModelType.EPS
|
return comfy.model_base.ModelType.EPS
|
||||||
|
|
||||||
@@ -22,21 +30,23 @@ def load_pixart(model_path, model_conf):
|
|||||||
parameters = comfy.utils.calculate_parameters(state_dict)
|
parameters = comfy.utils.calculate_parameters(state_dict)
|
||||||
unet_dtype = model_management.unet_dtype(model_params=parameters)
|
unet_dtype = model_management.unet_dtype(model_params=parameters)
|
||||||
|
|
||||||
|
model_conf = EXM_PixArt(model_conf) # convert to object
|
||||||
|
|
||||||
model = comfy.model_base.BaseModel(
|
model = comfy.model_base.BaseModel(
|
||||||
EXM_PixArt({"disable_unet_model_creation" : True }),
|
model_conf,
|
||||||
model_type=comfy.model_base.ModelType.EPS,
|
model_type=comfy.model_base.ModelType.EPS,
|
||||||
device=model_management.get_torch_device()
|
device=model_management.get_torch_device()
|
||||||
)
|
)
|
||||||
|
|
||||||
model.pixart_config = model_conf
|
model.pixart_config = model_conf
|
||||||
if model_conf["target"] == "PixArtMS":
|
if model_conf.model_target == "PixArtMS":
|
||||||
from .models.PixArtMS import PixArtMS
|
from .models.PixArtMS import PixArtMS
|
||||||
model.diffusion_model = PixArtMS(**model_conf)
|
model.diffusion_model = PixArtMS(**model_conf.unet_config)
|
||||||
elif model_conf["target"] == "PixArt":
|
elif model_conf.model_target == "PixArt":
|
||||||
from .models.PixArt import PixArt
|
from .models.PixArt import PixArt
|
||||||
model.diffusion_model = PixArt(**model_conf)
|
model.diffusion_model = PixArt(**model_conf.unet_config)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError(f"Unknown model target '{model_conf.model_target}'")
|
||||||
|
|
||||||
model.diffusion_model.load_state_dict(state_dict)
|
model.diffusion_model.load_state_dict(state_dict)
|
||||||
model.diffusion_model.dtype = unet_dtype
|
model.diffusion_model.dtype = unet_dtype
|
||||||
|
|||||||
Reference in New Issue
Block a user