AttributeError: 'NoneType' object has no attribute 'dtype' in modeling_cogagent.py
#2
by
truebit
- opened
When images is None, modeling_cogagent.py
would throw error. I added
cross_images = None
at line #935,
it would throw error: AttributeError: 'NoneType' object has no attribute 'dtype'
in stack:
[ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 412, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/cors.py", line 83, in __call__
await self.app(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 758, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 778, in app
await route.handle(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 299, in handle
await self.app(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 79, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/routing.py", line 299, in app
raise e
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/routing.py", line 294, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
return await dependant.call(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/Documents/CogVLM/openai_demo/openai_api.py", line 192, in create_chat_completion
response = generate_cogvlm(model, tokenizer, gen_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/Documents/CogVLM/openai_demo/openai_api.py", line 274, in generate_cogvlm
for response in generate_stream_cogvlm(model, tokenizer, params):
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 35, in generator_context
response = gen.send(None)
^^^^^^^^^^^^^^
File "/home/seganw/Documents/CogVLM/openai_demo/openai_api.py", line 383, in generate_stream_cogvlm
model.generate(**inputs, **gen_kwargs)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/transformers/generation/utils.py", line 1718, in generate
return self.greedy_search(
^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/transformers/generation/utils.py", line 2579, in greedy_search
outputs = self(
^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 786, in forward
outputs = self.model(
^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 539, in forward
return self.llm_forward(
^^^^^^^^^^^^^^^^^
File "/home/seganw/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 631, in llm_forward
layer_outputs = decoder_layer(
^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 382, in forward
attention_output, self_cross_attn_weights, present_cross_key_value = self.cross_attn(
^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 313, in forward
mixed_x_layer = self.key_value(encoder_outputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/bitsandbytes/nn/modules.py", line 240, in forward
self.set_compute_type(x)
File "/home/seganw/miniforge3/envs/CogVLM/lib/python3.11/site-packages/bitsandbytes/nn/modules.py", line 212, in set_compute_type
if x.dtype in [torch.float32, torch.bfloat16]:
^^^^^^^
AttributeError: 'NoneType' object has no attribute 'dtype'](ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 412, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/cors.py", line 83, in __call__
await self.app(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 758, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 778, in app
await route.handle(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 299, in handle
await self.app(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 79, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/routing.py", line 299, in app
raise e
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/routing.py", line 294, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
return await dependant.call(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/Documents/CogVLM/openai_demo/openai_api.py", line 192, in create_chat_completion
response = generate_cogvlm(model, tokenizer, gen_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/Documents/CogVLM/openai_demo/openai_api.py", line 274, in generate_cogvlm
for response in generate_stream_cogvlm(model, tokenizer, params):
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 35, in generator_context
response = gen.send(None)
^^^^^^^^^^^^^^
File "/home/truebit/Documents/CogVLM/openai_demo/openai_api.py", line 383, in generate_stream_cogvlm
model.generate(**inputs, **gen_kwargs)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/transformers/generation/utils.py", line 1718, in generate
return self.greedy_search(
^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/transformers/generation/utils.py", line 2579, in greedy_search
outputs = self(
^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 786, in forward
outputs = self.model(
^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 539, in forward
return self.llm_forward(
^^^^^^^^^^^^^^^^^
File "/home/truebit/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 631, in llm_forward
layer_outputs = decoder_layer(
^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 382, in forward
attention_output, self_cross_attn_weights, present_cross_key_value = self.cross_attn(
^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/.cache/huggingface/modules/transformers_modules/cogagent-chat-hf/modeling_cogagent.py", line 313, in forward
mixed_x_layer = self.key_value(encoder_outputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/accelerate/hooks.py", line 166, in new_forward
output = module._old_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/bitsandbytes/nn/modules.py", line 240, in forward
self.set_compute_type(x)
File "/home/truebit/miniforge3/envs/CogVLM/lib/python3.11/site-packages/bitsandbytes/nn/modules.py", line 212, in set_compute_type
if x.dtype in [torch.float32, torch.bfloat16]:
^^^^^^^
AttributeError: 'NoneType' object has no attribute 'dtype')
truebit
changed discussion title from
AttributeError: 'NoneType' object has no attribute 'dtype'
to AttributeError: 'NoneType' object has no attribute 'dtype' in modeling_cogagent.py
这个模型一定需要有图像才能对话,如果你是连续读话,可以直接把图像一起传入进去,在 history字段添加历史就行了