hcpdiff 0.9.1__tar.gz → 2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. hcpdiff-2.1/PKG-INFO +285 -0
  2. hcpdiff-2.1/README.md +248 -0
  3. hcpdiff-2.1/hcpdiff/__init__.py +4 -0
  4. hcpdiff-2.1/hcpdiff/ckpt_manager/__init__.py +4 -0
  5. hcpdiff-2.1/hcpdiff/ckpt_manager/ckpt.py +24 -0
  6. hcpdiff-2.1/hcpdiff/ckpt_manager/format/__init__.py +4 -0
  7. hcpdiff-2.1/hcpdiff/ckpt_manager/format/diffusers.py +59 -0
  8. hcpdiff-2.1/hcpdiff/ckpt_manager/format/emb.py +21 -0
  9. hcpdiff-2.1/hcpdiff/ckpt_manager/format/lora_webui.py +244 -0
  10. hcpdiff-2.1/hcpdiff/ckpt_manager/format/sd_single.py +41 -0
  11. hcpdiff-2.1/hcpdiff/ckpt_manager/loader.py +64 -0
  12. hcpdiff-2.1/hcpdiff/data/__init__.py +4 -0
  13. hcpdiff-2.1/hcpdiff/data/cache/__init__.py +1 -0
  14. hcpdiff-2.1/hcpdiff/data/cache/vae.py +102 -0
  15. hcpdiff-2.1/hcpdiff/data/dataset.py +20 -0
  16. hcpdiff-2.1/hcpdiff/data/handler/__init__.py +3 -0
  17. hcpdiff-2.1/hcpdiff/data/handler/controlnet.py +18 -0
  18. hcpdiff-2.1/hcpdiff/data/handler/diffusion.py +80 -0
  19. hcpdiff-2.1/hcpdiff/data/handler/text.py +111 -0
  20. hcpdiff-2.1/hcpdiff/data/source/__init__.py +3 -0
  21. hcpdiff-2.1/hcpdiff/data/source/folder_class.py +23 -0
  22. hcpdiff-2.1/hcpdiff/data/source/text2img.py +53 -0
  23. hcpdiff-2.1/hcpdiff/data/source/text2img_cond.py +16 -0
  24. hcpdiff-2.1/hcpdiff/diffusion/noise/__init__.py +2 -0
  25. hcpdiff-2.1/hcpdiff/diffusion/noise/pyramid_noise.py +42 -0
  26. hcpdiff-2.1/hcpdiff/diffusion/noise/zero_terminal.py +39 -0
  27. hcpdiff-2.1/hcpdiff/diffusion/sampler/__init__.py +5 -0
  28. hcpdiff-2.1/hcpdiff/diffusion/sampler/base.py +72 -0
  29. hcpdiff-2.1/hcpdiff/diffusion/sampler/ddpm.py +20 -0
  30. hcpdiff-2.1/hcpdiff/diffusion/sampler/diffusers.py +66 -0
  31. hcpdiff-2.1/hcpdiff/diffusion/sampler/edm.py +22 -0
  32. hcpdiff-2.1/hcpdiff/diffusion/sampler/sigma_scheduler/__init__.py +3 -0
  33. hcpdiff-2.1/hcpdiff/diffusion/sampler/sigma_scheduler/base.py +14 -0
  34. hcpdiff-2.1/hcpdiff/diffusion/sampler/sigma_scheduler/ddpm.py +197 -0
  35. hcpdiff-2.1/hcpdiff/diffusion/sampler/sigma_scheduler/edm.py +48 -0
  36. hcpdiff-2.1/hcpdiff/easy/__init__.py +2 -0
  37. hcpdiff-2.1/hcpdiff/easy/cfg/__init__.py +3 -0
  38. hcpdiff-2.1/hcpdiff/easy/cfg/sd15_train.py +201 -0
  39. hcpdiff-2.1/hcpdiff/easy/cfg/sdxl_train.py +140 -0
  40. hcpdiff-2.1/hcpdiff/easy/cfg/t2i.py +177 -0
  41. hcpdiff-2.1/hcpdiff/easy/model/__init__.py +2 -0
  42. hcpdiff-2.1/hcpdiff/easy/model/cnet.py +31 -0
  43. hcpdiff-2.1/hcpdiff/easy/model/loader.py +79 -0
  44. hcpdiff-2.1/hcpdiff/easy/sampler.py +46 -0
  45. hcpdiff-2.1/hcpdiff/evaluate/__init__.py +1 -0
  46. hcpdiff-2.1/hcpdiff/evaluate/previewer.py +60 -0
  47. hcpdiff-2.1/hcpdiff/loss/__init__.py +4 -0
  48. hcpdiff-2.1/hcpdiff/loss/base.py +41 -0
  49. hcpdiff-2.1/hcpdiff/loss/gw.py +35 -0
  50. hcpdiff-2.1/hcpdiff/loss/ssim.py +37 -0
  51. hcpdiff-2.1/hcpdiff/loss/vlb.py +79 -0
  52. hcpdiff-2.1/hcpdiff/loss/weighting.py +66 -0
  53. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/__init__.py +2 -2
  54. hcpdiff-2.1/hcpdiff/models/cfg_context.py +42 -0
  55. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/compose/compose_hook.py +44 -23
  56. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/compose/compose_tokenizer.py +21 -8
  57. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/compose/sdxl_composer.py +4 -4
  58. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/controlnet.py +16 -16
  59. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/lora_base_patch.py +14 -25
  60. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/lora_layers.py +3 -9
  61. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/lora_layers_patch.py +14 -24
  62. hcpdiff-2.1/hcpdiff/models/text_emb_ex.py +172 -0
  63. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/textencoder_ex.py +54 -18
  64. hcpdiff-2.1/hcpdiff/models/wrapper/__init__.py +3 -0
  65. hcpdiff-2.1/hcpdiff/models/wrapper/pixart.py +19 -0
  66. hcpdiff-2.1/hcpdiff/models/wrapper/sd.py +218 -0
  67. hcpdiff-2.1/hcpdiff/models/wrapper/utils.py +20 -0
  68. hcpdiff-2.1/hcpdiff/parser/__init__.py +1 -0
  69. hcpdiff-2.1/hcpdiff/parser/embpt.py +32 -0
  70. hcpdiff-2.1/hcpdiff/tools/__init__.py +0 -0
  71. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/convert_caption_txt2json.py +1 -1
  72. hcpdiff-2.1/hcpdiff/tools/dataset_generator.py +94 -0
  73. hcpdiff-2.1/hcpdiff/tools/download_hf_model.py +24 -0
  74. hcpdiff-2.1/hcpdiff/tools/init_proj.py +5 -0
  75. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/lora_convert.py +18 -17
  76. hcpdiff-2.1/hcpdiff/tools/save_model.py +12 -0
  77. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/sd2diffusers.py +1 -1
  78. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/train_colo.py +1 -1
  79. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/train_deepspeed.py +1 -1
  80. hcpdiff-2.1/hcpdiff/trainer_ac.py +79 -0
  81. hcpdiff-2.1/hcpdiff/trainer_ac_single.py +31 -0
  82. hcpdiff-2.1/hcpdiff/utils/__init__.py +2 -0
  83. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/utils/inpaint_pipe.py +7 -2
  84. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/utils/net_utils.py +29 -6
  85. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/utils/pipe_hook.py +24 -7
  86. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/utils/utils.py +21 -4
  87. hcpdiff-2.1/hcpdiff/workflow/__init__.py +20 -0
  88. hcpdiff-2.1/hcpdiff/workflow/daam/__init__.py +1 -0
  89. hcpdiff-2.1/hcpdiff/workflow/daam/act.py +66 -0
  90. hcpdiff-2.1/hcpdiff/workflow/daam/hook.py +109 -0
  91. hcpdiff-2.1/hcpdiff/workflow/diffusion.py +198 -0
  92. hcpdiff-2.1/hcpdiff/workflow/fast.py +31 -0
  93. hcpdiff-2.1/hcpdiff/workflow/flow.py +67 -0
  94. hcpdiff-2.1/hcpdiff/workflow/io.py +56 -0
  95. hcpdiff-2.1/hcpdiff/workflow/model.py +70 -0
  96. hcpdiff-2.1/hcpdiff/workflow/text.py +112 -0
  97. hcpdiff-2.1/hcpdiff/workflow/utils.py +53 -0
  98. hcpdiff-2.1/hcpdiff/workflow/vae.py +72 -0
  99. hcpdiff-2.1/hcpdiff.egg-info/PKG-INFO +285 -0
  100. hcpdiff-2.1/hcpdiff.egg-info/SOURCES.txt +117 -0
  101. hcpdiff-2.1/hcpdiff.egg-info/entry_points.txt +5 -0
  102. hcpdiff-2.1/hcpdiff.egg-info/requires.txt +7 -0
  103. {hcpdiff-0.9.1 → hcpdiff-2.1}/setup.py +12 -27
  104. hcpdiff-0.9.1/PKG-INFO +0 -199
  105. hcpdiff-0.9.1/README.md +0 -158
  106. hcpdiff-0.9.1/cfgs/infer/anime/text2img_anime.yaml +0 -21
  107. hcpdiff-0.9.1/cfgs/infer/anime/text2img_anime_lora.yaml +0 -58
  108. hcpdiff-0.9.1/cfgs/infer/change_vae.yaml +0 -6
  109. hcpdiff-0.9.1/cfgs/infer/euler_a.yaml +0 -8
  110. hcpdiff-0.9.1/cfgs/infer/img2img.yaml +0 -10
  111. hcpdiff-0.9.1/cfgs/infer/img2img_controlnet.yaml +0 -19
  112. hcpdiff-0.9.1/cfgs/infer/inpaint.yaml +0 -11
  113. hcpdiff-0.9.1/cfgs/infer/load_lora.yaml +0 -26
  114. hcpdiff-0.9.1/cfgs/infer/load_unet_part.yaml +0 -18
  115. hcpdiff-0.9.1/cfgs/infer/offload_2GB.yaml +0 -6
  116. hcpdiff-0.9.1/cfgs/infer/save_model.yaml +0 -44
  117. hcpdiff-0.9.1/cfgs/infer/text2img.yaml +0 -53
  118. hcpdiff-0.9.1/cfgs/infer/text2img_DA++.yaml +0 -34
  119. hcpdiff-0.9.1/cfgs/infer/text2img_sdxl.yaml +0 -9
  120. hcpdiff-0.9.1/cfgs/plugins/plugin_controlnet.yaml +0 -17
  121. hcpdiff-0.9.1/cfgs/te_struct.txt +0 -193
  122. hcpdiff-0.9.1/cfgs/train/dataset/base_dataset.yaml +0 -29
  123. hcpdiff-0.9.1/cfgs/train/dataset/regularization_dataset.yaml +0 -31
  124. hcpdiff-0.9.1/cfgs/train/examples/CustomDiffusion.yaml +0 -74
  125. hcpdiff-0.9.1/cfgs/train/examples/DreamArtist++.yaml +0 -135
  126. hcpdiff-0.9.1/cfgs/train/examples/DreamArtist.yaml +0 -45
  127. hcpdiff-0.9.1/cfgs/train/examples/DreamBooth.yaml +0 -62
  128. hcpdiff-0.9.1/cfgs/train/examples/FT_sdxl.yaml +0 -33
  129. hcpdiff-0.9.1/cfgs/train/examples/Lion_optimizer.yaml +0 -17
  130. hcpdiff-0.9.1/cfgs/train/examples/TextualInversion.yaml +0 -41
  131. hcpdiff-0.9.1/cfgs/train/examples/add_logger_tensorboard_wandb.yaml +0 -15
  132. hcpdiff-0.9.1/cfgs/train/examples/controlnet.yaml +0 -53
  133. hcpdiff-0.9.1/cfgs/train/examples/ema.yaml +0 -10
  134. hcpdiff-0.9.1/cfgs/train/examples/fine-tuning.yaml +0 -53
  135. hcpdiff-0.9.1/cfgs/train/examples/locon.yaml +0 -24
  136. hcpdiff-0.9.1/cfgs/train/examples/lora_anime_character.yaml +0 -77
  137. hcpdiff-0.9.1/cfgs/train/examples/lora_conventional.yaml +0 -56
  138. hcpdiff-0.9.1/cfgs/train/examples/lora_sdxl.yaml +0 -41
  139. hcpdiff-0.9.1/cfgs/train/examples/min_snr.yaml +0 -7
  140. hcpdiff-0.9.1/cfgs/train/examples/preview_in_training.yaml +0 -6
  141. hcpdiff-0.9.1/cfgs/train/examples_noob/DreamBooth.yaml +0 -70
  142. hcpdiff-0.9.1/cfgs/train/examples_noob/TextualInversion.yaml +0 -45
  143. hcpdiff-0.9.1/cfgs/train/examples_noob/fine-tuning.yaml +0 -45
  144. hcpdiff-0.9.1/cfgs/train/examples_noob/lora.yaml +0 -63
  145. hcpdiff-0.9.1/cfgs/train/train_base.yaml +0 -81
  146. hcpdiff-0.9.1/cfgs/train/tuning_base.yaml +0 -42
  147. hcpdiff-0.9.1/cfgs/unet_struct.txt +0 -932
  148. hcpdiff-0.9.1/cfgs/workflow/highres_fix_latent.yaml +0 -86
  149. hcpdiff-0.9.1/cfgs/workflow/highres_fix_pixel.yaml +0 -99
  150. hcpdiff-0.9.1/cfgs/workflow/text2img.yaml +0 -59
  151. hcpdiff-0.9.1/cfgs/workflow/text2img_lora.yaml +0 -70
  152. hcpdiff-0.9.1/cfgs/zero2.json +0 -32
  153. hcpdiff-0.9.1/cfgs/zero3.json +0 -39
  154. hcpdiff-0.9.1/hcpdiff/__init__.py +0 -4
  155. hcpdiff-0.9.1/hcpdiff/ckpt_manager/__init__.py +0 -5
  156. hcpdiff-0.9.1/hcpdiff/ckpt_manager/base.py +0 -16
  157. hcpdiff-0.9.1/hcpdiff/ckpt_manager/ckpt_diffusers.py +0 -45
  158. hcpdiff-0.9.1/hcpdiff/ckpt_manager/ckpt_pkl.py +0 -138
  159. hcpdiff-0.9.1/hcpdiff/ckpt_manager/ckpt_safetensor.py +0 -64
  160. hcpdiff-0.9.1/hcpdiff/ckpt_manager/ckpt_webui.py +0 -54
  161. hcpdiff-0.9.1/hcpdiff/data/__init__.py +0 -28
  162. hcpdiff-0.9.1/hcpdiff/data/bucket.py +0 -358
  163. hcpdiff-0.9.1/hcpdiff/data/caption_loader.py +0 -80
  164. hcpdiff-0.9.1/hcpdiff/data/cond_dataset.py +0 -40
  165. hcpdiff-0.9.1/hcpdiff/data/crop_info_dataset.py +0 -40
  166. hcpdiff-0.9.1/hcpdiff/data/data_processor.py +0 -33
  167. hcpdiff-0.9.1/hcpdiff/data/pair_dataset.py +0 -146
  168. hcpdiff-0.9.1/hcpdiff/data/sampler.py +0 -54
  169. hcpdiff-0.9.1/hcpdiff/data/source/__init__.py +0 -4
  170. hcpdiff-0.9.1/hcpdiff/data/source/base.py +0 -30
  171. hcpdiff-0.9.1/hcpdiff/data/source/folder_class.py +0 -40
  172. hcpdiff-0.9.1/hcpdiff/data/source/text2img.py +0 -91
  173. hcpdiff-0.9.1/hcpdiff/data/source/text2img_cond.py +0 -22
  174. hcpdiff-0.9.1/hcpdiff/data/utils.py +0 -80
  175. hcpdiff-0.9.1/hcpdiff/deprecated/__init__.py +0 -1
  176. hcpdiff-0.9.1/hcpdiff/deprecated/cfg_converter.py +0 -81
  177. hcpdiff-0.9.1/hcpdiff/deprecated/lora_convert.py +0 -31
  178. hcpdiff-0.9.1/hcpdiff/infer_workflow.py +0 -57
  179. hcpdiff-0.9.1/hcpdiff/loggers/__init__.py +0 -13
  180. hcpdiff-0.9.1/hcpdiff/loggers/base_logger.py +0 -76
  181. hcpdiff-0.9.1/hcpdiff/loggers/cli_logger.py +0 -40
  182. hcpdiff-0.9.1/hcpdiff/loggers/preview/__init__.py +0 -1
  183. hcpdiff-0.9.1/hcpdiff/loggers/preview/image_previewer.py +0 -149
  184. hcpdiff-0.9.1/hcpdiff/loggers/tensorboard_logger.py +0 -30
  185. hcpdiff-0.9.1/hcpdiff/loggers/wandb_logger.py +0 -31
  186. hcpdiff-0.9.1/hcpdiff/loggers/webui_logger.py +0 -9
  187. hcpdiff-0.9.1/hcpdiff/loss/__init__.py +0 -1
  188. hcpdiff-0.9.1/hcpdiff/loss/min_snr_loss.py +0 -52
  189. hcpdiff-0.9.1/hcpdiff/models/cfg_context.py +0 -39
  190. hcpdiff-0.9.1/hcpdiff/models/layers.py +0 -81
  191. hcpdiff-0.9.1/hcpdiff/models/plugin.py +0 -348
  192. hcpdiff-0.9.1/hcpdiff/models/text_emb_ex.py +0 -94
  193. hcpdiff-0.9.1/hcpdiff/models/wrapper.py +0 -75
  194. hcpdiff-0.9.1/hcpdiff/noise/__init__.py +0 -3
  195. hcpdiff-0.9.1/hcpdiff/noise/noise_base.py +0 -16
  196. hcpdiff-0.9.1/hcpdiff/noise/pyramid_noise.py +0 -50
  197. hcpdiff-0.9.1/hcpdiff/noise/zero_terminal.py +0 -44
  198. hcpdiff-0.9.1/hcpdiff/tools/init_proj.py +0 -23
  199. hcpdiff-0.9.1/hcpdiff/train_ac.py +0 -566
  200. hcpdiff-0.9.1/hcpdiff/train_ac_single.py +0 -39
  201. hcpdiff-0.9.1/hcpdiff/utils/__init__.py +0 -4
  202. hcpdiff-0.9.1/hcpdiff/utils/caption_tools.py +0 -105
  203. hcpdiff-0.9.1/hcpdiff/utils/cfg_net_tools.py +0 -321
  204. hcpdiff-0.9.1/hcpdiff/utils/cfg_resolvers.py +0 -16
  205. hcpdiff-0.9.1/hcpdiff/utils/ema.py +0 -52
  206. hcpdiff-0.9.1/hcpdiff/utils/img_size_tool.py +0 -248
  207. hcpdiff-0.9.1/hcpdiff/vis/__init__.py +0 -3
  208. hcpdiff-0.9.1/hcpdiff/vis/base_interface.py +0 -12
  209. hcpdiff-0.9.1/hcpdiff/vis/disk_interface.py +0 -48
  210. hcpdiff-0.9.1/hcpdiff/vis/webui_interface.py +0 -17
  211. hcpdiff-0.9.1/hcpdiff/viser_fast.py +0 -138
  212. hcpdiff-0.9.1/hcpdiff/visualizer.py +0 -265
  213. hcpdiff-0.9.1/hcpdiff/visualizer_reloadable.py +0 -237
  214. hcpdiff-0.9.1/hcpdiff/workflow/__init__.py +0 -15
  215. hcpdiff-0.9.1/hcpdiff/workflow/base.py +0 -59
  216. hcpdiff-0.9.1/hcpdiff/workflow/diffusion.py +0 -209
  217. hcpdiff-0.9.1/hcpdiff/workflow/io.py +0 -150
  218. hcpdiff-0.9.1/hcpdiff/workflow/model.py +0 -67
  219. hcpdiff-0.9.1/hcpdiff/workflow/text.py +0 -80
  220. hcpdiff-0.9.1/hcpdiff/workflow/utils.py +0 -33
  221. hcpdiff-0.9.1/hcpdiff/workflow/vae.py +0 -73
  222. hcpdiff-0.9.1/hcpdiff.egg-info/PKG-INFO +0 -199
  223. hcpdiff-0.9.1/hcpdiff.egg-info/SOURCES.txt +0 -163
  224. hcpdiff-0.9.1/hcpdiff.egg-info/entry_points.txt +0 -2
  225. hcpdiff-0.9.1/hcpdiff.egg-info/requires.txt +0 -22
  226. hcpdiff-0.9.1/prompt_tuning_template/caption.txt +0 -1
  227. hcpdiff-0.9.1/prompt_tuning_template/name.txt +0 -1
  228. hcpdiff-0.9.1/prompt_tuning_template/name_2pt_caption.txt +0 -1
  229. hcpdiff-0.9.1/prompt_tuning_template/name_caption.txt +0 -1
  230. hcpdiff-0.9.1/prompt_tuning_template/object.txt +0 -27
  231. hcpdiff-0.9.1/prompt_tuning_template/object_caption.txt +0 -27
  232. hcpdiff-0.9.1/prompt_tuning_template/style.txt +0 -19
  233. hcpdiff-0.9.1/prompt_tuning_template/style_caption.txt +0 -19
  234. {hcpdiff-0.9.1 → hcpdiff-2.1}/LICENSE +0 -0
  235. {hcpdiff-0.9.1/hcpdiff/tools → hcpdiff-2.1/hcpdiff/diffusion}/__init__.py +0 -0
  236. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/compose/__init__.py +0 -0
  237. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/compose/compose_textencoder.py +0 -0
  238. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/container.py +0 -0
  239. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/lora_base.py +0 -0
  240. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/models/tokenizer_ex.py +0 -0
  241. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/convert_old_lora.py +0 -0
  242. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/create_embedding.py +0 -0
  243. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/diffusers2sd.py +0 -0
  244. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/embedding_convert.py +0 -0
  245. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/tools/gen_from_ptlist.py +0 -0
  246. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff/utils/colo_utils.py +0 -0
  247. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff.egg-info/dependency_links.txt +0 -0
  248. {hcpdiff-0.9.1 → hcpdiff-2.1}/hcpdiff.egg-info/top_level.txt +0 -0
  249. {hcpdiff-0.9.1 → hcpdiff-2.1}/setup.cfg +0 -0
