-
Notifications
You must be signed in to change notification settings - Fork 79
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
Llama3.2-Vision: Add reference submodule and tests #14051
Merged
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bab4a1d
#13368: Move repeat interleave to xattn cache generation.
cglagovichTT ee48aaa
#0: Clean up demo, enable arbitrary padding for multimodal text sequence
cglagovichTT 29ae070
#13368: Add llama_models Meta reference for Llama3.2 as a submodule
cglagovichTT 303be06
#13368: Change reference imports to use new submodule
cglagovichTT ef329cd
#13368: Clean up comments after pushing repeat_interleave into xattn_…
cglagovichTT 27fa6d5
#13368: Clean up vision tests. Unify assertions and pcc checks. Fix L…
cglagovichTT f11162c
#13368: Fix LM head splits calculation
cglagovichTT f64f65a
#13368: For all vision tests, get model-specific parameters from mode…
cglagovichTT 3a39037
#13368: Fixup tests
cglagovichTT 8689d40
#13368: Add vision tests to unit, frequent, and demo
cglagovichTT 80db0b8
#13368: Relaxed 11B perf estimate to avoid error in CI
mtairum dd10a03
#0: Added Llama-models python requirements
cglagovichTT 2c5ff7f
#13368: Fixup mesh_device when not passed FAKE_DEVICE
cglagovichTT 4e79091
Merge branch 'main' into llama32-vision
cglagovichTT 698ac12
#0: Merge branch 'main' into llama32-vision
cglagovichTT 7eef19b
#0: Merge branch 'main' into llama32-vision
cglagovichTT bc99440
#13368: Remove llama-specific packages from requirements-dev.txt
cglagovichTT d59f132
Merge branch 'main' into llama32-vision
cglagovichTT df3e545
#13368: Remove llama_models as submodule. Move its install to llama3 …
cglagovichTT 3807f76
#13368: Fix resource path in multimodal demos.
cglagovichTT 2a0eb87
Merge branch 'main' into llama32-vision
cglagovichTT 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
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
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,108 @@ | ||
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from pathlib import Path | ||
from typing import Optional | ||
from loguru import logger | ||
|
||
from PIL import Image as PIL_Image | ||
from termcolor import cprint | ||
|
||
from models.demos.llama3.demo.multimodal_demo_text import create_multimodal_model | ||
import models.demos.llama3.reference.llama_models.models.llama3.reference_impl.generation as llama_reference_generation | ||
|
||
from models.demos.llama3.reference.llama_models.models.llama3.api.datatypes import ImageMedia, UserMessage | ||
|
||
THIS_DIR = Path(__file__).parent.parent.resolve() / "reference/llama_models/models/scripts/" | ||
|
||
import torch | ||
import pytest | ||
import os | ||
import ttnn | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"mesh_device", | ||
[ | ||
{"N150": (1, 1), "N300": (1, 2), "T3K": (1, 8), "TG": (8, 4)}.get( | ||
os.environ.get("FAKE_DEVICE"), len(ttnn.get_device_ids()) | ||
) | ||
], | ||
indirect=True, | ||
) | ||
@pytest.mark.parametrize( | ||
"target", | ||
("tt", "cpu"), | ||
) | ||
@pytest.mark.parametrize( | ||
"warmup_iters", | ||
(0, 1), | ||
) | ||
def test_llama_multimodal_demo_chat( | ||
mesh_device, | ||
target, | ||
warmup_iters, | ||
temperature: float = 0.5, | ||
top_p: float = 0.9, | ||
max_seq_len: int = 512, | ||
max_batch_size: int = 4, | ||
max_gen_len: Optional[int] = 200, | ||
model_parallel_size: Optional[int] = None, | ||
): | ||
mesh_device.enable_program_cache() | ||
mesh_device.enable_async(True) | ||
ckpt_dir = os.environ["LLAMA_DIR"] | ||
tokenizer_path = str(Path(ckpt_dir) / "tokenizer.model") | ||
|
||
logger.info(f"Creating reference model from checkpoint in '{ckpt_dir}'") | ||
generator = llama_reference_generation.Llama.build( | ||
ckpt_dir, | ||
tokenizer_path=tokenizer_path, | ||
max_seq_len=max_seq_len, | ||
max_batch_size=max_batch_size, | ||
model_parallel_size=model_parallel_size, | ||
) | ||
|
||
if target == "tt": | ||
logger.info(f"Creating TT model on {len(mesh_device.get_devices())} devices") | ||
model = create_multimodal_model(generator.args, mesh_device) | ||
generator.model = model | ||
|
||
# image understanding | ||
dialogs = [] | ||
with open(THIS_DIR / "resources/dog.jpg", "rb") as f: | ||
img = PIL_Image.open(f).convert("RGB") | ||
|
||
dialogs = [ | ||
[ | ||
UserMessage( | ||
content=[ | ||
ImageMedia(image=img), | ||
"Describe this image in two sentences", | ||
], | ||
) | ||
], | ||
] | ||
# text only | ||
dialogs += [ | ||
[UserMessage(content="what is the recipe of mayonnaise in two sentences?")], | ||
] | ||
|
||
print(f"Running text completion on {target}") | ||
for _ in range(warmup_iters + 1): | ||
for dialog in dialogs: | ||
result = generator.chat_completion( | ||
dialog, | ||
max_gen_len=max_gen_len, | ||
temperature=temperature, | ||
top_p=top_p, | ||
) | ||
|
||
for msg in dialog: | ||
print(f"{msg.role.capitalize()}: {msg.content}\n") | ||
|
||
out_message = result.generation | ||
print(f"> {out_message.role.capitalize()}: {out_message.content}") | ||
for t in out_message.tool_calls: | ||
print(f" Tool call: {t.tool_name} ({t.arguments})") | ||
print("\n==================================\n") |
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
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
Oops, something went wrong.
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.
Given that this submodule has a method to install the dependencies, can you dynamically install it whenever these tests are run? We should not be including everything under the sun in this repo
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.
I resolved this by dynamically installing in t3k test scripts