-
Notifications
You must be signed in to change notification settings - Fork 431
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
[WIP] Quick Llama3.2 e2e tutorial #1685
Open
RdoubleA
wants to merge
2
commits into
pytorch:main
Choose a base branch
from
RdoubleA:vlm_tutorial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
.. _finetune_vlm_label: | ||
|
||
========================================= | ||
Fine-Tune Your First VLM: Llama3.2-Vision | ||
========================================= | ||
|
||
In this tutorial, we will walk through fine-tuning Llama3.2-Vision-Instruct, a vision-language model (VLM), with a | ||
multimodal dataset in torchtune. | ||
|
||
.. grid:: 2 | ||
|
||
.. grid-item-card:: :octicon:`mortar-board;1em;` What you will learn | ||
|
||
* How to configure multimodal datasets | ||
* How to run inference on and evaluate a VLM | ||
|
||
.. grid-item-card:: :octicon:`list-unordered;1em;` Prerequisites | ||
|
||
* Install torchtune nightly build | ||
* Download the Llama3.2-Vision-Instruct model from Hugging Face | ||
|
||
Running a fine-tuning recipe | ||
---------------------------- | ||
|
||
After you've downloaded the Llama3.2 model, you can start fine-tuning it right away with ``tune run``. Let's | ||
launching a single device training job with the default dataset, the OCR-VQA subset of The Cauldron. | ||
|
||
.. code-block:: bash | ||
|
||
tune run full_finetune_single_device --config llama3_2_vision/11B_full_single_device max_steps_per_epoch=100 | ||
|
||
You can see where the dataset is defined in the config file. | ||
|
||
.. code-block:: yaml | ||
|
||
dataset: | ||
_component_: torchtune.datasets.multimodal.the_cauldron_dataset | ||
subset: ocrvqa | ||
|
||
You can modify the config to use a different multimodal dataset. See :ref:`multimodal_dataset_usage_label` for available | ||
built-in datasets in torchtune. Let's use the :func:`~torchtune.datasets.multimodal.llava_instruct_dataset` as an example. | ||
|
||
.. code-block:: yaml | ||
|
||
# This requires downloading the COCO image dataset separately | ||
dataset: | ||
_component_: torchtune.datasets.multimodal.llava_instruct_dataset | ||
image_dir: /home/user/coco/train2017/ | ||
|
||
.. code-block:: bash | ||
|
||
tune cp llama3_2_vision/11B_full_single_device ./my_config.yaml | ||
# Make changes to my_config.yaml | ||
tune run full_finetune_single_device --config my_config.yaml max_steps_per_epoch=100 | ||
|
||
You can also use :func:`~torchtune.datasets.multimodal.multimodal_chat_dataset` to define your custom multimodal dataset. | ||
See :ref:`example_multimodal` for more details. | ||
|
||
Inference | ||
--------- | ||
After fine-tuning, you can run inference on the model to check its output on sample data. | ||
In the generation config ``llama3_2_vision/generation_v2.yaml``, you can specify the input text | ||
and input image path (local or remote url). | ||
|
||
.. code-block:: yaml | ||
|
||
prompt: | ||
system: You are a helpful assistant who responds like the author Shakespeare. | ||
user: | ||
image: https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg | ||
text: What is in this image? | ||
|
||
Make sure you've updated the checkpoint files to point to your fine-tuned checkpoint. Then, you can run generation | ||
using ``tune run``. | ||
|
||
.. code-block:: bash | ||
|
||
tune cp llama3_2_vision/generation_v2 ./my_generation_config.yaml | ||
# Make changes to my_generation_config.yaml | ||
tune run dev/generate_v2 --config my_generation_config.yaml | ||
|
||
Evaluation | ||
---------- | ||
torchtune integrates with | ||
`EleutherAI's evaluation harness <https://github.com/EleutherAI/lm-evaluation-harness>`_ to run eval on MMMU for VLMs. | ||
You can update the config to point to your fine-tuned model, then run the eval recipe. | ||
|
||
.. code-block:: bash | ||
|
||
tune cp llama3_2_vision/evaluation ./my_evaluation_config.yaml | ||
# Make changes to my_evaluation_config.yaml | ||
tune run eleuther_eval --config my_evaluation_config.yaml | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a pointer to this from the README as well