microsoft / pyright

Static Type Checker for Python
Other
13.27k stars 1.44k forks source link

TypeError: StableDiffusionModelHijack.get_prompt_lengths() takes 2 positional arguments but 3 were given #7571

Closed chufanwsh closed 6 months ago

chufanwsh commented 6 months ago

Stable Diffusion 运行环境: Stable Diffusion environment: version: [v1.8.0]  •  python: 3.10.11  •  torch: 2.2.0+cu118  •  xformers: 0.0.24+cu118  •  gradio: 3.41.2  •  checkpoint: [7c819b6d13]

引发错误的插件:sd-webui-prompt-all-in-one Plugins that cause errors:sd-webui-prompt-all-in-one

Webui page error message: webui页面错误信息:'NoneType' object has no attribute 'group' 微信截图_20240327224150

控制台相关信息:(Console related information) *** API error: POST: http://127.0.0.1:7860/physton_prompt/token_counter {'error': 'TypeError', 'detail': '', 'body': '', 'errors': 'StableDiffusionModelHijack.get_prompt_lengths() takes 2 positional arguments but 3 were given'} Traceback (most recent call last): File "E:\sd-webui-aki-v4.7\python\lib\site-packages\anyio\streams\memory.py", line 94, in receive return self.receive_nowait() File "E:\sd-webui-aki-v4.7\python\lib\site-packages\anyio\streams\memory.py", line 89, in receive_nowait raise WouldBlock anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\base.py", line 78, in call_next
    message = await recv_stream.receive()
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\anyio\streams\memory.py", line 114, in receive
    raise EndOfStream
anyio.EndOfStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.7\modules\api\api.py", line 186, in exception_handling
    return await call_next(request)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
    raise app_exc
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "<enhanced_experience vendors.sentry_sdk.integrations.starlette>", line 157, in _create_span_call
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\base.py", line 108, in __call__
    response = await self.dispatch_func(request, call_next)
  File "E:\sd-webui-aki-v4.7\modules\api\api.py", line 150, in log_and_time
    res: Response = await call_next(req)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\base.py", line 84, in call_next
    raise app_exc
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "<enhanced_experience vendors.sentry_sdk.integrations.starlette>", line 157, in _create_span_call
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\cors.py", line 92, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\cors.py", line 147, in simple_response
    await self.app(scope, receive, send)
  File "<enhanced_experience vendors.sentry_sdk.integrations.starlette>", line 157, in _create_span_call
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "<enhanced_experience vendors.sentry_sdk.integrations.starlette>", line 256, in _sentry_exceptionmiddleware_call
  File "<enhanced_experience vendors.sentry_sdk.integrations.starlette>", line 157, in _create_span_call
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "<enhanced_experience vendors.sentry_sdk.integrations.starlette>", line 157, in _create_span_call
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
    raise e
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\starlette\routing.py", line 66, in app
    response = await func(request)
  File "<enhanced_experience vendors.sentry_sdk.integrations.fastapi>", line 136, in _sentry_app
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\fastapi\routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "E:\sd-webui-aki-v4.7\python\lib\site-packages\fastapi\routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "E:\sd-webui-aki-v4.7\extensions\sd-webui-prompt-all-in-one\scripts\on_app_started.py", line 108, in _token_counter
    return get_token_counter(data['text'], data['steps'])
  File "E:\sd-webui-aki-v4.7\extensions\sd-webui-prompt-all-in-one\scripts\physton_prompt\get_token_counter.py", line 31, in get_token_counter
    token_count, max_length = max([model_hijack.get_prompt_lengths(prompt,cond_stage_model) for prompt in prompts],
  File "E:\sd-webui-aki-v4.7\extensions\sd-webui-prompt-all-in-one\scripts\physton_prompt\get_token_counter.py", line 31, in <listcomp>
    token_count, max_length = max([model_hijack.get_prompt_lengths(prompt,cond_stage_model) for prompt in prompts],
TypeError: StableDiffusionModelHijack.get_prompt_lengths() takes 2 positional arguments but 3 were given

在SD 程序正常启动后,在sd-webui-prompt-all-in-one工具默认的百度翻译设置下,点击翻译提示词,webui页面右上角会出现错误信息:'NoneType' object has no attribute 'group',控制台出现以上相关错误信息。可以正常生成图片,我是个新手,还请大家帮忙指导解决。感谢帮助。

After the SD program starts normally, in the default Baidu translation settings of the sd-webii prompt all in one tool, click on the translation prompt word. An error message will appear in the upper right corner of the webui page: 'NoneType' object has no attribute 'group', and the console will display the above related error messages. I am a beginner and can generate images normally. Could you please help me guide and solve the problem. Thank you for your help.

erictraut commented 6 months ago

You have included a stack trace that has nothing to do with pyright. You have not explained how you're running pyright (as a CLI, in VS Code, in another editor, etc.). You have not provided any details about the code you're running pyright on. Please do not file additional bug reports of this nature. If you think that pyright might be in error, make sure to follow the instructions in the bug template and provide all of the requested information.

You mentioned that you're seeing a pyright-generated error. I presume that you are running pyright on your Python source code, and it is telling you that you have a type violation. That's the job of a static type checker. Since you haven't included a minimal, self-contained code sample, I can only guess at the cause of the error within your code. Based on the error message, it appears that you're attempting to reference an attribute via an object that could be None at runtime. A type checker's job is to tell you about potential bugs like this so you can fix them.

For basic information about static type checking, please refer to the pyright documentation.