Skip to content

Fix local variable 'image_features' referenced before assignment#1383

Merged
regisss merged 1 commit into
huggingface:transformers_futurefrom
vidyasiv:fix_image_features_llava
Oct 1, 2024
Merged

Fix local variable 'image_features' referenced before assignment#1383
regisss merged 1 commit into
huggingface:transformers_futurefrom
vidyasiv:fix_image_features_llava

Conversation

@vidyasiv
Copy link
Copy Markdown
Contributor

@vidyasiv vidyasiv commented Sep 30, 2024

What does this PR do?

PR fixes the following tests:

pytest -v -s tests/test_image_to_text_example.py -k llava-1.5

Failure:

UnboundLocalError: local variable 'image_features' referenced before assignment

Issue comes from transformers: huggingface/transformers@9c4639b#diff-2204a446d82a75771bf0df20c493c6b6cdfba7a87e51767ac63aa9cf8832100aR555
image_features is set inside an if statement and the tests fails as they don't enter it.

Verify outputs/functional accuracy test

  1. llava-1.5-7b-hf, BF16
python3 /root/synopsis/transformers_future/examples/image-to-text/run_pipeline.py --model_name_or_path llava-hf/llava-1.5-7b-hf --batch_size 1 --max_new_tokens 20 --use_hpu_graphs --bf16

# With this PR on transformers_future
09/30/2024 20:11:57 - INFO - __main__ - result = [[{'generated_text': 'USER:  \nWhat is shown in this image? ASSISTANT: The image shows a pier extending out over a body of water, with a mountain in the background.'}]]
09/30/2024 20:11:57 - INFO - __main__ - time = 224.79350978974253ms, Throughput (including tokenization) = 80.0734861822125 tokens/second
# On main
09/30/2024 20:16:39 - INFO - __main__ - result = [[{'generated_text': 'USER:  \nWhat is shown in this image? ASSISTANT: The image shows a pier extending out over a body of water, with a mountain in the background.'}]]
09/30/2024 20:16:39 - INFO - __main__ - time = 223.51140959654003ms, Throughput (including tokenization) = 80.53280158042831 tokens/second
  1. llava-1.5-13b-hf, BF16
python3 /root/synopsis/transformers_future/examples/image-to-text/run_pipeline.py --model_name_or_path llava-hf/llava-1.5-13b-hf --batch_size 1 --max_new_tokens 20 --use_hpu_graphs --bf16
# With this PR on transformers_future
09/30/2024 20:13:36 - INFO - __main__ - result = [[{'generated_text': 'USER:  \nWhat is shown in this image? ASSISTANT: The image shows a wooden pier extending out into a large body of water, with mountains in the background'}]]
09/30/2024 20:13:36 - INFO - __main__ - time = 366.76659581717104ms, Throughput (including tokenization) = 49.07753379201631 tokens/second
# On main
09/30/2024 20:17:22 - INFO - __main__ - result = [[{'generated_text': 'USER:  \nWhat is shown in this image? ASSISTANT: The image shows a wooden pier extending out into a large body of water, with mountains in the background'}]]
09/30/2024 20:17:22 - INFO - __main__ - time = 364.24360398668796ms, Throughput (including tokenization) = 49.41747721301881 tokens/second

Regressions on transformers_future + this PR

pytest -v -s tests/test_image_to_text_example.py 
=10 passed in 665.23s (0:11:05) =

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@vidyasiv vidyasiv marked this pull request as ready for review September 30, 2024 22:59
@vidyasiv vidyasiv requested a review from regisss as a code owner September 30, 2024 22:59
Copy link
Copy Markdown
Collaborator

@regisss regisss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

We could also add

image_hidden_states=image_features if pixel_values is not None and input_ids.shape[1] != 1 else None,

in the output, but it may not cover every case.

@regisss regisss merged commit 2332afb into huggingface:transformers_future Oct 1, 2024
alekseyfa pushed a commit to alekseyfa/optimum-habana that referenced this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants