style: rename

This commit is contained in:
Limitex
2025-10-31 20:53:33 +09:00
parent d0c07557d8
commit fc0d53e167
7 changed files with 18 additions and 16 deletions
+5 -5
View File
@@ -7,16 +7,16 @@ from ..ui.pipeline_handler import PipelineHandler
class Container(containers.DeclarativeContainer):
# 1. Repositories
pipeline_repository_provider = providers.Factory(DiffusersPipelineRepository)
pipeline_repository = providers.Factory(DiffusersPipelineRepository)
# 2. Services
create_pipeline_service_provider = providers.Factory(
create_pipeline_service = providers.Factory(
CreatePipelineService,
pipeline_repo=pipeline_repository_provider,
pipeline_repo=pipeline_repository,
)
# 3. Handler
pipeline_handler_provider = providers.Factory(
pipeline_handler = providers.Factory(
PipelineHandler,
create_pipeline_service=create_pipeline_service_provider,
create_pipeline_service=create_pipeline_service,
)
@@ -6,7 +6,7 @@ from diffusers import StableDiffusionPipeline
class IPipelineRepository(ABC):
@abstractmethod
def convert_from_single_file(self, checkpoint_path: str, dtype: torch.dtype) -> str:
def convert_and_save_from_single_file(self, checkpoint_path: str, dtype: torch.dtype) -> str:
pass
@abstractmethod
+5 -5
View File
@@ -9,16 +9,16 @@ from ...domain.repositories import IPipelineRepository
class DiffusersPipelineRepository(IPipelineRepository):
def __init__(self) -> None:
self.tmp_dir = folder_paths.get_temp_directory()
self.cache_dir = folder_paths.get_temp_directory()
def convert_from_single_file(self, checkpoint_path: str, dtype: torch.dtype) -> str:
def convert_and_save_from_single_file(self, checkpoint_path: str, dtype: torch.dtype) -> str:
checkpoint_name = os.path.basename(checkpoint_path)
ckpt_cache_path = os.path.join(self.tmp_dir, checkpoint_name)
ckpt_cache_path = os.path.join(self.cache_dir, checkpoint_name)
StableDiffusionPipeline.from_single_file(
pretrained_model_link_or_path=checkpoint_path,
torch_dtype=dtype,
cache_dir=self.tmp_dir,
cache_dir=self.cache_dir,
).save_pretrained(ckpt_cache_path, safe_serialization=True)
return ckpt_cache_path
@@ -28,6 +28,6 @@ class DiffusersPipelineRepository(IPipelineRepository):
pipe: StableDiffusionPipeline = StableDiffusionPipeline.from_pretrained( # type: ignore[no-untyped-call]
pretrained_model_name_or_path=model_path,
torch_dtype=dtype,
cache_dir=self.tmp_dir,
cache_dir=self.cache_dir,
)
return pipe
+1 -1
View File
@@ -26,7 +26,7 @@ class DiffusersPipelineLoader:
def execute(
self,
checkpoint_name: str,
handler: PipelineHandler = Provide[Container.pipeline_handler_provider],
handler: PipelineHandler = Provide[Container.pipeline_handler],
) -> tuple[ComfyUIPipelineDTO]:
pipeline_model = handler.create(checkpoint_name)
pipeline_dto = ComfyUIPipelineDTO.from_domain(pipeline_model)
+1 -1
View File
@@ -39,7 +39,7 @@ class ComfyUIPipelineDTO:
"""
# ClassVar to avoid being treated as a dataclass field
COMFY_TYPE: ClassVar[str] = "PIPELINE"
COMFY_TYPE: ClassVar[str] = "DIFFUSERS_PIPELINE"
pipeline: StableDiffusionPipeline
path: str
+4 -2
View File
@@ -11,8 +11,10 @@ class CreatePipelineService:
self.pipeline_repo = pipeline_repo
self.dtype = torch.float32
def execute(self, checkpoint_full_path: str) -> PipelineModel:
path = self.pipeline_repo.convert_from_single_file(checkpoint_full_path, self.dtype)
def create_from_checkpoint(self, checkpoint_full_path: str) -> PipelineModel:
path = self.pipeline_repo.convert_and_save_from_single_file(
checkpoint_full_path, self.dtype
)
if not os.path.exists(path):
raise RuntimeError(f"Failed to convert pipeline checkpoint: {checkpoint_full_path}")
+1 -1
View File
@@ -14,4 +14,4 @@ class PipelineHandler:
checkpoint_path = folder_paths.get_full_path("checkpoints", checkpoint_name)
if not os.path.exists(checkpoint_path):
raise FileNotFoundError(f"Checkpoint file not found: {checkpoint_name}")
return self.create_pipeline_service.execute(checkpoint_path)
return self.create_pipeline_service.create_from_checkpoint(checkpoint_path)