Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckpointLoaderSimple not finding model in folder #69

Closed
the-dream-machine opened this issue Sep 7, 2024 · 3 comments
Closed

CheckpointLoaderSimple not finding model in folder #69

the-dream-machine opened this issue Sep 7, 2024 · 3 comments
Labels
question Further information is requested runtime

Comments

@the-dream-machine
Copy link
Contributor

Related to #68. Decided to bake the model weights into the image by downloading the weights during build time:

import modal
import os
import requests
import io
import subprocess

app = modal.App("pony-diffusion")

image = (
    modal.Image.debian_slim(python_version="3.12.5")
    .apt_install("git", "libglib2.0-0", "libsm6", "libxrender1", "libxext6", "ffmpeg", "libgl1")
    .pip_install("torch==2.4.0+cu121", "torchvision", extra_options="--index-url https://download.pytorch.org/whl/cu121")
    .pip_install("xformers==0.0.27.post2")
    .pip_install("git+https://github.com/hiddenswitch/ComfyUI.git", extra_options="--no-build-isolation")
    .run_commands("comfyui --create-directories")
    .pip_install("comfy-script[default]", extra_options="--upgrade")
)

MODEL_URL = "https://civitai.com/api/download/models/290640"
MODEL_FILE_NAME = "pony-diffusion-v6-xl.safetensors"
MODEL_FILE_PATH = f"/models/checkpoints/{MODEL_FILE_NAME}"

@app.cls(gpu="T4", container_idle_timeout=120, image=image)
class Model:
    @modal.build()
    def build(self):
        print("🛠️ Building container...")

        os.makedirs(os.path.dirname(MODEL_FILE_PATH), exist_ok=True)
        with open(MODEL_FILE_PATH, "wb") as file:
            _ = file.write(requests.get(MODEL_URL).content)

    @modal.enter()
    def enter(self):
        print("✅ Entering container...")
        from comfy_script.runtime import load
        load("comfyui")

    @modal.exit()
    def exit(self):
        print("🧨 Exiting container...")

    @modal.method()
    def generate_image(self, prompt:str):
        print("🎨 Generating image...")

        from comfy_script.runtime import Workflow
        from comfy_script.runtime.nodes import CheckpointLoaderSimple, CLIPTextEncode, EmptyLatentImage, KSampler, VAEDecode, SaveImage

        with Workflow(wait=True):
            model, clip, vae = CheckpointLoaderSimple(MODEL_FILE_NAME)
            conditioning = CLIPTextEncode('beautiful scenery nature glass bottle landscape, , purple galaxy bottle,', clip)
            conditioning2 = CLIPTextEncode('text, watermark', clip)
            latent = EmptyLatentImage(512, 512, 1)
            latent = KSampler(model, 156680208700286, 20, 8, 'euler', 'normal', conditioning, conditioning2, latent, 1)
            image = VAEDecode(latent, vae)
            SaveImage(image, 'ComfyUI')

@app.local_entrypoint()
def main(prompt: str):
    Model().generate_image.remote(prompt)

CheckpointLoaderSimple doesn't seem to recognize the file in the models folder, here is the full error thrown:

🎨 Generating image...
Failed to validate prompt for output SaveImage.0:
* CheckpointLoaderSimple CheckpointLoaderSimple.0:
  - Value not in list: ckpt_name: 'pony-diffusion-v6-xl.safetensors' not in (list of length 36)
Output will be ignored
invalid prompt: {'type': 'prompt_outputs_failed_validation', 'message': 'Prompt outputs failed validation', 'details': '', 'extra_info': {}}
ComfyScript: Failed to queue prompt: <ClientResponse(http://127.0.0.1:8188/prompt) [400 Bad Request]>
<CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'Content-Length': '541', 'Date': 'Sat, 07 Sep 2024 00:00:25 GMT', 'Server': 'Python/3.12 aiohttp/3.9.1')>
<ClientResponse(http://127.0.0.1:8188/prompt) [400 Bad Request]>
<CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'Content-Length': '541', 'Date': 'Sat, 07 Sep 2024 00:00:25 GMT', 'Server': 'Python/3.12 aiohttp/3.9.1')>
{
  "error": {
    "type": "prompt_outputs_failed_validation",
    "message": "Prompt outputs failed validation",
    "details": "",
    "extra_info": {}
  },
  "node_errors": {
    "CheckpointLoaderSimple.0": {
      "errors": [
        {
          "type": "value_not_in_list",
          "message": "Value not in list",
          "details": "ckpt_name: 'pony-diffusion-v6-xl.safetensors' not in (list of length 36)",
          "extra_info": {
            "input_name": "ckpt_name",
            "input_config": null,
            "received_value": "pony-diffusion-v6-xl.safetensors"
          }
        }
      ],
      "dependent_outputs": [
        "SaveImage.0"
      ],
      "class_type": "CheckpointLoaderSimple"
    }
  }
}

I've confirmed that the model is downloaded to the checkpoints folder:
SCR-20240907-duot
SCR-20240907-duyg

@Chaoses-Ib
Copy link
Owner

It works on my side:

image

Is models in the working directory of the app? You can check it by:

import os
print(os.getcwd())
print(os.path.exists("models"))

Also, there was a bug in the old versions of the comfyui package that scripts named main.py can't find models properly: #65. But it's fixed recently, so if you are using the latest version it shouldn't be a problem.

@the-dream-machine
Copy link
Contributor Author

the-dream-machine commented Sep 7, 2024

Is models in the working directory of the app? You can check it by:

import os
print(os.getcwd())
print(os.path.exists("models"))

This returns /root and True respectively so the models folder is in the working directory. However, I'm seeing some more weird behavior that may be related to my environment setup. I'm going to investigate a little further and see if I can pin down the issue, I'll report back soon.

Thank you so much for your help and your quick responses. 👍

@Chaoses-Ib Chaoses-Ib added question Further information is requested runtime labels Sep 7, 2024
Chaoses-Ib added a commit that referenced this issue Sep 7, 2024
Co-Authored-By: the-dream-machine <20072792+the-dream-machine@users.noreply.github.com>
@Chaoses-Ib
Copy link
Owner

See #68 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested runtime
Projects
None yet
Development

No branches or pull requests

2 participants