Repository: modal-labs/modal-examples

Issue:
a1111 example
this [a1111](https://modal.com/docs/examples/a1111_webui#stable-diffusion-a1111) example is broken and gives the issue below. 

I think the issue is that the setup is just out of date for a1111
```
╰─$ modal run a1111_webui.py                                                                                                            2 ↵
✓ Initialized. View run at https://modal.com/nicholaskao1029/apps/ap-LdFciiKaOuin89Vcq9BGg4
Building image im-8pFRuirFJZ4P0wH3Lin4Fm

=> Step 0: FROM base

=> Step 1: RUN cd /webui && . venv/bin/activate && python -c 'from modules import shared_init, initialize; shared_init.initialize(); initialize.initialize()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/webui/modules/shared_init.py", line 5, in <module>
    from modules import shared
  File "/webui/modules/shared.py", line 3, in <module>
    import gradio as gr
  File "/webui/venv/lib/python3.10/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio.components as components
  File "/webui/venv/lib/python3.10/site-packages/gradio/components/__init__.py", line 1, in <module>
    from gradio.components.annotated_image import AnnotatedImage
  File "/webui/venv/lib/python3.10/site-packages/gradio/components/annotated_image.py", line 12, in <module>
    from gradio import utils
  File "/webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 353, in <module>
    class AsyncRequest:
  File "/webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 372, in AsyncRequest
    client = httpx.AsyncClient()
  File "/webui/venv/lib/python3.10/site-packages/httpx/_client.py", line 1397, in __init__
    self._transport = self._init_transport(
  File "/webui/venv/lib/python3.10/site-packages/httpx/_client.py", line 1445, in _init_transport
    return AsyncHTTPTransport(
  File "/webui/venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 275, in __init__
    self._pool = httpcore.AsyncConnectionPool(
TypeError: AsyncConnectionPool.__init__() got an unexpected keyword argument 'socket_options'
Terminating task due to error: failed to run builder command "cd /webui && . venv/bin/activate && python -c 'from modules import shared_init, initialize; shared_init.initialize(); initialize.initialize()'"

Caused by:
    container exit status: 1
Runner failed with exception: task exited with failure, status = exit status: 1
Stopping app - uncaught exception raised locally: RemoteError('Image build for im-8pFRuirFJZ4P0wH3Lin4Fm failed with the exception:\ntask exited with failure, status = exit status: 1').
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/bin/modal:8 in <module>                            │
│                                                                                                  │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(main())                                                                         │
│   9                                                                                              │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/__main__.py:9   │
│ in main                                                                                          │
│                                                                                                  │
│    8 │   setup_rich_traceback()                                                                  │
│ ❱  9 │   entrypoint_cli()                                                                        │
│   10                                                                                             │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/click/core.py:1157 in │
│ __call__                                                                                         │
│                                                                                                  │
│   1156 │   │   """Alias for :meth:`main`."""                                                     │
│ ❱ 1157 │   │   return self.main(*args, **kwargs)                                                 │
│   1158                                                                                           │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/typer/core.py:778 in  │
│ main                                                                                             │
│                                                                                                  │
│   777 │   ) -> Any:                                                                              │
│ ❱ 778 │   │   return _main(                                                                      │
│   779 │   │   │   self,                                                                          │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/typer/core.py:216 in  │
│ _main                                                                                            │
│                                                                                                  │
│   215 │   │   │   with self.make_context(prog_name, args, **extra) as ctx:                       │
│ ❱ 216 │   │   │   │   rv = self.invoke(ctx)                                                      │
│   217 │   │   │   │   if not standalone_mode:                                                    │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/click/core.py:1688 in │
│ invoke                                                                                           │
│                                                                                                  │
│   1687 │   │   │   │   with sub_ctx:                                                             │
│ ❱ 1688 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))               │
│   1689                                                                                           │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/click/core.py:1688 in │
│ invoke                                                                                           │
│                                                                                                  │
│   1687 │   │   │   │   with sub_ctx:                                                             │
│ ❱ 1688 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))               │
│   1689                                                                                           │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/click/core.py:1434 in │
│ invoke                                                                                           │
│                                                                                                  │
│   1433 │   │   if self.callback is not None:                                                     │
│ ❱ 1434 │   │   │   return ctx.invoke(self.callback, **ctx.params)                                │
│   1435                                                                                           │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/click/core.py:783 in  │
│ invoke                                                                                           │
│                                                                                                  │
│    782 │   │   │   with ctx:                                                                     │
│ ❱  783 │   │   │   │   return __callback(*args, **kwargs)                                        │
│    784                                                                                           │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/click/decorators.py:3 │
│ 3 in new_func                                                                                    │
│                                                                                                  │
│    32 │   def new_func(*args: "P.args", **kwargs: "P.kwargs") -> "R":                            │
│ ❱  33 │   │   return f(get_current_context(), *args, **kwargs)                                   │
│    34                                                                                            │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/cli/run.py:145  │
│ in f                                                                                             │
│                                                                                                  │
│   144 │   │                                                                                      │
│ ❱ 145 │   │   with run_stub(                                                                     │
│   146 │   │   │   stub,                                                                          │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/synchronicity/synchro │
│ nizer.py:497 in proxy_method                                                                     │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/synchronicity/combine │
│ d_types.py:26 in __call__                                                                        │
│                                                                                                  │
│ /usr/lib/python3.10/contextlib.py:199 in __aenter__                                              │
│                                                                                                  │
│   198 │   │   try:                                                                               │
│ ❱ 199 │   │   │   return await anext(self.gen)                                                   │
│   200 │   │   except StopAsyncIteration:                                                         │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/runner.py:140   │
│ in _run_stub                                                                                     │
│                                                                                                  │
│   139 │   │   │   exc_info = e                                                                   │
│ ❱ 140 │   │   │   raise e                                                                        │
│   141 │   │   finally:                                                                           │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/runner.py:94 in │
│ _run_stub                                                                                        │
│                                                                                                  │
│    93 │   │   │   # Create all members                                                           │
│ ❱  94 │   │   │   await app._create_all_objects(                                                 │
│    95 │   │   │   │   stub._indexed_objects, app_state, environment_name, shell=shell, output_   │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/app.py:106 in   │
│ _create_all_objects                                                                              │
│                                                                                                  │
│   105 │   │   │   │   existing_object_id = tag_to_object_id.get(tag)                             │
│ ❱ 106 │   │   │   │   await resolver.load(obj, existing_object_id)                               │
│   107 │   │   │   │   self._tag_to_object_id[tag] = obj.object_id                                │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/_resolver.py:13 │
│ 1 in load                                                                                        │
│                                                                                                  │
│   130 │   │                                                                                      │
│ ❱ 131 │   │   return await cached_future                                                         │
│   132                                                                                            │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/_resolver.py:10 │
│ 4 in loader                                                                                      │
│                                                                                                  │
│   103 │   │   │   │   # TODO(erikbern): do we need existing_object_id for those?                 │
│ ❱ 104 │   │   │   │   await asyncio.gather(*[self.load(dep) for dep in obj.deps()])              │
│   105                                                                                            │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/_resolver.py:13 │
│ 1 in load                                                                                        │
│                                                                                                  │
│   130 │   │                                                                                      │
│ ❱ 131 │   │   return await cached_future                                                         │
│   132                                                                                            │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/_resolver.py:10 │
│ 7 in loader                                                                                      │
│                                                                                                  │
│   106 │   │   │   │   # Load the object itself                                                   │
│ ❱ 107 │   │   │   │   await obj._load(obj, self, existing_object_id)                             │
│   108 │   │   │   │   if existing_object_id is not None and obj.object_id != existing_object_i   │
│                                                                                                  │
│ /mnt/nvme_drive/Work/sd/modal/a1111modal/venv/lib/python3.10/site-packages/modal/image.py:318 in │
│ _load                                                                                            │
│                                                                                                  │
│    317 │   │   │   if result.status == api_pb2.GenericResult.GENERIC_STATUS_FAILURE:             │
│ ❱  318 │   │   │   │   raise RemoteError(f"Image build for {image_id} failed with the exception  │
│    319 │   │   │   elif result.status == api_pb2.GenericResult.GENERIC_STATUS_TERMINATED:        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RemoteError: Image build for im-8pFRuirFJZ4P0wH3Lin4Fm failed with the exception:
task exited with failure, status = exit status: 1
```


Discussion:
Thanks for reporting. A quick Google search shows that this is a bug introduced by A1111, who did not pin their dependency versions properly. https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13840
Just updated the upstream Git repo tag to 1.7.0, and they seem to have patched the issue on their end.

<img width="1627" alt="image" src="https://github.com/modal-labs/modal-examples/assets/7550632/f2efd1d5-08d8-480a-ac4e-1dd270552ad1">


Resolving patch:
diff --git a/06_gpu_and_ml/stable_diffusion/a1111_webui.py b/06_gpu_and_ml/stable_diffusion/a1111_webui.py
--- a/06_gpu_and_ml/stable_diffusion/a1111_webui.py
+++ b/06_gpu_and_ml/stable_diffusion/a1111_webui.py
@@ -48,7 +48,7 @@ def wait_for_port(port: int):
     )
     .env({"LD_PRELOAD": "/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4"})
     .run_commands(
-        "git clone --depth 1 --branch v1.6.0 https://github.com/AUTOMATIC1111/stable-diffusion-webui /webui",
+        "git clone --depth 1 --branch v1.7.0 https://github.com/AUTOMATIC1111/stable-diffusion-webui /webui",
         "python -m venv /webui/venv",
         "cd /webui && . venv/bin/activate && "
         + "python -c 'from modules import launch_utils; launch_utils.prepare_environment()' --xformers",


Test patch: