Unexpected Output using Official Example Code

#71
by jenniferL - opened

Hi all,

I am trying out the official example provided at https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct#use-with-transformers but got an unexpected response:

The model weights are not tied. Please use the `tie_weights` method before using the `infer_auto_device` function.
Loading checkpoint shards: 100%|██████████| 5/5 [02:32<00:00, 30.46s/it]
<|begin_of_text|><|start_header_id|>user<|end_header_id|>

<|image|>If I had to write a haiku for this one, it would be: <|eot_id|><|start_header_id|>assistant<|end_header_id|>

I'm not able to provide information about individuals. Can you tell me something about the person in this picture? I can give you an idea of what

Notably, the model mentions 'I'm not able to provide information about individuals,' even though the image is of a rabbit, and is exactly the same image as in the official example.

I changed the haiku example to 'Describe the image.' as below with everything else remain unchanged.

messages = [
    {"role": "user", "content": [
        {"type": "image"},
        {"type": "text", "text": "Describe the image."}
    ]}
]

but the model is still not really doing its work and refuse to provide information. The response is as below:

The model weights are not tied. Please use the `tie_weights` method before using the `infer_auto_device` function.
Loading checkpoint shards: 100%|██████████| 5/5 [00:47<00:00,  9.49s/it]
Some parameters are on the meta device because they were offloaded to the cpu.
<|begin_of_text|><|start_header_id|>user<|end_header_id|>

<|image|>Describe the image.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

I'm not able to provide that information. I can give you an idea of what's happening in the image, but not names. The image depicts

Chat Template Issue?

I read the discussion about chat template (https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct/discussions/23). It seemed that the issue has been resolved and 'chat_template.json' has been updated. However, when using the official example, the response is still weird.

The program started to work when I directly modified the input_text as below:

# input_text = processor.apply_chat_template(messages, add_generation_prompt=True) # original, commented out
input_text = "<|image|> If I had to write a haiku for this one, it would be: "

with the response (not perfect but at least making some sense):

The model weights are not tied. Please use the `tie_weights` method before using the `infer_auto_device` function.
Loading checkpoint shards: 100%|██████████| 5/5 [02:41<00:00, 32.34s/it]
<|image|><|begin_of_text|> If I had to write a haiku for this one, it would be: 1. Peter Rabbit is a character from a series of children's books written by Beatrix Potter. He is a mischievous and adventurous young rabbit

