Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image-text-to-text task guide #31777

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

merveenoyan
Copy link
Contributor

Added shortly image-text-to-text task guide that includes streaming and more

@merveenoyan merveenoyan requested a review from stevhliu July 3, 2024 14:56
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

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

Very nice job! 🙂

docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
@merveenoyan merveenoyan requested a review from stevhliu July 4, 2024 08:44
Copy link
Member

@stevhliu stevhliu left a comment

Choose a reason for hiding this comment

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

Awesome work, thanks again!

@stevhliu stevhliu requested a review from amyeroberts July 8, 2024 17:10
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for adding!

Some comments, mostly nits

docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b")
```

This model has a [chat template](./chat_templating) format that's required for the input. Moreover, the model can also accept multiple images as input in a single conversation or message. We will now prepare the inputs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't quite right, we don't need to use a chat template for the model inputs. It's just useful to correctly format the prompt in the case of message-style inputs

Copy link
Contributor Author

@merveenoyan merveenoyan Jul 10, 2024

Choose a reason for hiding this comment

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

You likely know better, I thought when fine-tuning these chat templates are included in fine-tuning data, thus it is required to use chat templates no? e.g. Mistral one has <INST> </INST>

img_urls =["https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/cats.png",
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"]
images = [Image.open(requests.get(img_urls[0], stream=True).raw),
Image.open(requests.get(img_urls[1], stream=True).raw)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved

acc_text = ""
for text_token in streamer:
time.sleep(0.04)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

otherwise the text flows super fast which is essentially against streaming (and also from my experience it was crashing too)

docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
target=model.generate,
kwargs=generation_args,
)
thread.start()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this be safely closed?

docs/source/en/tasks/image_text_to_text.md Outdated Show resolved Hide resolved
quantized_model = Idefics2ForConditionalGeneration.from_pretrained(model_id, device_map="cuda", quantization_config=quantization_config)
```

And that's it, we can use the model the same way with no changes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good here to note what kind of change this makes e.g. x% reduction in memory footprint

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.

None yet

4 participants