hcpdiff-2.1/PKG-INFO ADDED
@@ -0,0 +1,285 @@
1
+ Metadata-Version: 2.4
2
+ Name: hcpdiff
3
+ Version: 2.1
4
+ Summary: A universal Diffusion toolbox
5
+ Home-page: https://github.com/IrisRainbowNeko/HCP-Diffusion
6
+ Author: Ziyi Dong
7
+ Author-email: rainbow-neko@outlook.com
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: rainbowneko
21
+ Requires-Dist: diffusers
22
+ Requires-Dist: matplotlib
23
+ Requires-Dist: pyarrow
24
+ Requires-Dist: transformers>=4.25.1
25
+ Requires-Dist: pytorch-msssim
26
+ Requires-Dist: lmdb
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: description-content-type
32
+ Dynamic: home-page
33
+ Dynamic: license-file
34
+ Dynamic: requires-dist
35
+ Dynamic: requires-python
36
+ Dynamic: summary
37
+
38
+ # HCP-Diffusion V2
39
+
40
+ [![PyPI](https://img.shields.io/pypi/v/hcpdiff)](https://pypi.org/project/hcpdiff/)
41
+ [![GitHub stars](https://img.shields.io/github/stars/7eu7d7/HCP-Diffusion)](https://github.com/7eu7d7/HCP-Diffusion/stargazers)
42
+ [![GitHub license](https://img.shields.io/github/license/7eu7d7/HCP-Diffusion)](https://github.com/7eu7d7/HCP-Diffusion/blob/master/LICENSE)
43
+ [![codecov](https://codecov.io/gh/7eu7d7/HCP-Diffusion/branch/main/graph/badge.svg)](https://codecov.io/gh/7eu7d7/HCP-Diffusion)
44
+ [![open issues](https://isitmaintained.com/badge/open/7eu7d7/HCP-Diffusion.svg)](https://github.com/7eu7d7/HCP-Diffusion/issues)
45
+
46
+ [📘中文说明](./README_cn.md)
47
+
48
+ [📘English document](https://hcpdiff.readthedocs.io/en/latest/)
49
+ [📘中文文档](https://hcpdiff.readthedocs.io/zh_CN/latest/)
50
+
51
+ Old HCP-Diffusion V1 at [main branch](https://github.com/IrisRainbowNeko/HCP-Diffusion/tree/main)
52
+
53
+ ## Introduction
54
+
55
+ **HCP-Diffusion** is a Diffusion model toolbox built on top of the [🐱 RainbowNeko Engine](https://github.com/IrisRainbowNeko/RainbowNekoEngine).
56
+ It features a clean code structure and a flexible **Python-based configuration file**, making it easier to conduct and manage complex experiments. It includes a wide variety of training components, and compared to existing frameworks, it's more extensible, flexible, and user-friendly.
57
+
58
+ HCP-Diffusion allows you to use a single `.py` config file to unify training workflows across popular methods and model architectures, including Prompt-tuning (Textual Inversion), DreamArtist, Fine-tuning, DreamBooth, LoRA, ControlNet, ....
59
+ Different techniques can also be freely combined.
60
+
61
+ This framework also implements **DreamArtist++**, an upgraded version of DreamArtist based on LoRA. It enables high generalization and controllability with just a single image for training.
62
+ Compared to the original DreamArtist, it offers better stability, image quality, controllability, and faster training.
63
+
64
+ ---
65
+
66
+ ## Installation
67
+
68
+ Install via pip:
69
+
70
+ ```bash
71
+ pip install hcpdiff
72
+ # Initialize configuration
73
+ hcpinit
74
+ ```
75
+
76
+ Install from source:
77
+
78
+ ```bash
79
+ git clone https://github.com/7eu7d7/HCP-Diffusion.git
80
+ cd HCP-Diffusion
81
+ pip install -e .
82
+ # Initialize configuration
83
+ hcpinit
84
+ ```
85
+
86
+ Use xFormers to reduce memory usage and accelerate training:
87
+
88
+ ```bash
89
+ # Choose the appropriate xformers version for your PyTorch version
90
+ pip install xformers==?
91
+ ```
92
+
93
+ ## 🚀 Python Configuration Files
94
+ RainbowNeko Engine supports configuration files written in a Python-like syntax. This allows users to call functions and classes directly within the configuration file, with function parameters inheritable from parent configuration files. The framework automatically handles the formatting of these configuration files.
95
+
96
+ For example, consider the following configuration file:
97
+ ```python
98
+ dict(
99
+ layer=Linear(in_features=4, out_features=4)
100
+ )
101
+ ```
102
+ During parsing, this will be automatically compiled into:
103
+ ```python
104
+ dict(
105
+ layer=dict(_target_=Linear, in_features=4, out_features=4)
106
+ )
107
+ ```
108
+ After parsing, the framework will instantiate the components accordingly. This means users can write configuration files using familiar Python syntax.
109
+
110
+ ---
111
+
112
+ ## ✨ Features
113
+
114
+ <details>
115
+ <summary>Features</summary>
116
+
117
+ ### 📦 Model Support
118
+
119
+ | Model Name | Status |
120
+ |--------------------------|-------------|
121
+ | Stable Diffusion 1.5 | ✅ Supported |
122
+ | Stable Diffusion XL (SDXL)| ✅ Supported |
123
+ | PixArt | ✅ Supported |
124
+ | FLUX | 🚧 In Development |
125
+ | Stable Diffusion 3 (SD3) | 🚧 In Development |
126
+
127
+ ---
128
+
129
+ ### 🧠 Fine-Tuning Capabilities
130
+
131
+ | Feature | Description/Support |
132
+ |----------------------------------|---------------------|
133
+ | LoRA Layer-wise Configuration | ✅ Supported (including Conv2d) |
134
+ | Layer-wise Fine-Tuning | ✅ Supported |
135
+ | Multi-token Prompt-Tuning | ✅ Supported |
136
+ | Layer-wise Model Merging | ✅ Supported |
137
+ | Custom Optimizers | ✅ Supported (Lion, DAdaptation, pytorch-optimizer, etc.) |
138
+ | Custom LR Schedulers | ✅ Supported |
139
+
140
+ ---
141
+
142
+ ### 🧩 Extension Method Support
143
+
144
+ | Method | Status |
145
+ |--------------------------------|-------------|
146
+ | ControlNet (including training)| ✅ Supported |
147
+ | DreamArtist / DreamArtist++ | ✅ Supported |
148
+ | Token Attention Adjustment | ✅ Supported |
149
+ | Max Sentence Length Extension | ✅ Supported |
150
+ | Textual Inversion (Custom Tokens)| ✅ Supported |
151
+ | CLIP Skip | ✅ Supported |
152
+
153
+ ---
154
+
155
+ ### 🚀 Training Acceleration
156
+
157
+ | Tool/Library | Supported Modules |
158
+ |---------------------------------------------------|---------------------------|
159
+ | [🤗 Accelerate](https://github.com/huggingface/accelerate) | ✅ Supported |
160
+ | [Colossal-AI](https://github.com/hpcaitech/ColossalAI) | ✅ Supported |
161
+ | [xFormers](https://github.com/facebookresearch/xformers) | ✅ Supported (UNet and text encoder) |
162
+
163
+ ---
164
+
165
+ ### 🗂 Dataset Support
166
+
167
+ | Feature | Description |
168
+ |----------------------------------|-------------|
169
+ | Aspect Ratio Bucket (ARB) | ✅ Auto-clustering supported |
170
+ | Multi-source / Multi-dataset | ✅ Supported |
171
+ | LMDB | ✅ Supported |
172
+ | webdataset | 🚧 In Development |
173
+ | Local Attention Enhancement | ✅ Supported |
174
+ | Tag Shuffling & Dropout | ✅ Multiple tag editing strategies |
175
+
176
+ ---
177
+
178
+ ### 📉 Supported Loss Functions
179
+
180
+ | Loss Type | Description |
181
+ |------------|-------------|
182
+ | Min-SNR | ✅ Supported |
183
+ | SSIM | ✅ Supported |
184
+ | GWLoss | ✅ Supported |
185
+
186
+ ---
187
+
188
+ ### 🌫 Supported Diffusion Strategies
189
+
190
+ | Strategy Type | Status |
191
+ |------------------|--------------|
192
+ | DDPM | ✅ Supported |
193
+ | EDM | ✅ Supported |
194
+ | Flow Matching | ✅ Supported |
195
+
196
+ ---
197
+
198
+ ### 🧠 Automatic Evaluation (Step Selection Assistant)
199
+
200
+ | Feature | Description/Status |
201
+ |------------------|------------------------------------------|
202
+ | Image Preview | ✅ Supported (workflow preview) |
203
+ | FID | 🚧 In Development |
204
+ | CLIP Score | 🚧 In Development |
205
+ | CCIP Score | 🚧 In Development |
206
+ | Corrupt Score | 🚧 In Development |
207
+
208
+ </details>
209
+
210
+ ---
211
+
212
+ ## Getting Started
213
+
214
+ ### Training
215
+
216
+ HCP-Diffusion provides training scripts based on 🤗 Accelerate.
217
+
218
+ ```bash
219
+ # Multi-GPU training, configure GPUs in cfgs/launcher/multi.yaml
220
+ hcp_train --cfg cfgs/train/py/your_config.py
221
+
222
+ # Single-GPU training, configure GPU in cfgs/launcher/single.yaml
223
+ hcp_train_1gpu --cfg cfgs/train/py/your_config.py
224
+ ```
225
+
226
+ You can also override config items via command line:
227
+
228
+ ```bash
229
+ # Override base model path
230
+ hcp_train --cfg cfgs/train/py/your_config.py model.wrapper.models.ckpt_path=pretrained_model_path
231
+ ```
232
+
233
+ ### Image Generation
234
+
235
+ Use the workflow defined in the Python config to generate images:
236
+
237
+ ```bash
238
+ hcp_run --cfg cfgs/workflow/text2img.py
239
+ ```
240
+
241
+ Or override parameters via command line:
242
+
243
+ ```bash
244
+ hcp_run --cfg cfgs/workflow/text2img_cli.py \
245
+ pretrained_model=pretrained_model_path \
246
+ prompt='positive_prompt' \
247
+ negative_prompt='negative_prompt' \
248
+ seed=42
249
+ ```
250
+
251
+ ### Tutorials
252
+
253
+ 🚧 In Development
254
+
255
+ ---
256
+
257
+ ## Contributing
258
+
259
+ We welcome contributions to support more models and features.
260
+
261
+ ---
262
+
263
+ ## Team
264
+
265
+ Maintained by [HCP-Lab at Sun Yat-sen University](https://www.sysu-hcp.net/).
266
+
267
+ ---
268
+
269
+ ## Citation
270
+
271
+ ```bibtex
272
+ @article{DBLP:journals/corr/abs-2211-11337,
273
+ author = {Ziyi Dong and
274
+ Pengxu Wei and
275
+ Liang Lin},
276
+ title = {DreamArtist: Towards Controllable One-Shot Text-to-Image Generation
277
+ via Positive-Negative Prompt-Tuning},
278
+ journal = {CoRR},
279
+ volume = {abs/2211.11337},
280
+ year = {2022},
281
+ doi = {10.48550/arXiv.2211.11337},
282
+ eprinttype = {arXiv},
283
+ eprint = {2211.11337},
284
+ }
285
+ ```
hcpdiff-2.1/README.md ADDED
@@ -0,0 +1,248 @@
1
+ # HCP-Diffusion V2
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/hcpdiff)](https://pypi.org/project/hcpdiff/)
4
+ [![GitHub stars](https://img.shields.io/github/stars/7eu7d7/HCP-Diffusion)](https://github.com/7eu7d7/HCP-Diffusion/stargazers)
5
+ [![GitHub license](https://img.shields.io/github/license/7eu7d7/HCP-Diffusion)](https://github.com/7eu7d7/HCP-Diffusion/blob/master/LICENSE)
6
+ [![codecov](https://codecov.io/gh/7eu7d7/HCP-Diffusion/branch/main/graph/badge.svg)](https://codecov.io/gh/7eu7d7/HCP-Diffusion)
7
+ [![open issues](https://isitmaintained.com/badge/open/7eu7d7/HCP-Diffusion.svg)](https://github.com/7eu7d7/HCP-Diffusion/issues)
8
+
9
+ [📘中文说明](./README_cn.md)
10
+
11
+ [📘English document](https://hcpdiff.readthedocs.io/en/latest/)
12
+ [📘中文文档](https://hcpdiff.readthedocs.io/zh_CN/latest/)
13
+
14
+ Old HCP-Diffusion V1 at [main branch](https://github.com/IrisRainbowNeko/HCP-Diffusion/tree/main)
15
+
16
+ ## Introduction
17
+
18
+ **HCP-Diffusion** is a Diffusion model toolbox built on top of the [🐱 RainbowNeko Engine](https://github.com/IrisRainbowNeko/RainbowNekoEngine).
19
+ It features a clean code structure and a flexible **Python-based configuration file**, making it easier to conduct and manage complex experiments. It includes a wide variety of training components, and compared to existing frameworks, it's more extensible, flexible, and user-friendly.
20
+
21
+ HCP-Diffusion allows you to use a single `.py` config file to unify training workflows across popular methods and model architectures, including Prompt-tuning (Textual Inversion), DreamArtist, Fine-tuning, DreamBooth, LoRA, ControlNet, ....
22
+ Different techniques can also be freely combined.
23
+
24
+ This framework also implements **DreamArtist++**, an upgraded version of DreamArtist based on LoRA. It enables high generalization and controllability with just a single image for training.
25
+ Compared to the original DreamArtist, it offers better stability, image quality, controllability, and faster training.
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ Install via pip:
32
+
33
+ ```bash
34
+ pip install hcpdiff
35
+ # Initialize configuration
36
+ hcpinit
37
+ ```
38
+
39
+ Install from source:
40
+
41
+ ```bash
42
+ git clone https://github.com/7eu7d7/HCP-Diffusion.git
43
+ cd HCP-Diffusion
44
+ pip install -e .
45
+ # Initialize configuration
46
+ hcpinit
47
+ ```
48
+
49
+ Use xFormers to reduce memory usage and accelerate training:
50
+
51
+ ```bash
52
+ # Choose the appropriate xformers version for your PyTorch version
53
+ pip install xformers==?
54
+ ```
55
+
56
+ ## 🚀 Python Configuration Files
57
+ RainbowNeko Engine supports configuration files written in a Python-like syntax. This allows users to call functions and classes directly within the configuration file, with function parameters inheritable from parent configuration files. The framework automatically handles the formatting of these configuration files.
58
+
59
+ For example, consider the following configuration file:
60
+ ```python
61
+ dict(
62
+ layer=Linear(in_features=4, out_features=4)
63
+ )
64
+ ```
65
+ During parsing, this will be automatically compiled into:
66
+ ```python
67
+ dict(
68
+ layer=dict(_target_=Linear, in_features=4, out_features=4)
69
+ )
70
+ ```
71
+ After parsing, the framework will instantiate the components accordingly. This means users can write configuration files using familiar Python syntax.
72
+
73
+ ---
74
+
75
+ ## ✨ Features
76
+
77
+ <details>
78
+ <summary>Features</summary>
79
+
80
+ ### 📦 Model Support
81
+
82
+ | Model Name | Status |
83
+ |--------------------------|-------------|
84
+ | Stable Diffusion 1.5 | ✅ Supported |
85
+ | Stable Diffusion XL (SDXL)| ✅ Supported |
86
+ | PixArt | ✅ Supported |
87
+ | FLUX | 🚧 In Development |
88
+ | Stable Diffusion 3 (SD3) | 🚧 In Development |
89
+
90
+ ---
91
+
92
+ ### 🧠 Fine-Tuning Capabilities
93
+
94
+ | Feature | Description/Support |
95
+ |----------------------------------|---------------------|
96
+ | LoRA Layer-wise Configuration | ✅ Supported (including Conv2d) |
97
+ | Layer-wise Fine-Tuning | ✅ Supported |
98
+ | Multi-token Prompt-Tuning | ✅ Supported |
99
+ | Layer-wise Model Merging | ✅ Supported |
100
+ | Custom Optimizers | ✅ Supported (Lion, DAdaptation, pytorch-optimizer, etc.) |
101
+ | Custom LR Schedulers | ✅ Supported |
102
+
103
+ ---
104
+
105
+ ### 🧩 Extension Method Support
106
+
107
+ | Method | Status |
108
+ |--------------------------------|-------------|
109
+ | ControlNet (including training)| ✅ Supported |
110
+ | DreamArtist / DreamArtist++ | ✅ Supported |
111
+ | Token Attention Adjustment | ✅ Supported |
112
+ | Max Sentence Length Extension | ✅ Supported |
113
+ | Textual Inversion (Custom Tokens)| ✅ Supported |
114
+ | CLIP Skip | ✅ Supported |
115
+
116
+ ---
117
+
118
+ ### 🚀 Training Acceleration
119
+
120
+ | Tool/Library | Supported Modules |
121
+ |---------------------------------------------------|---------------------------|
122
+ | [🤗 Accelerate](https://github.com/huggingface/accelerate) | ✅ Supported |
123
+ | [Colossal-AI](https://github.com/hpcaitech/ColossalAI) | ✅ Supported |
124
+ | [xFormers](https://github.com/facebookresearch/xformers) | ✅ Supported (UNet and text encoder) |
125
+
126
+ ---
127
+
128
+ ### 🗂 Dataset Support
129
+
130
+ | Feature | Description |
131
+ |----------------------------------|-------------|
132
+ | Aspect Ratio Bucket (ARB) | ✅ Auto-clustering supported |
133
+ | Multi-source / Multi-dataset | ✅ Supported |
134
+ | LMDB | ✅ Supported |
135
+ | webdataset | 🚧 In Development |
136
+ | Local Attention Enhancement | ✅ Supported |
137
+ | Tag Shuffling & Dropout | ✅ Multiple tag editing strategies |
138
+
139
+ ---
140
+
141
+ ### 📉 Supported Loss Functions
142
+
143
+ | Loss Type | Description |
144
+ |------------|-------------|
145
+ | Min-SNR | ✅ Supported |
146
+ | SSIM | ✅ Supported |
147
+ | GWLoss | ✅ Supported |
148
+
149
+ ---
150
+
151
+ ### 🌫 Supported Diffusion Strategies
152
+
153
+ | Strategy Type | Status |
154
+ |------------------|--------------|
155
+ | DDPM | ✅ Supported |
156
+ | EDM | ✅ Supported |
157
+ | Flow Matching | ✅ Supported |
158
+
159
+ ---
160
+
161
+ ### 🧠 Automatic Evaluation (Step Selection Assistant)
162
+
163
+ | Feature | Description/Status |
164
+ |------------------|------------------------------------------|
165
+ | Image Preview | ✅ Supported (workflow preview) |
166
+ | FID | 🚧 In Development |
167
+ | CLIP Score | 🚧 In Development |
168
+ | CCIP Score | 🚧 In Development |
169
+ | Corrupt Score | 🚧 In Development |
170
+
171
+ </details>
172
+
173
+ ---
174
+
175
+ ## Getting Started
176
+
177
+ ### Training
178
+
179
+ HCP-Diffusion provides training scripts based on 🤗 Accelerate.
180
+
181
+ ```bash
182
+ # Multi-GPU training, configure GPUs in cfgs/launcher/multi.yaml
183
+ hcp_train --cfg cfgs/train/py/your_config.py
184
+
185
+ # Single-GPU training, configure GPU in cfgs/launcher/single.yaml
186
+ hcp_train_1gpu --cfg cfgs/train/py/your_config.py
187
+ ```
188
+
189
+ You can also override config items via command line:
190
+
191
+ ```bash
192
+ # Override base model path
193
+ hcp_train --cfg cfgs/train/py/your_config.py model.wrapper.models.ckpt_path=pretrained_model_path
194
+ ```
195
+
196
+ ### Image Generation
197
+
198
+ Use the workflow defined in the Python config to generate images:
199
+
200
+ ```bash
201
+ hcp_run --cfg cfgs/workflow/text2img.py
202
+ ```
203
+
204
+ Or override parameters via command line:
205
+
206
+ ```bash
207
+ hcp_run --cfg cfgs/workflow/text2img_cli.py \
208
+ pretrained_model=pretrained_model_path \
209
+ prompt='positive_prompt' \
210
+ negative_prompt='negative_prompt' \
211
+ seed=42
212
+ ```
213
+
214
+ ### Tutorials
215
+
216
+ 🚧 In Development
217
+
218
+ ---
219
+
220
+ ## Contributing
221
+
222
+ We welcome contributions to support more models and features.
223
+
224
+ ---
225
+
226
+ ## Team
227
+
228
+ Maintained by [HCP-Lab at Sun Yat-sen University](https://www.sysu-hcp.net/).
229
+
230
+ ---
231
+
232
+ ## Citation
233
+
234
+ ```bibtex
235
+ @article{DBLP:journals/corr/abs-2211-11337,
236
+ author = {Ziyi Dong and
237
+ Pengxu Wei and
238
+ Liang Lin},
239
+ title = {DreamArtist: Towards Controllable One-Shot Text-to-Image Generation
240
+ via Positive-Negative Prompt-Tuning},
241
+ journal = {CoRR},
242
+ volume = {abs/2211.11337},
243
+ year = {2022},
244
+ doi = {10.48550/arXiv.2211.11337},
245
+ eprinttype = {arXiv},
246
+ eprint = {2211.11337},
247
+ }
248
+ ```
@@ -0,0 +1,4 @@
1
+ #from .train_ac_old import Trainer
2
+ #from .train_ac_single import TrainerSingleCard
3
+ # from .visualizer import Visualizer
4
+ # from .visualizer_reloadable import VisualizerReloadable
@@ -0,0 +1,4 @@
1
+ from .format import EmbFormat, DiffusersSD15Format, DiffusersModelFormat, DiffusersSDXLFormat, DiffusersPixArtFormat, OfficialSDXLFormat, \
2
+ OfficialSD15Format
3
+ from .ckpt import EmbSaver, easy_emb_saver
4
+ from .loader import HCPLoraLoader
@@ -0,0 +1,24 @@
1
+ from rainbowneko.ckpt_manager import NekoSaver, CkptFormat, LocalCkptSource, PKLFormat
2
+ from torch import nn
3
+ from typing import Dict, Any
4
+
5
+ class EmbSaver(NekoSaver):
6
+ def __init__(self, format: CkptFormat, source: LocalCkptSource, target_key='embs', prefix=None):
7
+ super().__init__(format, source)
8
+ self.target_key = target_key
9
+ self.prefix = prefix
10
+
11
+ def save_to(self, name, model: nn.Module, plugin_groups: Dict[str, Any], model_ema=None, exclude_key=None,
12
+ name_template=None):
13
+ train_pts = plugin_groups[self.target_key]
14
+ for pt_name, pt in train_pts.items():
15
+ self.save(pt_name, (pt_name, pt), prefix=self.prefix)
16
+ if name_template is not None:
17
+ pt_name = name_template.format(pt_name)
18
+ self.save(pt_name, (pt_name, pt), prefix=self.prefix)
19
+
20
+ def easy_emb_saver():
21
+ return EmbSaver(
22
+ format=PKLFormat(),
23
+ source=LocalCkptSource(),
24
+ )
@@ -0,0 +1,4 @@
1
+ from .emb import EmbFormat
2
+ from .diffusers import DiffusersSD15Format, DiffusersModelFormat, DiffusersSDXLFormat, DiffusersPixArtFormat
3
+ from .sd_single import OfficialSD15Format, OfficialSDXLFormat
4
+ from .lora_webui import LoraWebuiFormat
@@ -0,0 +1,59 @@
1
+ import torch
2
+ from diffusers import ModelMixin, AutoencoderKL, UNet2DConditionModel, PixArtTransformer2DModel
3
+ from rainbowneko.ckpt_manager.format import CkptFormat
4
+ from transformers import CLIPTextModel, AutoTokenizer, T5EncoderModel
5
+
6
+ from hcpdiff.diffusion.sampler import DDPMSampler, DDPMDiscreteSigmaScheduler
7
+ from hcpdiff.models.compose import SDXLTokenizer, SDXLTextEncoder
8
+
9
+ class DiffusersModelFormat(CkptFormat):
10
+ def __init__(self, builder: ModelMixin):
11
+ self.builder = builder
12
+
13
+ def save_ckpt(self, sd_model: ModelMixin, save_f: str, **kwargs):
14
+ sd_model.save_pretrained(save_f)
15
+
16
+ def load_ckpt(self, ckpt_f: str, map_location="cpu", **kwargs):
17
+ self.builder.from_pretrained(ckpt_f, **kwargs)
18
+
19
+ class DiffusersSD15Format(CkptFormat):
20
+ def load_ckpt(self, pretrained_model: str, map_location="cpu", denoiser=None, TE=None, vae: AutoencoderKL = None, noise_sampler=None,
21
+ tokenizer=None, revision=None, dtype=torch.float32, **kwargs):
22
+ denoiser = denoiser or UNet2DConditionModel.from_pretrained(
23
+ pretrained_model, subfolder="unet", revision=revision, torch_dtype=dtype
24
+ )
25
+ vae = vae or AutoencoderKL.from_pretrained(pretrained_model, subfolder="vae", revision=revision, torch_dtype=dtype)
26
+ noise_sampler = noise_sampler or DDPMSampler(DDPMDiscreteSigmaScheduler())
27
+
28
+ TE = TE or CLIPTextModel.from_pretrained(pretrained_model, subfolder="text_encoder", revision=revision, torch_dtype=dtype)
29
+ tokenizer = tokenizer or AutoTokenizer.from_pretrained(pretrained_model, subfolder="tokenizer", revision=revision, use_fast=False)
30
+
31
+ return dict(denoiser=denoiser, TE=TE, vae=vae, noise_sampler=noise_sampler, tokenizer=tokenizer)
32
+
33
+ class DiffusersSDXLFormat(CkptFormat):
34
+ def load_ckpt(self, pretrained_model: str, map_location="cpu", denoiser=None, TE=None, vae: AutoencoderKL = None, noise_sampler=None,
35
+ tokenizer=None, revision=None, dtype=torch.float32, **kwargs):
36
+ denoiser = denoiser or UNet2DConditionModel.from_pretrained(
37
+ pretrained_model, subfolder="unet", revision=revision, torch_dtype=dtype
38
+ )
39
+ vae = vae or AutoencoderKL.from_pretrained(pretrained_model, subfolder="vae", revision=revision, torch_dtype=dtype)
40
+ noise_sampler = noise_sampler or DDPMSampler(DDPMDiscreteSigmaScheduler())
41
+
42
+ TE = TE or SDXLTextEncoder.from_pretrained(pretrained_model, subfolder="text_encoder", revision=revision, torch_dtype=dtype)
43
+ tokenizer = tokenizer or SDXLTokenizer.from_pretrained(pretrained_model, subfolder="tokenizer", revision=revision, use_fast=False)
44
+
45
+ return dict(denoiser=denoiser, TE=TE, vae=vae, noise_sampler=noise_sampler, tokenizer=tokenizer)
46
+
47
+ class DiffusersPixArtFormat(CkptFormat):
48
+ def load_ckpt(self, pretrained_model: str, map_location="cpu", denoiser=None, TE=None, vae: AutoencoderKL = None, noise_sampler=None,
49
+ tokenizer=None, revision=None, dtype=torch.float32, **kwargs):
50
+ denoiser = denoiser or PixArtTransformer2DModel.from_pretrained(
51
+ pretrained_model, subfolder="transformer", revision=revision, torch_dtype=dtype
52
+ )
53
+ vae = vae or AutoencoderKL.from_pretrained(pretrained_model, subfolder="vae", revision=revision, torch_dtype=dtype)
54
+ noise_sampler = noise_sampler or DDPMSampler(DDPMDiscreteSigmaScheduler())
55
+
56
+ TE = TE or T5EncoderModel.from_pretrained(pretrained_model, subfolder="text_encoder", revision=revision, torch_dtype=dtype)
57
+ tokenizer = tokenizer or AutoTokenizer.from_pretrained(pretrained_model, subfolder="tokenizer", revision=revision, use_fast=False)
58
+
59
+ return dict(denoiser=denoiser, TE=TE, vae=vae, noise_sampler=noise_sampler, tokenizer=tokenizer)
@@ -0,0 +1,21 @@
1
+ from typing import Tuple
2
+
3
+ import torch
4
+ from rainbowneko.ckpt_manager.format import CkptFormat
5
+ from torch.serialization import FILE_LIKE
6
+
7
+ class EmbFormat(CkptFormat):
8
+ EXT = 'pt'
9
+
10
+ def save_ckpt(self, sd_model: Tuple[str, torch.Tensor], save_f: FILE_LIKE):
11
+ name, emb = sd_model
12
+ torch.save({'string_to_param':{'*':emb}, 'name':name}, save_f)
13
+
14
+ def load_ckpt(self, ckpt_f: FILE_LIKE, map_location="cpu"):
15
+ state = torch.load(ckpt_f, map_location=map_location)
16
+ if 'string_to_param' in state:
17
+ emb = state['string_to_param']['*']
18
+ else:
19
+ emb = state['emb_params']
20
+ emb.requires_grad_(False)
21
+ return emb