InternLM / InternLM-XComposer

InternLM-XComposer2 is a groundbreaking vision-language large model (VLLM) excelling in free-form text-image composition and comprehension.
1.91k stars 120 forks source link

Error running 4khd inference #304

Closed ChorlingLau closed 1 month ago

ChorlingLau commented 1 month ago

I directly used the code from QuickStart in the model card, but encountered the following error.

Traceback (most recent call last):
  File "example_4khd_chat.py", line 47, in <module>
    response, his = model.chat(tokenizer, query=text, image=image, hd_num=55, history=[], do_sample=False, num_beams=3)
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/root/.cache/huggingface/modules/transformers_modules/internlm-xcomposer2-4khd-7b/modeling_internlm_xcomposer2.py", line 556, in chat
    outputs = self.generate(
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/transformers/generation/utils.py", line 1611, in generate
    return self.beam_search(
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/transformers/generation/utils.py", line 2909, in beam_search
    outputs = self(
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/.cache/huggingface/modules/transformers_modules/internlm-xcomposer2-4khd-7b/modeling_internlm_xcomposer2.py", line 408, in forward
    outputs = self.model(
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/.cache/huggingface/modules/transformers_modules/internlm-xcomposer2-4khd-7b/modeling_internlm2.py", line 960, in forward
    layer_outputs = decoder_layer(
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/.cache/huggingface/modules/transformers_modules/internlm-xcomposer2-4khd-7b/modeling_internlm2.py", line 659, in forward
    hidden_states, self_attn_weights, present_key_value = self.attention(
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/my/.conda/envs/internlm/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/.cache/huggingface/modules/transformers_modules/internlm-xcomposer2-4khd-7b/modeling_internlm2.py", line 488, in forward
    query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
  File "/root/.cache/huggingface/modules/transformers_modules/internlm-xcomposer2-4khd-7b/modeling_internlm2.py", line 235, in apply_rotary_pos_emb
    q_embed = (q * cos) + (rotate_half(q) * sin)
RuntimeError: The size of tensor a (8302) must match the size of tensor b (8303) at non-singleton dimension 2
../aten/src/ATen/native/cuda/IndexKernel.cu:92: operator(): block: [4151,0,0], thread: [32,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:92: operator(): block: [4151,0,0], thread: [33,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:92: operator(): block: [4151,0,0], thread: [34,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.

And I find the position_ids.shape is changing when processing the same image. Is there anyone else facing this error?