forked from xdit-project/xDiT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] data parallel bugs (xdit-project#249)
- Loading branch information
1 parent
56b1975
commit 346b381
Showing
5 changed files
with
60 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
import os | ||
from typing import Any, Type, Union | ||
from diffusers.pipelines.pipeline_utils import DiffusionPipeline | ||
|
||
from xfuser.config.config import InputConfig | ||
from xfuser.core.distributed import ( | ||
init_distributed_environment, | ||
initialize_model_parallel, | ||
) | ||
from xfuser.config import EngineConfig | ||
from xfuser.core.distributed.parallel_state import ( | ||
get_data_parallel_rank, | ||
get_data_parallel_world_size, | ||
is_dp_last_group, | ||
) | ||
from xfuser.logger import init_logger | ||
from xfuser.model_executor.pipelines.base_pipeline import xFuserPipelineBaseWrapper | ||
from xfuser.model_executor.pipelines.register import xFuserPipelineWrapperRegister | ||
|
||
logger = init_logger(__name__) | ||
|
||
|
||
def xdit_parallel(pipe, engine_config: EngineConfig): | ||
if isinstance(pipe, type): | ||
xfuser_pipe_class = xFuserPipelineWrapperRegister.get_class(pipe) | ||
return xfuser_pipe_class | ||
else: | ||
class xDiTParallel: | ||
def __init__(self, pipe, engine_config: EngineConfig, input_config: InputConfig): | ||
xfuser_pipe_wrapper = xFuserPipelineWrapperRegister.get_class(pipe) | ||
return xfuser_pipe_wrapper(pipeline=pipe, engine_config=engine_config) | ||
self.pipe = xfuser_pipe_wrapper(pipeline=pipe, engine_config=engine_config) | ||
self.config = engine_config | ||
self.pipe.prepare_run(input_config) | ||
|
||
def __call__( | ||
self, | ||
*args, | ||
**kwargs, | ||
): | ||
self.result = self.pipe(*args, **kwargs) | ||
return self.result | ||
|
||
def save(self, directory: str, prefix: str): | ||
dp_rank = get_data_parallel_rank() | ||
parallel_info = ( | ||
f"dp{self.config.parallel_config.dp_degree}_cfg{self.config.parallel_config.cfg_degree}_" | ||
f"ulysses{self.config.parallel_config.ulysses_degree}_ring{self.config.parallel_config.ring_degree}_" | ||
f"pp{self.config.parallel_config.pp_degree}_patch{self.config.parallel_config.pp_config.num_pipeline_patch}" | ||
) | ||
prefix = f"{directory}/{prefix}_result_{parallel_info}_dprank{dp_rank}" | ||
if is_dp_last_group(): | ||
if not os.path.exists("results"): | ||
os.mkdir("results") | ||
for i, image in enumerate(self.result.images): | ||
image.save(f"{prefix}_image{i}.png") | ||
print(f"{prefix}_image{i}.png") |