Load and save video-processor from separate folder (#33562)
* load and save from video-processor folder * Update src/transformers/models/llava_onevision/processing_llava_onevision.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> --------- Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
5af7d41e49
commit
e40bb4845e
@@ -58,15 +58,16 @@ class LlavaOnevisionProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
||||
return AutoProcessor.from_pretrained(self.tmpdirname, **kwargs).video_processor
|
||||
|
||||
def prepare_processor_dict(self):
|
||||
return {"chat_template": "dummy_template"}
|
||||
return {"chat_template": "dummy_template", "num_image_tokens": 6, "vision_feature_select_strategy": "default"}
|
||||
|
||||
@unittest.skip(
|
||||
"Skip because the model has no processor kwargs except for chat template and"
|
||||
"chat template is saved as a separate file. Stop skipping this test when the processor"
|
||||
"has new kwargs saved in config file."
|
||||
)
|
||||
def test_processor_to_json_string(self):
|
||||
pass
|
||||
processor = self.get_processor()
|
||||
obj = json.loads(processor.to_json_string())
|
||||
for key, value in self.prepare_processor_dict().items():
|
||||
# chat_tempalate are tested as a separate test because they are saved in separate files
|
||||
if key != "chat_template":
|
||||
self.assertEqual(obj[key], value)
|
||||
self.assertEqual(getattr(processor, key, None), value)
|
||||
|
||||
# Copied from tests.models.llava.test_processor_llava.LlavaProcessorTest.test_chat_template_is_saved
|
||||
def test_chat_template_is_saved(self):
|
||||
@@ -191,7 +192,7 @@ class LlavaOnevisionProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
||||
max_length=76,
|
||||
)
|
||||
self.assertEqual(inputs["pixel_values"].shape[3], 214)
|
||||
self.assertEqual(len(inputs["input_ids"][0]), 5)
|
||||
self.assertEqual(len(inputs["input_ids"][0]), 4)
|
||||
|
||||
@require_torch
|
||||
@require_vision
|
||||
@@ -282,7 +283,7 @@ class LlavaOnevisionProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
||||
image_input = self.prepare_image_inputs()
|
||||
|
||||
inputs = processor(text=input_str, images=image_input, return_tensors="pt", max_length=112)
|
||||
self.assertEqual(len(inputs["input_ids"][0]), 112)
|
||||
self.assertEqual(len(inputs["input_ids"][0]), 2)
|
||||
|
||||
@require_vision
|
||||
@require_torch
|
||||
@@ -299,4 +300,4 @@ class LlavaOnevisionProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
||||
image_input = self.prepare_image_inputs()
|
||||
|
||||
inputs = processor(text=input_str, images=image_input, return_tensors="pt")
|
||||
self.assertEqual(len(inputs["input_ids"][0]), 117)
|
||||
self.assertEqual(len(inputs["input_ids"][0]), 2)
|
||||
|
||||
@@ -112,6 +112,14 @@ class ProcessorTesterMixin:
|
||||
|
||||
self.assertEqual(processor_second.to_dict(), processor_first.to_dict())
|
||||
|
||||
for attribute in processor_first.attributes:
|
||||
attribute_first = getattr(processor_first, attribute)
|
||||
attribute_second = getattr(processor_second, attribute)
|
||||
|
||||
# tokenizer repr contains model-path from where we loaded
|
||||
if "tokenizer" not in attribute:
|
||||
self.assertEqual(repr(attribute_first), repr(attribute_second))
|
||||
|
||||
# These kwargs-related tests ensure that processors are correctly instantiated.
|
||||
# they need to be applied only if an image_processor exists.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user