continue-revolution / sd-webui-animatediff

AnimateDiff for AUTOMATIC1111 Stable Diffusion WebUI
Other
3.11k stars 258 forks source link

[Bug]: API response with code 500, error said "'tuple' object does not support item assignment" #455

Closed yubingjiaocn closed 8 months ago

yubingjiaocn commented 8 months ago

Is there an existing issue for this?

Have you read FAQ on README?

What happened?

When calling /txt2img API, SD Web UI responses code 500 with the following error:

{
  "error": "TypeError",
  "detail": "",
  "body": "",
  "errors": "'tuple' object does not support item assignment"
}

While generating image via UI works well.

Steps to reproduce the problem

  1. Enable API mode of SD Web UI
  2. Send the following requests to http://localhost:8080/sdapi/v1/txt2img endpoints:
    {
    "alwayson_scripts": {
        "AnimateDiff": {
            "args": [
                {
                    "batch_size": 16,
                    "closed_loop": "N",
                    "enable": true,
                    "format": ["GIF"],
                    "fps": 8,
                    "interp": "Off",
                    "interp_x": 10,
                    "last_frame": null,
                    "latent_power": 1,
                    "latent_scale": 32,
                    "loop_number": 0,
                    "model": "mm_sd15_v3.safetensors",
                    "overlap": -1,
                    "stride": 1,
                    "video_length": 32
                }
            ]
        }
    },
    "batch_size": 32,
    "cfg_scale": 7,
    "height": 512,
    "negative_prompt": "(worst quality:1.2), (low quality:1.2), (lowres:1.1), (monochrome:1.1), (greyscale), multiple views, comic, sketch, (((bad anatomy))), (((deformed))), (((disfigured))), watermark, multiple_views, mutation hands, mutation fingers, extra fingers, missing fingers, watermark, nude, nsfw",
    "prompt": "masterpiece, 30 year old women, cleavage, red hair, bun, ponytail, medium breast, desert, cactus vibe, sensual pose, (looking in the camera:1.2), (front view:1.2), facing the camera, close up, upper body",
    "steps": 20,
    "width": 512
    }

What should have happened?

Response code should be 200, and animated image should be generated.

Commit where the problem happens

webui: bef51aed032c0aaa5cfd80445bc4cf0d85b408b5 extension: 12a503b8b782b57005a0108c80b42b95db2a09ec

What browsers do you use to access the UI ?

API using Swagger

Command Line Arguments

ACCELERATE=true exec python ./launch.py -f --api --api-log --no-gradio-queue --skip-prepare-environment --no-hashing --no-download-sd-model --loglevel INFO --log-startup --listen --port 8080 --xformers

Console logs

2024-03-07 11:48:26 INFO [modules.shared_state] Starting job scripts_txt2img
*** Error running before_process: /opt/ml/code/extensions/sd-webui-animatediff/scripts/animatediff.py
    Traceback (most recent call last):
      File "/opt/ml/code/modules/scripts.py", line 776, in before_process
        script.before_process(p, *script_args)
      File "/opt/ml/code/extensions/sd-webui-animatediff/scripts/animatediff.py", line 54, in before_process
        params = get_animatediff_arg(p)
      File "/opt/ml/code/extensions/sd-webui-animatediff/scripts/animatediff_utils.py", line 43, in get_animatediff_arg
        p.script_args[script.args_from] = animatediff_arg
    TypeError: 'tuple' object does not support item assignment

---
2024-03-07 11:48:26 INFO [modules.shared_state] Ending job scripts_txt2img (0.00 seconds)
*** API error: POST: http://localhost:8001/sdapi/v1/txt2img {'error': 'TypeError', 'detail': '', 'body': '', 'errors': "'tuple' object does not support item assignment"}
    Traceback (most recent call last):
      File "/home/user/.local/lib/python3.10/site-packages/anyio/streams/memory.py", line 98, in receive
        return self.receive_nowait()
      File "/home/user/.local/lib/python3.10/site-packages/anyio/streams/memory.py", line 93, in receive_nowait
        raise WouldBlock
    anyio.WouldBlock

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next
        message = await recv_stream.receive()
      File "/home/user/.local/lib/python3.10/site-packages/anyio/streams/memory.py", line 118, in receive
        raise EndOfStream
    anyio.EndOfStream

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/ml/code/modules/api/api.py", line 186, in exception_handling
        return await call_next(request)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
        raise app_exc
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/base.py", line 108, in __call__
        response = await self.dispatch_func(request, call_next)
      File "/opt/ml/code/modules/api/api.py", line 150, in log_and_time
        res: Response = await call_next(req)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
        raise app_exc
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
        await self.app(scope, receive_or_disconnect, send_no_error)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 92, in __call__
        await self.simple_response(scope, receive, send, request_headers=headers)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 147, in simple_response
        await self.app(scope, receive, send)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
        await responder(scope, receive, send)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in __call__
        await self.app(scope, receive, self.send_with_gzip)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
        raise exc
      File "/home/user/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
        await self.app(scope, receive, sender)
      File "/home/user/.local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
        raise e
      File "/home/user/.local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
        await self.app(scope, receive, send)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
        await route.handle(scope, receive, send)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
        await self.app(scope, receive, send)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
        response = await func(request)
      File "/home/user/.local/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app
        raw_response = await run_endpoint_function(
      File "/home/user/.local/lib/python3.10/site-packages/fastapi/routing.py", line 165, in run_endpoint_function
        return await run_in_threadpool(dependant.call, **values)
      File "/home/user/.local/lib/python3.10/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
        return await anyio.to_thread.run_sync(func, *args)
      File "/home/user/.local/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
        return await get_asynclib().run_sync_in_worker_thread(
      File "/home/user/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
        return await future
      File "/home/user/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
        result = context.run(func, *args)
      File "/opt/ml/code/modules/api/api.py", line 477, in text2imgapi
        processed = process_images(p)
      File "/opt/ml/code/modules/processing.py", line 785, in process_images
        res = process_images_inner(p)
      File "/opt/ml/code/extensions/sd-webui-controlnet/scripts/batch_hijack.py", line 46, in processing_process_images_hijack
        ad_params = get_animatediff_arg(p)
      File "/opt/ml/code/extensions/sd-webui-animatediff/scripts/animatediff_utils.py", line 43, in get_animatediff_arg
        p.script_args[script.args_from] = animatediff_arg
    TypeError: 'tuple' object does not support item assignment

---

Additional information

Python 3.10.12, torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 triton==2.1.0 xformers==0.0.23.post1

blueming333 commented 8 months ago

me too

yuchen1984 commented 8 months ago

FYI I made an unofficial hacky fix to v2.0.0a and the A1111 API now seems to work correctly for Animatediff+ControlNet .

https://github.com/continue-revolution/sd-webui-animatediff/compare/master...yuchen1984:sd-webui-animatediff:v2.0.0a-api-fix

continue-revolution commented 8 months ago

@yuchen1984 please make a PR to master branch and I will take a look.

yuchen1984 commented 8 months ago

PR created for your reference @continue-revolution https://github.com/continue-revolution/sd-webui-animatediff/pull/463

continue-revolution commented 8 months ago

fixed in #463

yuchen1984 commented 7 months ago

@continue-revolution https://github.com/continue-revolution/sd-webui-animatediff/pull/468 seems to break the API pipeline again. I made another fix in the PR below. Now it can handle the ip-adapter case (which takes a single reference image rather than batch images) as well, at least generating same results as the one from the WebUI....

https://github.com/continue-revolution/sd-webui-animatediff/pull/480