xfuser 0.1__py3-none-any.whl

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 (113) hide show
  1. pipefuser/__init__.py +0 -0
  2. pipefuser/__version__.py +1 -0
  3. pipefuser/logger.py +99 -0
  4. pipefuser/models/__init__.py +13 -0
  5. pipefuser/models/base_model.py +52 -0
  6. pipefuser/models/diffusers/__init__.py +10 -0
  7. pipefuser/models/diffusers/attention.py +728 -0
  8. pipefuser/models/diffusers/attention_processor.py +2900 -0
  9. pipefuser/models/diffusers/transformers_2d.py +546 -0
  10. pipefuser/models/distri_dit_hunyuan_pipefusion.py +102 -0
  11. pipefuser/models/distri_dit_pipefusion.py +104 -0
  12. pipefuser/models/distri_dit_pp.py +178 -0
  13. pipefuser/models/distri_dit_sd3_pipefusion.py +96 -0
  14. pipefuser/models/distri_dit_tp.py +183 -0
  15. pipefuser/models/distri_sdxl_unet_pp.py +262 -0
  16. pipefuser/models/distri_sdxl_unet_tp.py +231 -0
  17. pipefuser/models/distri_unet_pp.py +262 -0
  18. pipefuser/models/distri_unet_tp.py +231 -0
  19. pipefuser/models/naive_patch_dit.py +125 -0
  20. pipefuser/models/naive_patch_sdxl.py +260 -0
  21. pipefuser/models/naive_patch_unet.py +260 -0
  22. pipefuser/modules/__init__.py +0 -0
  23. pipefuser/modules/base_module.py +29 -0
  24. pipefuser/modules/conv/__init__.py +0 -0
  25. pipefuser/modules/conv/conv_chunk/__init__.py +0 -0
  26. pipefuser/modules/conv/conv_chunk/chunk_conv2d.py +181 -0
  27. pipefuser/modules/conv/conv_parallel/__init__.py +0 -0
  28. pipefuser/modules/conv/conv_parallel/parallel_state.py +83 -0
  29. pipefuser/modules/conv/conv_parallel/patch_parallel_conv2d.py +399 -0
  30. pipefuser/modules/conv/conv_parallel/patch_util.py +97 -0
  31. pipefuser/modules/dit/__init__.py +0 -0
  32. pipefuser/modules/dit/patch_parallel/__init__.py +5 -0
  33. pipefuser/modules/dit/patch_parallel/attn.py +312 -0
  34. pipefuser/modules/dit/patch_parallel/conv2d.py +162 -0
  35. pipefuser/modules/dit/patch_parallel/groupnorm.py +122 -0
  36. pipefuser/modules/dit/patch_parallel/patchembed.py +50 -0
  37. pipefuser/modules/dit/patch_parallel/transformer2d.py +208 -0
  38. pipefuser/modules/dit/patch_parallel/transformer_2d.py +213 -0
  39. pipefuser/modules/dit/pipefusion/__init__.py +14 -0
  40. pipefuser/modules/dit/pipefusion/attn.py +495 -0
  41. pipefuser/modules/dit/pipefusion/conv2d.py +153 -0
  42. pipefuser/modules/dit/pipefusion/patchembed.py +94 -0
  43. pipefuser/modules/dit/pipefusion/transformer2d.py +269 -0
  44. pipefuser/modules/dit/pipefusion/transformer_2d.py +274 -0
  45. pipefuser/modules/dit/pipefusion/transformer_hunyuan.py +201 -0
  46. pipefuser/modules/dit/pipefusion/transformer_sd3.py +189 -0
  47. pipefuser/modules/dit/tensor_parallel/__init__.py +3 -0
  48. pipefuser/modules/dit/tensor_parallel/attention.py +211 -0
  49. pipefuser/modules/dit/tensor_parallel/conv2d.py +70 -0
  50. pipefuser/modules/dit/tensor_parallel/feed_forward.py +178 -0
  51. pipefuser/modules/dit/tensor_parallel/resnet.py +224 -0
  52. pipefuser/pipelines/__init__.py +10 -0
  53. pipefuser/pipelines/dit.py +180 -0
  54. pipefuser/pipelines/hunyuandit.py +357 -0
  55. pipefuser/pipelines/pip/__init__.py +0 -0
  56. pipefuser/pipelines/pip/distri_hunyuandit.py +567 -0
  57. pipefuser/pipelines/pip/distri_pixartalpha.py +504 -0
  58. pipefuser/pipelines/pip/distri_sd3.py +431 -0
  59. pipefuser/pipelines/pixartalpha.py +338 -0
  60. pipefuser/pipelines/sd3.py +287 -0
  61. pipefuser/pipelines/sdxl.py +180 -0
  62. pipefuser/schedulers/__init__.py +0 -0
  63. pipefuser/schedulers/pip/__init__.py +9 -0
  64. pipefuser/schedulers/pip/ddim.py +21 -0
  65. pipefuser/schedulers/pip/ddpm.py +24 -0
  66. pipefuser/schedulers/pip/dpmsolver_multistep.py +131 -0
  67. pipefuser/schedulers/pip/flow_match_euler_discrete.py +30 -0
  68. pipefuser/utils.py +580 -0
  69. xfuser/__init__.py +16 -0
  70. xfuser/__version__.py +1 -0
  71. xfuser/config/__init__.py +26 -0
  72. xfuser/config/args.py +198 -0
  73. xfuser/config/config.py +222 -0
  74. xfuser/distributed/__init__.py +52 -0
  75. xfuser/distributed/group_coordinator.py +817 -0
  76. xfuser/distributed/parallel_state.py +503 -0
  77. xfuser/distributed/runtime_state.py +328 -0
  78. xfuser/envs.py +134 -0
  79. xfuser/logger.py +99 -0
  80. xfuser/model_executor/__init__.py +0 -0
  81. xfuser/model_executor/base_wrapper.py +40 -0
  82. xfuser/model_executor/layers/__init__.py +13 -0
  83. xfuser/model_executor/layers/attention_processor.py +748 -0
  84. xfuser/model_executor/layers/base_layer.py +40 -0
  85. xfuser/model_executor/layers/conv.py +159 -0
  86. xfuser/model_executor/layers/embeddings.py +98 -0
  87. xfuser/model_executor/layers/register.py +52 -0
  88. xfuser/model_executor/models/__init__.py +5 -0
  89. xfuser/model_executor/models/base_model.py +111 -0
  90. xfuser/model_executor/models/transformers/__init__.py +13 -0
  91. xfuser/model_executor/models/transformers/base_transformer.py +123 -0
  92. xfuser/model_executor/models/transformers/pixart_transformer_2d.py +202 -0
  93. xfuser/model_executor/models/transformers/register.py +58 -0
  94. xfuser/model_executor/models/transformers/transformer_flux.py +180 -0
  95. xfuser/model_executor/models/transformers/transformer_sd3.py +167 -0
  96. xfuser/model_executor/pipelines/__init__.py +13 -0
  97. xfuser/model_executor/pipelines/base_pipeline.py +289 -0
  98. xfuser/model_executor/pipelines/pipeline_flux.py +501 -0
  99. xfuser/model_executor/pipelines/pipeline_pixart_alpha.py +649 -0
  100. xfuser/model_executor/pipelines/pipeline_pixart_sigma.py +610 -0
  101. xfuser/model_executor/pipelines/pipeline_stable_diffusion_3.py +736 -0
  102. xfuser/model_executor/pipelines/register.py +63 -0
  103. xfuser/model_executor/schedulers/__init__.py +15 -0
  104. xfuser/model_executor/schedulers/base_scheduler.py +43 -0
  105. xfuser/model_executor/schedulers/register.py +50 -0
  106. xfuser/model_executor/schedulers/scheduling_dpmsolver_multistep.py +169 -0
  107. xfuser/model_executor/schedulers/scheduling_flow_match_euler_discrete.py +121 -0
  108. xfuser/parallel.py +52 -0
  109. xfuser-0.1.dist-info/LICENSE.txt +202 -0
  110. xfuser-0.1.dist-info/METADATA +322 -0
  111. xfuser-0.1.dist-info/RECORD +113 -0
  112. xfuser-0.1.dist-info/WHEEL +5 -0
  113. xfuser-0.1.dist-info/top_level.txt +1 -0
