Update some dependencies. Repair some codes.
This commit is contained in:
		
							parent
							
								
									4fe518038d
								
							
						
					
					
						commit
						e1639039d7
					
				@ -5,7 +5,7 @@ RUN apt-get update \
 | 
				
			|||||||
    && apt-get autoremove -y \
 | 
					    && apt-get autoremove -y \
 | 
				
			||||||
    && apt-get clean -y \
 | 
					    && apt-get clean -y \
 | 
				
			||||||
    && rm -rf /var/lib/apt/lists/* \
 | 
					    && rm -rf /var/lib/apt/lists/* \
 | 
				
			||||||
    && pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu117 --no-cache-dir \
 | 
					    && pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu121 --no-cache-dir \
 | 
				
			||||||
    && mkdir -p /vol/cache/esrgan \
 | 
					    && mkdir -p /vol/cache/esrgan \
 | 
				
			||||||
    && wget --progress=dot:giga https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P /vol/cache/esrgan \
 | 
					    && wget --progress=dot:giga https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P /vol/cache/esrgan \
 | 
				
			||||||
    && wget --progress=dot:giga https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth -P /vol/cache/esrgan \
 | 
					    && wget --progress=dot:giga https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth -P /vol/cache/esrgan \
 | 
				
			||||||
 | 
				
			|||||||
@ -2,10 +2,10 @@ from __future__ import annotations
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import stable_diffusion_1_5
 | 
					import stable_diffusion_1_5
 | 
				
			||||||
import stable_diffusion_xl
 | 
					import stable_diffusion_xl
 | 
				
			||||||
from setup import stub
 | 
					from setup import app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@stub.function(gpu="A10G")
 | 
					@app.function(gpu="A10G")
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    stable_diffusion_1_5.SD15
 | 
					    stable_diffusion_1_5.SD15
 | 
				
			||||||
    stable_diffusion_xl.SDXLTxt2Img
 | 
					    stable_diffusion_xl.SDXLTxt2Img
 | 
				
			||||||
 | 
				
			|||||||
@ -1,21 +1,21 @@
 | 
				
			|||||||
invisible_watermark
 | 
					invisible_watermark
 | 
				
			||||||
accelerate
 | 
					accelerate
 | 
				
			||||||
diffusers[torch]==0.24.0
 | 
					diffusers[torch]==0.27.2
 | 
				
			||||||
onnxruntime==1.16.3
 | 
					onnxruntime==1.17.3
 | 
				
			||||||
safetensors==0.4.1
 | 
					safetensors==0.4.3
 | 
				
			||||||
torch==2.1.0
 | 
					torch==2.2.2
 | 
				
			||||||
transformers==4.39.1
 | 
					transformers==4.39.3
 | 
				
			||||||
xformers==0.0.22.post7
 | 
					xformers==0.0.25.post1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
realesrgan==0.3.0
 | 
					realesrgan==0.3.0
 | 
				
			||||||
basicsr>=1.4.2
 | 
					basicsr>=1.4.2
 | 
				
			||||||
facexlib>=0.3.0
 | 
					facexlib>=0.3.0
 | 
				
			||||||
gfpgan>=1.3.8
 | 
					gfpgan>=1.3.8
 | 
				
			||||||
scipy==1.12.0
 | 
					scipy==1.13.0
 | 
				
			||||||
opencv-python
 | 
					opencv-python
 | 
				
			||||||
Pillow
 | 
					Pillow
 | 
				
			||||||
pillow-avif-plugin
 | 
					pillow-avif-plugin
 | 
				
			||||||
torchvision
 | 
					torchvision==0.17.2
 | 
				
			||||||
tqdm
 | 
					tqdm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
controlnet_aux
 | 
					controlnet_aux
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@ from __future__ import annotations
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import diffusers
 | 
					import diffusers
 | 
				
			||||||
from modal import Image, Mount, Secret, Stub
 | 
					from modal import App, Image, Mount, Secret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BASE_CACHE_PATH = "/vol/cache"
 | 
					BASE_CACHE_PATH = "/vol/cache"
 | 
				
			||||||
BASE_CACHE_PATH_LORA = "/vol/cache/lora"
 | 
					BASE_CACHE_PATH_LORA = "/vol/cache/lora"
 | 
				
			||||||
@ -58,7 +58,7 @@ def download_model(name: str, model_url: str, token: str):
 | 
				
			|||||||
    cache_path = os.path.join(BASE_CACHE_PATH, name)
 | 
					    cache_path = os.path.join(BASE_CACHE_PATH, name)
 | 
				
			||||||
    pipe = diffusers.StableDiffusionPipeline.from_single_file(
 | 
					    pipe = diffusers.StableDiffusionPipeline.from_single_file(
 | 
				
			||||||
        pretrained_model_link_or_path=model_url,
 | 
					        pretrained_model_link_or_path=model_url,
 | 
				
			||||||
        use_auth_token=token,
 | 
					        token=token,
 | 
				
			||||||
        cache_dir=cache_path,
 | 
					        cache_dir=cache_path,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    pipe.save_pretrained(cache_path, safe_serialization=True)
 | 
					    pipe.save_pretrained(cache_path, safe_serialization=True)
 | 
				
			||||||
@ -131,12 +131,12 @@ def build_image():
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stub = Stub("stable-diffusion-cli")
 | 
					app = App("stable-diffusion-cli")
 | 
				
			||||||
base_stub = Image.from_dockerfile(
 | 
					base_stub = Image.from_dockerfile(
 | 
				
			||||||
    path="Dockerfile",
 | 
					    path="Dockerfile",
 | 
				
			||||||
    context_mount=Mount.from_local_file("requirements.txt"),
 | 
					    context_mount=Mount.from_local_file("requirements.txt"),
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
stub.image = base_stub.dockerfile_commands(
 | 
					app.image = base_stub.dockerfile_commands(
 | 
				
			||||||
    "FROM base",
 | 
					    "FROM base",
 | 
				
			||||||
    "COPY config.yml /",
 | 
					    "COPY config.yml /",
 | 
				
			||||||
    context_mount=Mount.from_local_file("config.yml"),
 | 
					    context_mount=Mount.from_local_file("config.yml"),
 | 
				
			||||||
 | 
				
			|||||||
@ -10,11 +10,11 @@ from setup import (
 | 
				
			|||||||
    BASE_CACHE_PATH_CONTROLNET,
 | 
					    BASE_CACHE_PATH_CONTROLNET,
 | 
				
			||||||
    BASE_CACHE_PATH_LORA,
 | 
					    BASE_CACHE_PATH_LORA,
 | 
				
			||||||
    BASE_CACHE_PATH_TEXTUAL_INVERSION,
 | 
					    BASE_CACHE_PATH_TEXTUAL_INVERSION,
 | 
				
			||||||
    stub,
 | 
					    app,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@stub.cls(
 | 
					@app.cls(
 | 
				
			||||||
    gpu="A10G",
 | 
					    gpu="A10G",
 | 
				
			||||||
    secrets=[Secret.from_dotenv(__file__)],
 | 
					    secrets=[Secret.from_dotenv(__file__)],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@ -187,15 +187,16 @@ class SD15:
 | 
				
			|||||||
            generated_images.extend(fixed_by_controlnet)
 | 
					            generated_images.extend(fixed_by_controlnet)
 | 
				
			||||||
            base_images = fixed_by_controlnet
 | 
					            base_images = fixed_by_controlnet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if upscaler != "":
 | 
					        # TODO: Upscaler stopped working due to update of dependent packages. Replace with diffusers upscaler.
 | 
				
			||||||
            upscaled = self._upscale(
 | 
					        # if upscaler != "":
 | 
				
			||||||
                base_images=base_images,
 | 
					        #     upscaled = self._upscale(
 | 
				
			||||||
                half_precision=False,
 | 
					        #         base_images=base_images,
 | 
				
			||||||
                tile=700,
 | 
					        #         half_precision=False,
 | 
				
			||||||
                upscaler=upscaler,
 | 
					        #         tile=700,
 | 
				
			||||||
                use_face_enhancer=use_face_enhancer,
 | 
					        #         upscaler=upscaler,
 | 
				
			||||||
            )
 | 
					        #         use_face_enhancer=use_face_enhancer,
 | 
				
			||||||
            generated_images.extend(upscaled)
 | 
					        #     )
 | 
				
			||||||
 | 
					        #     generated_images.extend(upscaled)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        image_output = []
 | 
					        image_output = []
 | 
				
			||||||
        for image in generated_images:
 | 
					        for image in generated_images:
 | 
				
			||||||
 | 
				
			|||||||
@ -5,10 +5,10 @@ import os
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import PIL.Image
 | 
					import PIL.Image
 | 
				
			||||||
from modal import Secret, enter, method
 | 
					from modal import Secret, enter, method
 | 
				
			||||||
from setup import BASE_CACHE_PATH, BASE_CACHE_PATH_CONTROLNET, stub
 | 
					from setup import BASE_CACHE_PATH, app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@stub.cls(
 | 
					@app.cls(
 | 
				
			||||||
    gpu="A10G",
 | 
					    gpu="A10G",
 | 
				
			||||||
    secrets=[Secret.from_dotenv(__file__)],
 | 
					    secrets=[Secret.from_dotenv(__file__)],
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@ -39,13 +39,13 @@ class SDXLTxt2Img:
 | 
				
			|||||||
            variant="fp16",
 | 
					            variant="fp16",
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # self.refiner_cache_path = self.cache_path + "-refiner"
 | 
					        self.refiner_cache_path = self.cache_path + "-refiner"
 | 
				
			||||||
        # self.refiner = diffusers.StableDiffusionXLImg2ImgPipeline.from_pretrained(
 | 
					        self.refiner = diffusers.StableDiffusionXLImg2ImgPipeline.from_pretrained(
 | 
				
			||||||
        #     self.refiner_cache_path,
 | 
					            self.refiner_cache_path,
 | 
				
			||||||
        #     torch_dtype=torch.float16,
 | 
					            torch_dtype=torch.float16,
 | 
				
			||||||
        #     use_safetensors=True,
 | 
					            use_safetensors=True,
 | 
				
			||||||
        #     variant="fp16",
 | 
					            variant="fp16",
 | 
				
			||||||
        # )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # controlnets = config.get("controlnets")
 | 
					        # controlnets = config.get("controlnets")
 | 
				
			||||||
        # if controlnets is not None:
 | 
					        # if controlnets is not None:
 | 
				
			||||||
@ -94,12 +94,10 @@ class SDXLTxt2Img:
 | 
				
			|||||||
        n_prompt: str,
 | 
					        n_prompt: str,
 | 
				
			||||||
        height: int = 1024,
 | 
					        height: int = 1024,
 | 
				
			||||||
        width: int = 1024,
 | 
					        width: int = 1024,
 | 
				
			||||||
        batch_size: int = 1,
 | 
					 | 
				
			||||||
        steps: int = 30,
 | 
					        steps: int = 30,
 | 
				
			||||||
        seed: int = 1,
 | 
					        seed: int = 1,
 | 
				
			||||||
        upscaler: str = "",
 | 
					        upscaler: str = "",
 | 
				
			||||||
        use_face_enhancer: bool = False,
 | 
					        use_face_enhancer: bool = False,
 | 
				
			||||||
        fix_by_controlnet_tile: bool = False,
 | 
					 | 
				
			||||||
        output_format: str = "png",
 | 
					        output_format: str = "png",
 | 
				
			||||||
    ) -> list[bytes]:
 | 
					    ) -> list[bytes]:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@ -119,37 +117,33 @@ class SDXLTxt2Img:
 | 
				
			|||||||
        ).images
 | 
					        ).images
 | 
				
			||||||
        base_images = generated_images
 | 
					        base_images = generated_images
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # for image in base_images:
 | 
					        for image in base_images:
 | 
				
			||||||
        #     image = self._resize_image(image=image, scale_factor=2)
 | 
					            image = self._resize_image(image=image, scale_factor=2)
 | 
				
			||||||
        #     self.refiner.to("cuda")
 | 
					            self.refiner.to("cuda")
 | 
				
			||||||
        #     refined_images = self.refiner(
 | 
					            refined_images = self.refiner(
 | 
				
			||||||
        #         prompt=prompt,
 | 
					                prompt=prompt,
 | 
				
			||||||
        #         negative_prompt=n_prompt,
 | 
					                negative_prompt=n_prompt,
 | 
				
			||||||
        #         num_inference_steps=steps,
 | 
					                num_inference_steps=steps,
 | 
				
			||||||
        #         strength=0.1,
 | 
					                strength=0.1,
 | 
				
			||||||
        #         # guidance_scale=7.5,
 | 
					                # guidance_scale=7.5,
 | 
				
			||||||
        #         generator=generator,
 | 
					                generator=generator,
 | 
				
			||||||
        #         image=image,
 | 
					                image=image,
 | 
				
			||||||
        #     ).images
 | 
					            ).images
 | 
				
			||||||
        # generated_images.extend(refined_images)
 | 
					        generated_images.extend(refined_images)
 | 
				
			||||||
        # base_images = refined_images
 | 
					        base_images = refined_images
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Fix the generated images by the control_v11f1e_sd15_tile when `fix_by_controlnet_tile` is `True`.
 | 
					        Fix the generated images by the control_v11f1e_sd15_tile when `fix_by_controlnet_tile` is `True`.
 | 
				
			||||||
        https://huggingface.co/lllyasviel/control_v11f1e_sd15_tile
 | 
					        https://huggingface.co/lllyasviel/control_v11f1e_sd15_tile
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        # if fix_by_controlnet_tile:
 | 
					        # if fix_by_controlnet_tile:
 | 
				
			||||||
        #     max_embeddings_multiples = self._count_token(p=prompt, n=n_prompt)
 | 
					        #     max_embeddings_multiples = self._count_token(p=prompt, n=n_prompt)
 | 
				
			||||||
        #     print("========================確認用========================")
 | 
					 | 
				
			||||||
        #     print("Step1")
 | 
					 | 
				
			||||||
        #     self.controlnet_pipe.to("cuda")
 | 
					        #     self.controlnet_pipe.to("cuda")
 | 
				
			||||||
        #     self.controlnet_pipe.enable_vae_tiling()
 | 
					        #     self.controlnet_pipe.enable_vae_tiling()
 | 
				
			||||||
        #     self.controlnet_pipe.enable_xformers_memory_efficient_attention()
 | 
					        #     self.controlnet_pipe.enable_xformers_memory_efficient_attention()
 | 
				
			||||||
        #     print("Step2")
 | 
					 | 
				
			||||||
        #     for image in base_images:
 | 
					        #     for image in base_images:
 | 
				
			||||||
        #         image = self._resize_image(image=image, scale_factor=2)
 | 
					        #         image = self._resize_image(image=image, scale_factor=2)
 | 
				
			||||||
        #         print("Step3")
 | 
					 | 
				
			||||||
        #         with torch.autocast("cuda"):
 | 
					        #         with torch.autocast("cuda"):
 | 
				
			||||||
        #             print("Step4")
 | 
					 | 
				
			||||||
        #             fixed_by_controlnet = self.controlnet_pipe(
 | 
					        #             fixed_by_controlnet = self.controlnet_pipe(
 | 
				
			||||||
        #                 prompt=prompt * batch_size,
 | 
					        #                 prompt=prompt * batch_size,
 | 
				
			||||||
        #                 negative_prompt=n_prompt * batch_size,
 | 
					        #                 negative_prompt=n_prompt * batch_size,
 | 
				
			||||||
@ -160,7 +154,6 @@ class SDXLTxt2Img:
 | 
				
			|||||||
        #                 generator=generator,
 | 
					        #                 generator=generator,
 | 
				
			||||||
        #                 image=image,
 | 
					        #                 image=image,
 | 
				
			||||||
        #             ).images
 | 
					        #             ).images
 | 
				
			||||||
        #     print("Step5")
 | 
					 | 
				
			||||||
        #     generated_images.extend(fixed_by_controlnet)
 | 
					        #     generated_images.extend(fixed_by_controlnet)
 | 
				
			||||||
        #     base_images = fixed_by_controlnet
 | 
					        #     base_images = fixed_by_controlnet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,11 +3,11 @@ import time
 | 
				
			|||||||
import modal
 | 
					import modal
 | 
				
			||||||
import util
 | 
					import util
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stub = modal.Stub("run-stable-diffusion-cli")
 | 
					app = modal.App("run-stable-diffusion-cli")
 | 
				
			||||||
stub.run_inference = modal.Function.from_name("stable-diffusion-cli", "SD15.run_txt2img_inference")
 | 
					app.run_inference = modal.Function.from_name("stable-diffusion-cli", "SD15.run_txt2img_inference")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@stub.local_entrypoint()
 | 
					@app.local_entrypoint()
 | 
				
			||||||
def main(
 | 
					def main(
 | 
				
			||||||
    prompt: str,
 | 
					    prompt: str,
 | 
				
			||||||
    n_prompt: str,
 | 
					    n_prompt: str,
 | 
				
			||||||
@ -33,7 +33,7 @@ def main(
 | 
				
			|||||||
        if seed == -1:
 | 
					        if seed == -1:
 | 
				
			||||||
            seed_generated = util.generate_seed()
 | 
					            seed_generated = util.generate_seed()
 | 
				
			||||||
        start_time = time.time()
 | 
					        start_time = time.time()
 | 
				
			||||||
        images = stub.run_inference.remote(
 | 
					        images = app.run_inference.remote(
 | 
				
			||||||
            prompt=prompt,
 | 
					            prompt=prompt,
 | 
				
			||||||
            n_prompt=n_prompt,
 | 
					            n_prompt=n_prompt,
 | 
				
			||||||
            height=height,
 | 
					            height=height,
 | 
				
			||||||
 | 
				
			|||||||
@ -3,16 +3,18 @@ import time
 | 
				
			|||||||
import modal
 | 
					import modal
 | 
				
			||||||
import util
 | 
					import util
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stub = modal.Stub("run-stable-diffusion-cli")
 | 
					app = modal.Stub("run-stable-diffusion-cli")
 | 
				
			||||||
stub.run_inference = modal.Function.from_name("stable-diffusion-cli", "SDXLTxt2Img.run_inference")
 | 
					app.run_inference = modal.Function.from_name("stable-diffusion-cli", "SDXLTxt2Img.run_inference")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@stub.local_entrypoint()
 | 
					@app.local_entrypoint()
 | 
				
			||||||
def main(
 | 
					def main(
 | 
				
			||||||
    prompt: str,
 | 
					    prompt: str,
 | 
				
			||||||
 | 
					    n_prompt: str,
 | 
				
			||||||
    height: int = 1024,
 | 
					    height: int = 1024,
 | 
				
			||||||
    width: int = 1024,
 | 
					    width: int = 1024,
 | 
				
			||||||
    samples: int = 5,
 | 
					    samples: int = 5,
 | 
				
			||||||
 | 
					    steps: int = 20,
 | 
				
			||||||
    seed: int = -1,
 | 
					    seed: int = -1,
 | 
				
			||||||
    upscaler: str = "",
 | 
					    upscaler: str = "",
 | 
				
			||||||
    use_face_enhancer: str = "False",
 | 
					    use_face_enhancer: str = "False",
 | 
				
			||||||
@ -29,10 +31,12 @@ def main(
 | 
				
			|||||||
        if seed == -1:
 | 
					        if seed == -1:
 | 
				
			||||||
            seed_generated = util.generate_seed()
 | 
					            seed_generated = util.generate_seed()
 | 
				
			||||||
        start_time = time.time()
 | 
					        start_time = time.time()
 | 
				
			||||||
        images = stub.run_inference.remote(
 | 
					        images = app.run_inference.remote(
 | 
				
			||||||
            prompt=prompt,
 | 
					            prompt=prompt,
 | 
				
			||||||
 | 
					            n_prompt=n_prompt,
 | 
				
			||||||
            height=height,
 | 
					            height=height,
 | 
				
			||||||
            width=width,
 | 
					            width=width,
 | 
				
			||||||
 | 
					            steps=steps,
 | 
				
			||||||
            seed=seed_generated,
 | 
					            seed=seed_generated,
 | 
				
			||||||
            upscaler=upscaler,
 | 
					            upscaler=upscaler,
 | 
				
			||||||
            use_face_enhancer=use_face_enhancer == "True",
 | 
					            use_face_enhancer=use_face_enhancer == "True",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user