Skip to content

Commit

Permalink
add vit patching tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqing-feng committed Jul 4, 2024
1 parent f8cd850 commit 316507f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/ipex/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,17 @@ def test_pipeline(self, model_arch):
self.assertEqual(pipe.device, model.device)
self.assertGreaterEqual(outputs[0]["score"], 0.0)
self.assertTrue(isinstance(outputs[0]["label"], str))

def test_patched_model(self):
ipex_model = IPEXModelForQuestionAnswering.from_pretrained(
"Jiqing/patched_tiny_random_vit_for_image_classification"
)
transformers_model = AutoModelForQuestionAnswering.from_pretrained("hf-internal-testing/tiny-random-vit")
preprocessor = AutoFeatureExtractor.from_pretrained("hf-internal-testing/tiny-random-vit")
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = preprocessor(images=image, return_tensors="pt")
with torch.no_grad():
transformers_outputs = transformers_model(**inputs)
outputs = ipex_model(**inputs)
self.assertTrue(torch.allclose(outputs.logits, transformers_outputs.logits, atol=1e-4))

0 comments on commit 316507f

Please sign in to comment.