Skip to content

Commit

Permalink
add prepare inputs test
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaizzy committed Jan 3, 2025
1 parent 2465445 commit bd55658
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions mlx_vlm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from mlx_vlm.utils import (
get_class_predicate,
prepare_inputs,
quantize_model,
sanitize_weights,
update_module_configs,
Expand Down Expand Up @@ -145,3 +146,46 @@ def __init__(self, shape):

# Check config is updated correctly
assert updated_config["vision_config"]["skip_vision"] is True


def test_prepare_inputs():
"""Test prepare_inputs function."""

# Mock processor
class MockProcessor:
def __init__(self):
self.tokenizer = type(
"DummyTokenizer", (), {"pad_token": None, "eos_token": "[EOS]"}
)()

def __call__(self, text=None, images=None, padding=None, return_tensors=None):
return {
"input_ids": mx.array([1, 2, 3]),
"pixel_values": mx.array([4, 5, 6]),
"attention_mask": mx.array([7, 8, 9]),
}

processor = MockProcessor()

# Test text-only input
inputs = prepare_inputs(
processor, prompts="test", images=None, image_token_index=None
)
assert "input_ids" in inputs
assert mx.array_equal(inputs["input_ids"], mx.array([1, 2, 3]))

# Test image-only input
image = mx.zeros((3, 224, 224))
inputs = prepare_inputs(
processor, prompts=None, images=image, image_token_index=None
)
assert "input_ids" in inputs
assert mx.array_equal(inputs["input_ids"], mx.array([1, 2, 3]))

# Test both text and image
image = mx.zeros((3, 224, 224))
inputs = prepare_inputs(
processor, prompts="test", images=image, image_token_index=None
)
assert "input_ids" in inputs
assert mx.array_equal(inputs["input_ids"], mx.array([1, 2, 3]))

0 comments on commit bd55658

Please sign in to comment.