From 3c80ae5ff09473fc026c8e0871c5d85bd391b695 Mon Sep 17 00:00:00 2001 From: "Liu, Kaixuan" Date: Fri, 3 Apr 2026 07:41:56 +0000 Subject: [PATCH 1/2] musicflamingo: add test support for Intel XPU device Signed-off-by: Liu, Kaixuan --- .../musicflamingo/expected_results_batched.json | 11 ++++++++++- .../musicflamingo/test_modeling_musicflamingo.py | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/musicflamingo/expected_results_batched.json b/tests/fixtures/musicflamingo/expected_results_batched.json index 267791212093..589035713650 100644 --- a/tests/fixtures/musicflamingo/expected_results_batched.json +++ b/tests/fixtures/musicflamingo/expected_results_batched.json @@ -1 +1,10 @@ -{"transcriptions": ["This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on the skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the"], "token_ids": [[1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 279, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279]]} \ No newline at end of file +{ + "cuda": { + "transcriptions": ["This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on the skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the"], + "token_ids": [[1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 279, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279]] + }, + "xpu": { + "transcriptions": ["This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on red skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the"], + "token_ids": [[1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 2518, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279]] + } +} \ No newline at end of file diff --git a/tests/models/musicflamingo/test_modeling_musicflamingo.py b/tests/models/musicflamingo/test_modeling_musicflamingo.py index 05954aba61af..21c43ce6803a 100644 --- a/tests/models/musicflamingo/test_modeling_musicflamingo.py +++ b/tests/models/musicflamingo/test_modeling_musicflamingo.py @@ -29,7 +29,9 @@ is_torch_available, ) from transformers.testing_utils import ( + Expectations, cleanup, + require_deterministic_for_xpu, require_torch, slow, torch_device, @@ -345,6 +347,7 @@ def test_fixture_single_matches(self): txt = self.processor.batch_decode(gen_ids, skip_special_tokens=True) self.assertListEqual(txt, exp_txt) + @require_deterministic_for_xpu @slow def test_fixture_batched_matches(self): """ @@ -353,8 +356,16 @@ def test_fixture_batched_matches(self): path = Path(__file__).parent.parent.parent / "fixtures/musicflamingo/expected_results_batched.json" with open(path, "r", encoding="utf-8") as f: raw = json.load(f) - exp_ids = torch.tensor(raw["token_ids"]) - exp_txt = raw["transcriptions"] + + exp_ids = Expectations( + { + ("cuda", None): torch.tensor(raw["cuda"]["token_ids"]), + ("xpu", None): torch.tensor(raw["xpu"]["token_ids"]), + } + ).get_expectation() + exp_txt = Expectations( + {("cuda", None): raw["cuda"]["transcriptions"], ("xpu", None): raw["xpu"]["transcriptions"]} + ).get_expectation() conversations = [ [ From bfac946d4f34199e737c3e3391aa5e49fea1fcfe Mon Sep 17 00:00:00 2001 From: "Liu, Kaixuan" Date: Fri, 10 Apr 2026 08:09:40 +0000 Subject: [PATCH 2/2] update Signed-off-by: Liu, Kaixuan --- .../expected_results_batched.json | 10 ------- .../test_modeling_musicflamingo.py | 27 ++++++++++++++----- 2 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 tests/fixtures/musicflamingo/expected_results_batched.json diff --git a/tests/fixtures/musicflamingo/expected_results_batched.json b/tests/fixtures/musicflamingo/expected_results_batched.json deleted file mode 100644 index 589035713650..000000000000 --- a/tests/fixtures/musicflamingo/expected_results_batched.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "cuda": { - "transcriptions": ["This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on the skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the"], - "token_ids": [[1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 279, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279]] - }, - "xpu": { - "transcriptions": ["This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on red skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the"], - "token_ids": [[1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 2518, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279]] - } -} \ No newline at end of file diff --git a/tests/models/musicflamingo/test_modeling_musicflamingo.py b/tests/models/musicflamingo/test_modeling_musicflamingo.py index 21c43ce6803a..8c3b0ce549c8 100644 --- a/tests/models/musicflamingo/test_modeling_musicflamingo.py +++ b/tests/models/musicflamingo/test_modeling_musicflamingo.py @@ -353,19 +353,32 @@ def test_fixture_batched_matches(self): """ reproducer (creates JSON directly in repo): https://gist.github.com/ebezzam/a3226a0ba25e51be84a4808a79b59257#file-reproducer_hf-py """ - path = Path(__file__).parent.parent.parent / "fixtures/musicflamingo/expected_results_batched.json" - with open(path, "r", encoding="utf-8") as f: - raw = json.load(f) - + # fmt: off exp_ids = Expectations( { - ("cuda", None): torch.tensor(raw["cuda"]["token_ids"]), - ("xpu", None): torch.tensor(raw["xpu"]["token_ids"]), + ("cuda", None): torch.tensor([ + [1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], + [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 279, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279], + ]), + ("xpu", None): torch.tensor([ + [1986, 3754, 374, 458, 94509, 19461, 98875, 55964, 3528, 1163, 681, 55964, 11598, 55564, 429, 57843, 279, 9842, 3040, 55964, 263, 55964, 1782, 55964, 30449, 27235, 315, 11416, 19461, 98875, 448, 279, 68897, 11, 10581, 52760, 42898, 975, 14260, 315, 6481, 97431, 55964, 13573, 2591, 2420, 13, 220, 576, 8090], + [334, 68043, 220, 16, 1019, 33648, 9287, 88828, 304, 51454, 11, 12711, 28347, 261, 304, 279, 3054, 11, 24353, 20783, 18707, 30789, 11, 22502, 4614, 389, 2518, 49293, 271, 334, 68043, 220, 17, 1019, 26843, 2367, 98091, 389, 279, 39612, 11, 304, 17172, 582, 6950, 11, 14697, 41315, 311, 279], + ]), } ).get_expectation() exp_txt = Expectations( - {("cuda", None): raw["cuda"]["transcriptions"], ("xpu", None): raw["xpu"]["transcriptions"]} + { + ("cuda", None): [ + "This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", + "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on the skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the", + ], + ("xpu", None): [ + "This track is an uplifting Eurodance‑style Trance‑Pop anthem that blends the driving four‑on‑the‑floor pulse of classic Eurodance with the soaring, melodic synth work typical of modern trance‑infused pop. The duration", + "**Verse 1**\nMidnight cravings in bloom, lights flicker in the room, pepperoni dreams arise, pizza party on red skies\n\n**Verse 2**\nCheese melts on the crust, in flavor we trust, boxes stacked to the", + ], + } ).get_expectation() + # fmt: on conversations = [ [