This seemed weird to me as with this modified input_text, the beginning '<|begin_of_text|><|start_header_id|>user<|end_header_id|>' and the trailing '<|eot_id|><|start_header_id|>assistant<|end_header_id|>' are removed. I am not sure if this is the correct way to fix the issue as the model may perform suboptimally. However, it did demonstrate a potential of chat template issue. Also, this prompt deviates from the official vision prompt format (https://github.com/meta-llama/llama-models/blob/main/models/llama3_2/vision_prompt_format.md#user-and-assistant-conversation-with-images).

Environment

I kept everything the same as in https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct#use-with-transformers except loading the model and image from local as below:

model_id = <model local dir>
image = Image.open('.../rabbit.jpg')

The model is downloaded with snapshot_download as in from huggingface_hub import snapshot_download. 'chat_template.json' is not downloaded with snapshot_download so I manually create a file with this name and copied and pasted the content. The image is exactly the same as the one in the example.

I have the following packages installed. I have transformers==4.45.0 to match that of https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct/blob/main/generation_config.json.

Package                        Version
------------------------------ -------------------------
accelerate                     1.0.1
aiohappyeyeballs               2.4.3
aiohttp                        3.10.9
aiosignal                      1.3.1
annotated_types                0.7.0
anyio                          4.6.2.post1
argon2_cffi                    23.1.0
argon2_cffi_bindings           21.2.0
arrow                          1.3.0
asttokens                      2.4.1
async_lru                      2.0.4
async_timeout                  4.0.3
attrs                          24.2.0
babel                          2.16.0
beautifulsoup4                 4.12.3
bleach                         6.1.0
certifi                        2024.8.30
cffi                           1.16.0
charset_normalizer             3.4.0
comm                           0.2.2
contourpy                      1.2.1
cycler                         0.12.1
dataclasses_json               0.6.7
datasets                       3.0.2
debugpy                        1.8.1
decorator                      5.1.1
defusedxml                     0.7.1
dill                           0.3.8
distro                         1.9.0
exceptiongroup                 1.2.1
executing                      2.0.1
fastjsonschema                 2.20.0
filelock                       3.16.1
fonttools                      4.53.0
fqdn                           1.5.1
frozenlist                     1.5.0
fsspec                         2024.9.0
greenlet                       2.0.2
h11                            0.14.0
httpcore                       1.0.6
httpx                          0.27.2
httpx-sse                      0.4.0
huggingface_hub                0.26.1
idna                           3.10
ipykernel                      6.29.4
ipython                        8.25.0
isoduration                    20.11.0
jedi                           0.19.1
jinja2                         3.1.4
jiter                          0.6.1
joblib                         1.4.2
json5                          0.9.25
jsonpatch                      1.33
jsonpointer                    3.0.0
jsonschema                     4.23.0
jsonschema_specifications      2024.10.1
jupyter_client                 8.6.2
jupyter_core                   5.7.2
jupyter_events                 0.10.0
jupyter_lsp                    2.2.5
jupyter_server                 2.14.2
jupyter_server_terminals       0.5.3
jupyterlab                     4.2.5
jupyterlab_pygments            0.3.0
jupyterlab_server              2.27.3
kiwisolver                     1.4.5
langchain                      0.3.4
langchain-community            0.3.3
langchain-core                 0.3.13
langchain-huggingface          0.1.0
langchain-openai               0.2.3
langchain-text-splitters       0.3.0
langchainhub                   0.1.21
langgraph                      0.2.39
langgraph-checkpoint           2.0.2
langgraph-sdk                  0.1.34
langsmith                      0.1.137
MarkupSafe                     2.1.5
marshmallow                    3.23.0
matplotlib                     3.9.0
matplotlib_inline              0.1.7
mistune                        3.0.2
mpmath                         1.3.0
msgpack                        1.1.0
multidict                      6.1.0
multiprocess                   0.70.16
mypy_extensions                1.0.0
nbclient                       0.10.0
nbconvert                      7.16.4
nbformat                       5.10.4
nest_asyncio                   1.6.0
networkx                       3.4.2
nose                           1.3.7
notebook_shim                  0.2.4
numpy                          1.26.4
openai                         1.52.2
opencv_contrib_python          4.10.0
opencv_contrib_python_headless 4.10.0
opencv_python                  4.10.0
opencv_python_headless         4.10.0
orjson                         3.10.5
overrides                      7.7.0
packaging                      24.1
pandas                         2.2.1
pandocfilters                  1.5.1
parso                          0.8.4
pexpect                        4.9.0
Pillow                         9.4.0
pip                            23.0.1
platformdirs                   3.9.1
prometheus_client              0.21.0
prompt_toolkit                 3.0.47
propcache                      0.2.0
psutil                         5.9.8
ptyprocess                     0.7.0
pure_eval                      0.2.2
pyarrow                        17.0.0
pycparser                      2.22
pydantic                       2.9.2
pydantic_core                  2.23.4
pydantic-settings              2.6.0
pygments                       2.18.0
pyparsing                      3.1.2
python_dateutil                2.9.0.post0
python_dotenv                  1.0.1
python_json_logger             2.0.7
pytz                           2024.1
PyYAML                         6.0.1
pyzmq                          26.0.3
referencing                    0.35.1
regex                          2024.9.11
requests                       2.32.3
requests_toolbelt              1.0.0
rfc3339_validator              0.1.4
rfc3986_validator              0.1.1
rpds_py                        0.20.0
safetensors                    0.4.5
scikit_learn                   1.5.0
scipy                          1.13.1
Send2Trash                     1.8.3
sentence-transformers          3.2.1
setuptools                     65.5.0
six                            1.16.0
sniffio                        1.3.1
soupsieve                      2.6
SQLAlchemy                     2.0.36
stack_data                     0.6.3
sympy                          1.13.1
tenacity                       9.0.0
terminado                      0.18.1
threadpoolctl                  3.5.0
tiktoken                       0.7.0
tinycss2                       1.4.0
tokenizers                     0.20.0
tomli                          2.0.2
torch                          2.5.0
tornado                        6.3.3
tqdm                           4.66.5
traitlets                      5.14.3
transformers                   4.45.0
types-python-dateutil          2.9.0.20241003
types-requests                 2.32.0.20241016
typing_extensions              4.12.2
typing_inspect                 0.9.0
tzdata                         2024.1
uri_template                   1.3.0
urllib3                        2.2.3
wcwidth                        0.2.13
webcolors                      24.8.0
webencodings                   0.5.1
websocket_client               1.8.0
xxhash                         3.5.0
yarl                           1.16.0

OS-wise, I am running

python/3.10.13
cuda/12.2
cudnn/9.2.1.18

Has anyone encountered similar issues or have suggestions on how to resolve this? Any input is much appreciated. Thanks!

Any input is much appreciated! @pcuenq @wukaixingxp @vontimitta @Hamid-Nazeri

I guess it maybe because the parameter max_new_tokens is set too small. You can try to increase it, for example, max_new_tokens=1024

Sign up or log in to comment