Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions tests/models/deepseek_vl_hybrid/test_modeling_deepseek_vl_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_memory_cleanup_mixin import MemoryCleanupMixin
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin
from ...test_processing_common import url_to_local_path
Expand Down Expand Up @@ -238,15 +239,13 @@ def test_sdpa_can_dispatch_on_flash(self):
@require_torch
@require_torch_accelerator
@slow
class DeepseekVLHybridIntegrationTest(unittest.TestCase):
class DeepseekVLHybridIntegrationTest(MemoryCleanupMixin, unittest.TestCase):
def setUp(self):
super().setUp()
self.model_id = "deepseek-community/deepseek-vl-7b-chat"

def test_model_text_generation(self):
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(
self.model_id, dtype="auto", device_map="auto"
)
model.to(torch_device)
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(self.model_id, dtype="auto").to(torch_device)
model.eval()
processor = AutoProcessor.from_pretrained(self.model_id)

Expand Down Expand Up @@ -279,10 +278,7 @@ def test_model_text_generation(self):
)

def test_model_text_generation_batched(self):
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(
self.model_id, dtype="auto", device_map="auto"
)
model.to(torch_device)
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(self.model_id, dtype="auto").to(torch_device)
model.eval()
processor = AutoProcessor.from_pretrained(self.model_id)

Expand Down Expand Up @@ -317,12 +313,18 @@ def test_model_text_generation_batched(self):
],
]
EXPECTED_TEXT = [
"You are a helpful language and vision assistant. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language.\n\nUser: Describe this image.\n\nAssistant:\nThe image depicts a fluffy, light brown animal with a white face and black markings around its eyes", # fmt: skip
"You are a helpful language and vision assistant. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language.\n\nUser: Describe this image.\n\nAssistant:The image depicts a fluffy, light brown animal with a white face and black markings on its face and", # fmt: skip
"You are a helpful language and vision assistant. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language.\n\nUser: What animal do you see in the image?\n\nAssistant:I see a large, furry animal that appears to be a type of bear.The ", # fmt: skip
]

inputs = processor.apply_chat_template(
messages, add_generation_prompt=True, tokenize=True, padding=True, return_dict=True, return_tensors="pt"
messages,
add_generation_prompt=True,
tokenize=True,
padding=True,
return_dict=True,
return_tensors="pt",
padding_side="left",
)
inputs = inputs.to(model.device, dtype=model.dtype)
output = model.generate(**inputs, max_new_tokens=20, do_sample=False)
Expand All @@ -331,10 +333,7 @@ def test_model_text_generation_batched(self):
self.assertEqual(EXPECTED_TEXT, text)

def test_model_text_generation_with_multi_image(self):
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(
self.model_id, dtype="auto", device_map="auto"
)
model.to(torch_device)
model = DeepseekVLHybridForConditionalGeneration.from_pretrained(self.model_id, dtype="auto").to(torch_device)
model.eval()
processor = AutoProcessor.from_pretrained(self.model_id)

Expand Down
Loading