Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] use internal properties for moe (#36441)

River Lidbc78921dc8e
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
index 2e7151f60ec..0d815b4283f 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
@@ -168,6 +168,10 @@ static constexpr Property<bool, ov::PropertyMutability::RW> disable_fc_swiglu_fu
static constexpr Property<bool, ov::PropertyMutability::RW> disable_gated_mlp_fusion{"GPU_DISABLE_GATED_MLP_FUSION"};
static constexpr Property<bool, ov::PropertyMutability::RW> disable_fake_alignment{"GPU_DISABLE_FAKE_ALIGNMENT"};
static constexpr Property<bool, ov::PropertyMutability::RW> disable_moe_opt{"GPU_DISABLE_MOE_OPT"};
+static constexpr Property<bool, ov::PropertyMutability::RW> moe_use_micro_gemm_prefill{"GPU_MOE_USE_MICRO_GEMM_PREFILL"};
+static constexpr Property<bool, ov::PropertyMutability::RW> moe_use_gpu_mask_gen_prefill{"GPU_MOE_USE_GPU_MASK_GEN_PREFILL"};
+static constexpr Property<bool, ov::PropertyMutability::RW> moe_use_grouped_gemm_prefill{"GPU_MOE_USE_GROUPED_GEMM_PREFILL"};
+static constexpr Property<size_t, ov::PropertyMutability::RW> moe_batched_gemv_threshold{"GPU_MOE_BATCHED_GEMV_THRESHOLD"};
static constexpr Property<bool, ov::PropertyMutability::RW> disable_runtime_skip_reorder{"GPU_DISABLE_RUNTIME_SKIP_REORDER"};
static constexpr Property<bool, ov::PropertyMutability::RW> asym_dynamic_quantization{"GPU_ASYM_DYNAMIC_QUANTIZATION"};
static constexpr Property<size_t, ov::PropertyMutability::RW> dynamic_quantization_threshold{"GPU_DYNAMIC_QUANTIZATION_THRESHOLD"};
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
index 757a8a25d6f..931faecf4d1 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
@@ -62,6 +62,10 @@ OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, dynamic_quantization_precompute
OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, allow_bypass_xattn, true, "Allow bypass xattn execution if threshold >= 1.0.")
OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, weightless_attr, nullptr, "Used to configure ov::WeightlessCacheAttribute for constants that are not loaded from a .bin file. This typically applies to non-IR inputs (e.g., ORT)")
OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, pa_mixed_route_mode, std::string("split"), "Mixed route mode for CM paged attention. Supported values: multi, split")
+OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, moe_use_micro_gemm_prefill, true, "MoE 3GEMM: use micro-kernel GEMM for the prefill path. Requires Xe2+ and 4-bit weights; overridden when grouped GEMM is enabled")
+OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, moe_use_gpu_mask_gen_prefill, false, "MoE 3GEMM: generate routing masks on GPU instead of CPU for the micro-kernel prefill path")
+OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, moe_use_grouped_gemm_prefill, true, "MoE 3GEMM: use a single OneDNN grouped matmul per GEMM layer for the prefill path. Takes priority over micro-kernel GEMM")
+OV_CONFIG_RELEASE_INTERNAL_OPTION(ov::intel_gpu, moe_batched_gemv_threshold, 32, "MoE 3-GEMM: token count (<=) that selects the batched GEMV decode path instead of the prefill path")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, help, false, "Print help message for all config options")
OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, verbose, 0, "Enable logging for debugging purposes. The higher value the more verbose output. 0 - Disabled, 4 - Maximum verbosity")
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/moe/moe_3gemm_swiglu_opt.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/moe/moe_3gemm_swiglu_opt.cpp
index 86a3298c1a4..57f87d8075d 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/moe/moe_3gemm_swiglu_opt.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/moe/moe_3gemm_swiglu_opt.cpp
@@ -648,34 +648,20 @@ public:
}
init(node.as<moe_3gemm_fused_compressed>().get_primitive());
- auto use_micro_gemm_prefill_str = std::getenv("MOE_USE_MICRO_GEMM_PREFILL");
- if (use_micro_gemm_prefill_str) {
- GPU_DEBUG_TRACE_DETAIL << "MOE_USE_MICRO_GEMM_PREFILL = " << use_micro_gemm_prefill_str << std::endl;
- use_micro_gemm_prefill = std::stoi(use_micro_gemm_prefill_str);
- } else {
- // micro_gemm is better than gemm, default to use it
- use_micro_gemm_prefill = true;
- }
+ const auto& config = params.get_program().get_config();
- auto use_gpu_mask_gen_prefill_str = std::getenv("MOE_USE_GPU_MASK_PREFILL");
- if (use_gpu_mask_gen_prefill_str) {
- GPU_DEBUG_TRACE_DETAIL << "MOE_USE_GPU_MASK_PREFILL = " << use_gpu_mask_gen_prefill_str << std::endl;
- use_gpu_mask_gen_prefill = std::stoi(use_gpu_mask_gen_prefill_str);
- } else {
- // gpu mask gen kernel performace is worse than cpu mask gen, default is off
- use_gpu_mask_gen_prefill = false;
- }
+ // micro_gemm is better than gemm, default to use it
+ use_micro_gemm_prefill = config.get_moe_use_micro_gemm_prefill();
+ // gpu mask gen kernel performance is worse than cpu mask gen, default is off
+ use_gpu_mask_gen_prefill = config.get_moe_use_gpu_mask_gen_prefill();
auto& engine = params.prog->get_engine();
const auto& info = engine.get_device_info();
if (info.arch < gpu_arch::xe2) {
use_micro_gemm_prefill = false;
- GPU_DEBUG_TRACE_DETAIL << "[DEBUG] moe_3gemm_swiglu_opt_impl(): use_micro_gemm_prefill=" << use_micro_gemm_prefill
- << ", arch=" << static_cast<int>(info.arch) << std::endl;
- } else {
- GPU_DEBUG_TRACE_DETAIL << "[DEBUG] moe_3gemm_swiglu_opt_impl(): use_micro_gemm_prefill=" << use_micro_gemm_prefill
- << ", arch=" << static_cast<int>(info.arch) << std::endl;
}
+ GPU_DEBUG_TRACE_DETAIL << "[DEBUG] moe_3gemm_swiglu_opt_impl(): use_micro_gemm_prefill=" << use_micro_gemm_prefill
+ << ", arch=" << static_cast<int>(info.arch) << std::endl;
// Remove this limitation once micro_gemm kernels has supported i8/u8 weights.
const auto& weight_dt = params.get_input_layout(static_cast<size_t>(MOE3GemmInputIndex::WEIGHT_0)).data_type;
@@ -685,13 +671,7 @@ public:
// grouped_gemm path: single OneDNN grouped matmul per GEMM layer (all experts at once).
// micro_gemm takes priority; grouped_gemm falls back to onednn loop by default.
- auto use_grouped_gemm_prefill_str = std::getenv("MOE_USE_GROUPED_GEMM_PREFILL");
- if (use_grouped_gemm_prefill_str) {
- GPU_DEBUG_TRACE_DETAIL << "MOE_USE_GROUPED_GEMM_PREFILL = " << use_grouped_gemm_prefill_str << std::endl;
- use_grouped_gemm_prefill = std::stoi(use_grouped_gemm_prefill_str) != 0;
- } else {
- use_grouped_gemm_prefill = true;
- }
+ use_grouped_gemm_prefill = config.get_moe_use_grouped_gemm_prefill();
// grouped_gemm supersedes micro_gemm
if (use_grouped_gemm_prefill) {
use_micro_gemm_prefill = false;
@@ -699,14 +679,11 @@ public:
GPU_DEBUG_TRACE_DETAIL << "[DEBUG] moe_3gemm_swiglu_opt_impl(): use_grouped_gemm_prefill=" << use_grouped_gemm_prefill << std::endl;
- auto batched_gemv_threshold_str = std::getenv("MOE_BATCHED_GEMV_THRESHOLD");
- if (batched_gemv_threshold_str) {
- batched_gemv_threshold = std::stoul(batched_gemv_threshold_str);
- if (batched_gemv_threshold <= 0) {
- batched_gemv_threshold = 1;
- }
- GPU_DEBUG_TRACE_DETAIL << "MOE_BATCHED_GEMV_THRESHOLD = " << batched_gemv_threshold << std::endl;
+ batched_gemv_threshold = config.get_moe_batched_gemv_threshold();
+ if (batched_gemv_threshold == 0) {
+ batched_gemv_threshold = 1;
}
+ GPU_DEBUG_TRACE_DETAIL << "[DEBUG] moe_3gemm_swiglu_opt_impl(): batched_gemv_threshold=" << batched_gemv_threshold << std::endl;
// Don't change the order of stages
add_stage(gather, params);