Skip to content

Commit

Permalink
Add test for deepseek_vl
Browse files Browse the repository at this point in the history
  • Loading branch information
meenakshiramanathan1 committed Jan 30, 2025
1 parent d407988 commit 07bb2f6
Show file tree
Hide file tree
Showing 13 changed files with 2,891 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/proj_sw/user_dev/mramanathan/lab72_jan29_forge/tt-forge-fe/forge/test/models/pytorch/multimodal/deepseek/image/training_pipelines.jpg filter=lfs diff=lfs merge=lfs -text
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions forge/test/models/pytorch/multimodal/deepseek/test_deepseek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# SPDX-FileCopyrightText: © 2024 Tenstorrent AI ULC

# SPDX-License-Identifier: Apache-2.0
import pytest
import torch
from transformers import AutoModelForCausalLM

import forge
from forge.verify.verify import verify

from test.models.pytorch.text.deepseek.utils.io import load_pil_images

Check failure on line 11 in forge/test/models/pytorch/multimodal/deepseek/test_deepseek.py

View workflow job for this annotation

GitHub Actions / TT-Forge-FE Tests

test_deepseek.forge.test.models.pytorch.multimodal.deepseek.test_deepseek

collection failure
Raw output
ImportError while importing test module '/__w/tt-forge-fe/tt-forge-fe/forge/test/models/pytorch/multimodal/deepseek/test_deepseek.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/ttforge-toolchain/venv/lib/python3.10/site-packages/_pytest/python.py:578: in _importtestmodule
    mod = import_path(self.fspath, mode=importmode)
/opt/ttforge-toolchain/venv/lib/python3.10/site-packages/_pytest/pathlib.py:524: in import_path
    importlib.import_module(module_name)
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
/opt/ttforge-toolchain/venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:170: in exec_module
    exec(co, module.__dict__)
forge/test/models/pytorch/multimodal/deepseek/test_deepseek.py:11: in <module>
    from test.models.pytorch.text.deepseek.utils.io import load_pil_images
E   ModuleNotFoundError: No module named 'test.models.pytorch.text.deepseek'
from test.models.pytorch.text.deepseek.utils.models import (
MultiModalityCausalLM,
VLChatProcessor,
)
from test.models.utils import Framework, Source, Task, build_module_name


def generate_model_deepseek_vl_pytorch(variant):
model_path = variant
vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path)
tokenizer = vl_chat_processor.tokenizer

vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
vl_gpt = vl_gpt.to(torch.bfloat16).eval()

class Wrapper(torch.nn.Module):
def __init__(self, model):
super().__init__()
self.model = model
self.eos_token_id = tokenizer.eos_token_id
self.bos_token_id = tokenizer.bos_token_id
self.pad_token_id = tokenizer.pad_token_id

def forward(self, inputs_embeds, attention_mask):
return self.model.language_model.generate(
inputs_embeds=inputs_embeds,
attention_mask=attention_mask,
pad_token_id=self.pad_token_id,
bos_token_id=self.bos_token_id,
eos_token_id=self.eos_token_id,
max_new_tokens=512,
do_sample=False,
use_cache=True,
)

framework_model = Wrapper(vl_gpt)

return framework_model, vl_chat_processor, tokenizer


@pytest.mark.nightly
@pytest.mark.parametrize("variant", ["deepseek-ai/deepseek-vl-1.3b-base", "deepseek-ai/deepseek-vl-1.3b-chat"])
def test_deepseek_vl_pytorch(record_forge_property, variant):

# Build Module Name
module_name = build_module_name(
framework=Framework.PYTORCH, model="deepseek", variant=variant, task=Task.CAUSAL_LM, source=Source.HUGGINGFACE
)

# Record Forge Property
record_forge_property("model_name", module_name)

# Get the model, processor, and tokenizer
vl_gpt, vl_chat_processor, tokenizer = generate_model_deepseek_vl_pytorch(variant)

# Single image conversation example
conversation = [
{
"role": "User",
"content": "<image_placeholder>Describe each stage of this image.",
"images": ["forge/test/models/pytorch/text/deepseek/image/training_pipelines.jpg"],
},
{"role": "Assistant", "content": ""},
]

# Load images and prepare for inputs
pil_images = load_pil_images(conversation)
prepare_inputs = vl_chat_processor(conversations=conversation, images=pil_images, force_batchify=True).to(
vl_gpt.device
)

# Run image encoder to get the image embeddings
inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
attention_mask = prepare_inputs.attention_mask
inputs = [inputs_embeds, attention_mask]

# Forge compile framework model
compiled_model = forge.compile(framework_model, sample_inputs=inputs, module_name=module_name)

# Model Verification
verify(inputs, framework_model, compiled_model)
Loading

0 comments on commit 07bb2f6

Please sign in to comment.