mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
589 stars 159 forks source link

Error when launching Fooocus on a container. #368

Closed ryanrezrez closed 4 months ago

ryanrezrez commented 5 months ago

When i try to launch my container on modal.com in Fooocus i get a few errors. This is the log:

`[2024-06-27 17:32:25] INFO [System ARGV] ['main.py', '--host', '0.0.0.0', '--port', '8080'] [2024-06-27 17:32:25] INFO [Fooocus API] Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] [2024-06-27 17:32:25] INFO [Fooocus API] Fooocus API version: 0.4.1.0 Requirement already satisfied: torchsde==0.2.5 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 1)) (0.2.5) Requirement already satisfied: einops==0.4.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 2)) (0.4.1) Requirement already satisfied: transformers==4.30.2 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 3)) (4.30.2) Requirement already satisfied: safetensors==0.3.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 4)) (0.3.1) Requirement already satisfied: accelerate==0.21.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 5)) (0.21.0) Requirement already satisfied: pyyaml==6.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 6)) (6.0) Requirement already satisfied: Pillow==9.4.0 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 7)) (9.4.0) Requirement already satisfied: scipy==1.9.3 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 8)) (1.9.3) Requirement already satisfied: tqdm==4.64.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 9)) (4.64.1) Requirement already satisfied: psutil==5.9.5 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 10)) (5.9.5) Requirement already satisfied: pytorch_lightning==1.9.4 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 11)) (1.9.4) Requirement already satisfied: omegaconf==2.2.3 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 12)) (2.2.3) Requirement already satisfied: pygit2==1.12.2 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 13)) (1.12.2) Requirement already satisfied: opencv-contrib-python==4.8.0.74 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 14)) (4.8.0.74) Requirement already satisfied: onnxruntime==1.16.3 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 15)) (1.16.3) Requirement already satisfied: timm==0.9.2 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 16)) (0.9.2) Collecting fastapi>=0.103.1 (from -r requirements.txt (line 17)) Downloading fastapi-0.111.0-py3-none-any.whl.metadata (25 kB) Collecting pydantic==2.4.2 (from -r requirements.txt (line 18)) Downloading pydantic-2.4.2-py3-none-any.whl.metadata (158 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 158.6/158.6 kB 5.3 MB/s eta 0:00:00 Requirement already satisfied: pydantic_core==2.10.1 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 19)) (2.10.1) Requirement already satisfied: python-multipart==0.0.6 in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 20)) (0.0.6) Requirement already satisfied: uvicorn==0.23.2 in /opt/conda/lib/python3.10/site-packages (from uvicorn[standard]==0.23.2->-r requirements.txt (line 21)) (0.23.2) Requirement already satisfied: colorlog in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 22)) (6.8.2) Requirement already satisfied: requests in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 23)) (2.31.0) Requirement already satisfied: numpy in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 24)) (1.25.2) Requirement already satisfied: sqlalchemy in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 25)) (2.0.31) Requirement already satisfied: packaging in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 26)) (23.1) Requirement already satisfied: rich in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 27)) (12.3.0) Requirement already satisfied: chardet in /opt/conda/lib/python3.10/site-packages (from -r requirements.txt (line 28)) (4.0.0) ERROR: Exception: Traceback (most recent call last): File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/pkg_resources/init.py", line 3070, in _dep_map return self.dep_map File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/pkg_resources/init.py", line 2863, in getattr raise AttributeError(attr) AttributeError: _DistInfoDistributiondep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/requirements.py", line 36, in init parsed = _parse_requirement(requirement_string) File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/_parser.py", line 62, in parse_requirement return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES)) File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/_parser.py", line 80, in _parse_requirement url, specifier, marker = _parse_requirement_details(tokenizer) File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/_parser.py", line 118, in _parse_requirement_details specifier = _parse_specifier(tokenizer) File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/_parser.py", line 214, in _parse_specifier parsed_specifiers = _parse_version_many(tokenizer) File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/_parser.py", line 229, in _parse_version_many tokenizer.raise_syntax_error( File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/_tokenizer.py", line 167, in raise_syntax_error raise ParserSyntaxError( pip._vendor.packaging._tokenizer.ParserSyntaxError: . suffix can only be used with == or != operators numpy (>=1.19.) ; python_version >= "3.7"



The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 179, in exc_logging_wrapper
    status = run_func(*args)
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    return func(self, options, args)
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 377, in run
    requirement_set = resolver.resolve(
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 95, in resolve
    result = self._result = resolver.resolve(
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 427, in resolve
    failure_causes = self._attempt_to_pin_criterion(name)
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 239, in _attempt_to_pin_criterion
    criteria = self._get_updated_criteria(candidate)
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 229, in _get_updated_criteria
    for requirement in self._p.get_dependencies(candidate=candidate):
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/provider.py", line 247, in get_dependencies
    return [r for r in candidate.iter_dependencies(with_requires) if r is not None]
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/provider.py", line 247, in <listcomp>
    return [r for r in candidate.iter_dependencies(with_requires) if r is not None]
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 401, in iter_dependencies
    for r in self.dist.iter_dependencies():
  File "/opt/conda/lib/python3.10/site-packages/pip/_internal/metadata/pkg_resources.py", line 247, in iter_dependencies
    return self._dist.requires(extras)
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2786, in requires
    dm = self._dep_map
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3072, in _dep_map
    self.__dep_map = self._compute_dependencies()
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3082, in _compute_dependencies
    reqs.extend(parse_requirements(req))
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3135, in __init__
    super().__init__(requirement_string)
  File "/opt/conda/lib/python3.10/site-packages/pip/_vendor/packaging/requirements.py", line 38, in __init__
    raise InvalidRequirement(str(e)) from e
pip._vendor.packaging.requirements.InvalidRequirement: .* suffix can only be used with `==` or `!=` operators
    numpy (>=1.19.*) ; python_version >= "3.7"
           ~~~~~~~^
Installing requirements
CMD Failed install -r requirements.txt: Couldn't install requirements.
Command: "/opt/conda/bin/python" -m pip install -r requirements.txt --prefer-binary
Error code: 2
Downloading: "https://huggingface.co/lllyasviel/fav_models/resolve/main/fav/juggernautXL_v8Rundiffusion.safetensors" to /app/repositories/Fooocus/models/checkpoints/juggernautXL_v8Rundiffusion.safetensors

100%|██████████| 6.62G/6.62G [00:25<00:00, 281MB/s]
Downloading: "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors" to /app/repositories/Fooocus/models/loras/sd_xl_offset_example-lora_1.0.safetensors

100%|██████████| 47.3M/47.3M [00:00<00:00, 217MB/s]
Downloading: "https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth" to /app/repositories/Fooocus/models/vae_approx/xlvaeapp.pth

100%|██████████| 209k/209k [00:00<00:00, 14.7MB/s]
Downloading: "https://huggingface.co/lllyasviel/misc/resolve/main/vaeapp_sd15.pt" to /app/repositories/Fooocus/models/vae_approx/vaeapp_sd15.pth

100%|██████████| 209k/209k [00:00<00:00, 9.96MB/s]
Downloading: "https://huggingface.co/lllyasviel/misc/resolve/main/xl-to-v1_interposer-v3.1.safetensors" to /app/repositories/Fooocus/models/vae_approx/xl-to-v1_interposer-v3.1.safetensors

100%|██████████| 6.25M/6.25M [00:00<00:00, 104MB/s]
Downloading: "https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin" to /app/repositories/Fooocus/models/prompt_expansion/fooocus_expansion/pytorch_model.bin

100%|██████████| 335M/335M [00:01<00:00, 254MB/s]
Total VRAM 22693 MB, total RAM 167043 MB
Set vram state to: NORMAL_VRAM
Device: cuda:0 NVIDIA L4 : native
VAE dtype: torch.bfloat16
Using pytorch cross attention
Traceback (most recent call last):
  File "/app/main.py", line 197, in <module>
    if prepare_environments(args):
  File "/app/main.py", line 122, in prepare_environments
    from fooocusapi import worker
  File "/app/fooocusapi/worker.py", line 23, in <module>
    from fooocusapi.task_queue import (
  File "/app/fooocusapi/task_queue.py", line 21, in <module>
    from fooocusapi.parameters import ImageGenerationParams
  File "/app/fooocusapi/parameters.py", line 5, in <module>
    from fooocusapi.models.common.requests import AdvancedParams
  File "/app/fooocusapi/models/common/requests.py", line 31, in <module>
    from fooocusapi.models.common.base import (
  File "/app/fooocusapi/models/common/base.py", line 6, in <module>
    from pydantic import (
ImportError: cannot import name 'TypeAdapter' from 'pydantic' (/opt/conda/lib/python3.10/site-packages/pydantic/__init__.cpython-310-x86_64-linux-gnu.so)
Traceback (most recent call last):
  File "/pkg/modal/_container_io_manager.py", line 492, in handle_input_exception
    yield
  File "/pkg/modal/_container_entrypoint.py", line 351, in run_input_async
    async for value in res:
  File "/pkg/modal/_asgi.py", line 128, in fn
    app_task.result()  # consume/raise exceptions if there are any!
  File "/opt/conda/lib/python3.10/site-packages/fastapi/applications.py", line 270, in __call__
    await super().__call__(scope, receive, send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/opt/conda/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/middleware/cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/opt/conda/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/opt/conda/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/opt/conda/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/opt/conda/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/opt/conda/lib/python3.10/site-packages/fastapi/routing.py", line 235, in app
    raw_response = await run_endpoint_function(
  File "/opt/conda/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/opt/conda/lib/python3.10/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/opt/conda/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "/opt/conda/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
    return await future
  File "/opt/conda/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 859, in run
    result = context.run(func, *args)
  File "/root/deploy.py", line 23, in api
    subprocess.run(command, check=True)
  File "/opt/conda/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['python', 'main.py', '--host', '0.0.0.0', '--port', '8080']' returned non-zero exit status 1.`

Please help. This is my dockerbuild:
FROM konieshadow/fooocus-api

WORKDIR /app

CMD ["python", "main.py", "--host", "0.0.0.0", "--port", "8888"]
davefojtik commented 5 months ago

The numpy doesn't have version specified in the requirements file. I had to deal with this when building the latest RunPods too. I believe you have to pump up the torchsde from 0.2.5 to 0.2.6 to fix it, as it was some bug in the dependencies.

See: https://github.com/pypa/pip/issues/12146

ryanrezrez commented 4 months ago

Thank you very much this fixed it.