@@ -144,6 +144,12 @@ static void RunQMoETest(const std::vector<float>& input, const std::vector<float
144144 // Test CPU execution provider (always available)
145145 // Skip CPU test if FC3 weights are provided since CPU doesn't support FC3
146146 if (fc3_experts_weights.empty ()) {
147+ // Ensure CPU EP is available before running CPU tests
148+ auto cpu_ep = DefaultCpuExecutionProvider ();
149+ if (!cpu_ep) {
150+ return ; // Skip CPU test if CPU EP is not available
151+ }
152+
147153 OpTester cpu_tester (" QMoE" , 1 , onnxruntime::kMSDomain );
148154 cpu_tester.AddAttribute <int64_t >(" k" , static_cast <int64_t >(top_k));
149155 cpu_tester.AddAttribute <std::string>(" activation_type" , activation_type);
@@ -1323,6 +1329,13 @@ TEST(MoETest, QMoETest_Mixtral_Int4) {
13231329
13241330// CPU-specific QMoE tests
13251331TEST (MoETest, QMoETest_CPU_Int4_MLAS) {
1332+ #ifdef USE_MLAS
1333+ // Skip this test if we're not testing CPU execution provider
1334+ auto cpu_ep = DefaultCpuExecutionProvider ();
1335+ if (!cpu_ep) {
1336+ GTEST_SKIP () << " CPU execution provider not available" ;
1337+ }
1338+
13261339 int num_rows = 2 ;
13271340 int num_experts = 2 ;
13281341 int hidden_size = 32 ;
@@ -1387,9 +1400,19 @@ TEST(MoETest, QMoETest_CPU_Int4_MLAS) {
13871400 std::vector<std::unique_ptr<IExecutionProvider>> cpu_execution_providers;
13881401 cpu_execution_providers.push_back (DefaultCpuExecutionProvider ());
13891402 cpu_tester.Run (OpTester::ExpectResult::kExpectSuccess , " " , {}, nullptr , &cpu_execution_providers);
1403+ #else
1404+ GTEST_SKIP () << " Skipping CPU QMoE test" ;
1405+ #endif
13901406}
13911407
13921408TEST (MoETest, QMoETest_CPU_Int8_MLAS) {
1409+ #ifdef USE_MLAS
1410+ // Skip this test if we're not testing CPU execution provider
1411+ auto cpu_ep = DefaultCpuExecutionProvider ();
1412+ if (!cpu_ep) {
1413+ GTEST_SKIP () << " CPU execution provider not available" ;
1414+ }
1415+
13931416 // Test CPU implementation with 8-bit quantization - CPU ONLY
13941417 int num_rows = 1 ;
13951418 int num_experts = 2 ;
@@ -1446,9 +1469,19 @@ TEST(MoETest, QMoETest_CPU_Int8_MLAS) {
14461469 std::vector<std::unique_ptr<IExecutionProvider>> cpu_execution_providers;
14471470 cpu_execution_providers.push_back (DefaultCpuExecutionProvider ());
14481471 cpu_tester.Run (OpTester::ExpectResult::kExpectSuccess , " " , {}, nullptr , &cpu_execution_providers);
1472+ #else
1473+ GTEST_SKIP () << " Skipping CPU QMoE test" ;
1474+ #endif
14491475}
14501476
14511477TEST (MoETest, QMoETest_CPU_FC3_Error) {
1478+ #ifdef USE_MLAS
1479+ // Skip this test if we're not testing CPU execution provider
1480+ auto cpu_ep = DefaultCpuExecutionProvider ();
1481+ if (!cpu_ep) {
1482+ GTEST_SKIP () << " CPU execution provider not available" ;
1483+ }
1484+
14521485 // Test that CPU throws error when FC3 gating is provided - CPU ONLY
14531486 int num_rows = 1 ;
14541487 int num_experts = 2 ;
@@ -1506,9 +1539,19 @@ TEST(MoETest, QMoETest_CPU_FC3_Error) {
15061539
15071540 // Expect this to fail with FC3 not implemented error
15081541 cpu_tester.Run (OpTester::ExpectResult::kExpectFailure , " FC3 gating is not yet implemented" , {}, nullptr , &cpu_execution_providers);
1542+ #else
1543+ GTEST_SKIP () << " Skipping CPU QMoE test" ;
1544+ #endif
15091545}
15101546
15111547TEST (MoETest, QMoETest_CPU_SwiGLU_Int4) {
1548+ #ifdef USE_MLAS
1549+ // Skip this test if we're not testing CPU execution provider
1550+ auto cpu_ep = DefaultCpuExecutionProvider ();
1551+ if (!cpu_ep) {
1552+ GTEST_SKIP () << " CPU execution provider not available" ;
1553+ }
1554+
15121555 // Test CPU implementation with 4-bit quantization and SwiGLU activation
15131556 int num_rows = 2 ;
15141557 int num_experts = 2 ;
@@ -1573,9 +1616,18 @@ TEST(MoETest, QMoETest_CPU_SwiGLU_Int4) {
15731616 std::vector<std::unique_ptr<IExecutionProvider>> cpu_execution_providers;
15741617 cpu_execution_providers.push_back (DefaultCpuExecutionProvider ());
15751618 cpu_tester.Run (OpTester::ExpectResult::kExpectSuccess , " " , {}, nullptr , &cpu_execution_providers);
1619+ #else
1620+ GTEST_SKIP () << " Skipping CPU QMoE test" ;
1621+ #endif
15761622}
15771623
15781624TEST (MoETest, QMoETest_CPU_SwiGLU_Int8) {
1625+ #ifdef USE_MLAS
1626+ // Skip this test if we're not testing CPU execution provider
1627+ auto cpu_ep = DefaultCpuExecutionProvider ();
1628+ if (!cpu_ep) {
1629+ GTEST_SKIP () << " CPU execution provider not available" ;
1630+ }
15791631 // Test CPU implementation with 8-bit quantization and SwiGLU activation
15801632 int num_rows = 1 ;
15811633 int num_experts = 2 ;
@@ -1633,6 +1685,9 @@ TEST(MoETest, QMoETest_CPU_SwiGLU_Int8) {
16331685 std::vector<std::unique_ptr<IExecutionProvider>> cpu_execution_providers;
16341686 cpu_execution_providers.push_back (DefaultCpuExecutionProvider ());
16351687 cpu_tester.Run (OpTester::ExpectResult::kExpectSuccess , " " , {}, nullptr , &cpu_execution_providers);
1688+ #else
1689+ GTEST_SKIP () << " Skipping CPU QMoE test" ;
1690+ #endif
16361691}
16371692
16381693#endif
0 commit comments