pipefuser/__init__.py ADDED
File without changes
@@ -0,0 +1 @@
1
+ __version__ = "0.1"
pipefuser/logger.py ADDED
@@ -0,0 +1,99 @@
1
+ # Adapted from
2
+ # https://github.com/skypilot-org/skypilot/blob/86dc0f6283a335e4aa37b3c10716f90999f48ab6/sky/sky_logging.py
3
+ """Logging configuration."""
4
+ import logging
5
+ import sys
6
+ import os
7
+ from typing import Optional
8
+
9
+ _FORMAT = "%(levelname)s %(asctime)s [%(filename)s:%(lineno)d] %(message)s"
10
+ _DATE_FORMAT = "%m-%d %H:%M:%S"
11
+
12
+ _LOG_LEVEL = os.environ.get("LOG_LEVEL", "debug")
13
+ _LOG_LEVEL = getattr(logging, _LOG_LEVEL.upper(), 0)
14
+ _LOG_DIR = os.environ.get("LOG_DIR", None)
15
+
16
+
17
+ class NewLineFormatter(logging.Formatter):
18
+ """Adds logging prefix to newlines to align multi-line messages."""
19
+
20
+ def __init__(self, fmt, datefmt=None):
21
+ logging.Formatter.__init__(self, fmt, datefmt)
22
+
23
+ def format(self, record):
24
+ msg = logging.Formatter.format(self, record)
25
+ if record.message != "":
26
+ parts = msg.split(record.message)
27
+ msg = msg.replace("\n", "\r\n" + parts[0])
28
+ return msg
29
+
30
+
31
+ _root_logger = logging.getLogger("pipefuser")
32
+ _default_handler = None
33
+ _default_file_handler = None
34
+ _inference_log_file_handler = {}
35
+
36
+
37
+ def _setup_logger():
38
+ _root_logger.setLevel(_LOG_LEVEL)
39
+ global _default_handler
40
+ global _default_file_handler
41
+ fmt = NewLineFormatter(_FORMAT, datefmt=_DATE_FORMAT)
42
+
43
+ if _default_handler is None:
44
+ _default_handler = logging.StreamHandler(sys.stdout)
45
+ _default_handler.flush = sys.stdout.flush # type: ignore
46
+ _default_handler.setLevel(_LOG_LEVEL)
47
+ _root_logger.addHandler(_default_handler)
48
+
49
+ if _default_file_handler is None and _LOG_DIR is not None:
50
+ if not os.path.exists(_LOG_DIR):
51
+ try:
52
+ os.makedirs(_LOG_DIR)
53
+ except OSError as e:
54
+ _root_logger.warn(f"Error creating directory {_LOG_DIR} : {e}")
55
+ _default_file_handler = logging.FileHandler(_LOG_DIR + "/default.log")
56
+ _default_file_handler.setLevel(_LOG_LEVEL)
57
+ _default_file_handler.setFormatter(fmt)
58
+ _root_logger.addHandler(_default_file_handler)
59
+
60
+ _default_handler.setFormatter(fmt)
61
+ # Setting this will avoid the message
62
+ # being propagated to the parent logger.
63
+ _root_logger.propagate = False
64
+
65
+
66
+ # The logger is initialized when the module is imported.
67
+ # This is thread-safe as the module is only imported once,
68
+ # guaranteed by the Python GIL.
69
+ _setup_logger()
70
+
71
+
72
+ def init_logger(name: str):
73
+ pid = os.getpid()
74
+ # Use the same settings as above for root logger
75
+ logger = logging.getLogger(name)
76
+ logger.setLevel(_LOG_LEVEL)
77
+ logger.addHandler(_default_handler)
78
+ if _LOG_DIR is not None and pid is None:
79
+ logger.addHandler(_default_file_handler)
80
+ elif _LOG_DIR is not None:
81
+ if _inference_log_file_handler.get(pid, None) is not None:
82
+ logger.addHandler(_inference_log_file_handler[pid])
83
+ else:
84
+ if not os.path.exists(_LOG_DIR):
85
+ try:
86
+ os.makedirs(_LOG_DIR)
87
+ except OSError as e:
88
+ _root_logger.warn(f"Error creating directory {_LOG_DIR} : {e}")
89
+ _inference_log_file_handler[pid] = logging.FileHandler(
90
+ _LOG_DIR + f"/process.{pid}.log"
91
+ )
92
+ _inference_log_file_handler[pid].setLevel(_LOG_LEVEL)
93
+ _inference_log_file_handler[pid].setFormatter(
94
+ NewLineFormatter(_FORMAT, datefmt=_DATE_FORMAT)
95
+ )
96
+ _root_logger.addHandler(_inference_log_file_handler[pid])
97
+ logger.addHandler(_inference_log_file_handler[pid])
98
+ logger.propagate = False
99
+ return logger
@@ -0,0 +1,13 @@
1
+ from packaging.version import Version
2
+ import diffusers
3
+
4
+ if Version('0.29.0') <= Version(diffusers.__version__):
5
+ from .distri_dit_sd3_pipefusion import DistriDiTSD3PipeFusion
6
+
7
+ from .naive_patch_dit import NaivePatchDiT
8
+ from .distri_dit_pp import DistriDiTPP
9
+ from .distri_dit_tp import DistriDiTTP
10
+ from .distri_dit_pipefusion import DistriDiTPipeFusion
11
+ from .distri_dit_hunyuan_pipefusion import DistriDiTHunyuanPipeFusion
12
+
13
+
@@ -0,0 +1,52 @@
1
+ from diffusers import ConfigMixin, ModelMixin
2
+ from torch import nn
3
+
4
+ from pipefuser.modules.base_module import BaseModule
5
+ from ..utils import PatchParallelismCommManager, DistriConfig
6
+
7
+
8
+ class BaseModel(ModelMixin, ConfigMixin):
9
+ def __init__(self, model: nn.Module, distri_config: DistriConfig):
10
+ super(BaseModel, self).__init__()
11
+ self.model = model
12
+ self.distri_config = distri_config
13
+ self.comm_manager = None
14
+
15
+ self.buffer_list = None
16
+ self.output_buffer = None
17
+ self.counter = 0
18
+
19
+ # for cuda graph
20
+ self.static_inputs = None
21
+ self.static_outputs = None
22
+ self.cuda_graphs = None
23
+
24
+ def forward(self, *args, **kwargs):
25
+ raise NotImplementedError
26
+
27
+ def set_counter(self, counter: int = 0):
28
+ self.counter = counter
29
+ for module in self.model.modules():
30
+ if isinstance(module, BaseModule):
31
+ module.set_counter(counter)
32
+
33
+ def set_comm_manager(self, comm_manager: PatchParallelismCommManager):
34
+ self.comm_manager = comm_manager
35
+ for module in self.model.modules():
36
+ if isinstance(module, BaseModule):
37
+ module.set_comm_manager(comm_manager)
38
+
39
+ def setup_cuda_graph(self, static_outputs, cuda_graphs):
40
+ self.static_outputs = static_outputs
41
+ self.cuda_graphs = cuda_graphs
42
+
43
+ @property
44
+ def config(self):
45
+ return self.model.config
46
+
47
+ def synchronize(self):
48
+ if self.comm_manager is not None and self.comm_manager.handles is not None:
49
+ for i in range(len(self.comm_manager.handles)):
50
+ if self.comm_manager.handles[i] is not None:
51
+ self.comm_manager.handles[i].wait()
52
+ self.comm_manager.handles[i] = None
@@ -0,0 +1,10 @@
1
+ USE_CUSTOMIZED_IMPL = False
2
+
3
+ if USE_CUSTOMIZED_IMPL:
4
+ from .attention import Attention
5
+ from .transformers_2d import Transformer2DModel
6
+ else:
7
+ from diffusers.models.attention import Attention
8
+ from diffusers.models.transformers.transformer_2d import Transformer2DModel
9
+
10
+ __all__ = ["Attention", "Transformer2DModel"]