Skip to content

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

[GPU] fix MOE OTD low performance in dGPU (#37800)

Zaixing Wang0e5f0df2215d
diff --git a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
index ed1e33dd5a6..e6b04cd76ef 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp
@@ -120,7 +120,13 @@ static void create_data(ProgramBuilder& p, const ov::Shape& const_shape, const s
p.primitive_ids[initialconstPrimID] = constPrimID;
p.profiling_ids.push_back(initialconstPrimID);
} else {
- auto partial_upload = try_prepare_partial_upload(p, op, const_shape, out_dtype, constFormat, constLayout);
+ auto partial_upload = try_prepare_partial_upload(p.get_engine(),
+ p.get_config(),
+ op,
+ const_shape,
+ out_dtype,
+ constFormat,
+ constLayout);
cldnn::memory::ptr mem = nullptr;
diff --git a/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.cpp
index 3e8bc46bfb2..39275caf4f4 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.cpp
@@ -40,7 +40,8 @@ PartialUploadLogState& get_partial_upload_log_state() {
return state;
}
-PartialUploadDesc try_prepare_partial_upload(ProgramBuilder& p,
+PartialUploadDesc try_prepare_partial_upload(cldnn::engine& engine,
+ const ExecutionConfig& config,
const std::shared_ptr<ov::op::v0::Constant>& op,
const ov::Shape& const_shape,
cldnn::data_types out_dtype,
@@ -48,7 +49,7 @@ PartialUploadDesc try_prepare_partial_upload(ProgramBuilder& p,
const cldnn::layout& const_layout) {
PartialUploadDesc desc;
- const size_t otd_ratio = p.get_config().get_offload_ratio();
+ const size_t otd_ratio = config.get_offload_ratio();
// Only routed expert weights are partially uploaded; shared experts stay fully resident.
// ratio=0 (all resident) or ratio=100 (all on disk, invalid) → no partial upload.
const bool partial_moe_const_upload = otd_ratio > 0 && otd_ratio < 100 && get_moe_constant_role(op) == MoEConstantRole::RoutedExpert;
@@ -64,19 +65,20 @@ PartialUploadDesc try_prepare_partial_upload(ProgramBuilder& p,
desc.upload_shape[0] = std::min<size_t>(const_shape[0], resident_expert_num);
auto upload_layout = cldnn::layout(desc.upload_shape, out_dtype, const_format);
- auto upload_mem = p.get_engine().allocate_memory(upload_layout, false);
+ auto upload_mem = engine.allocate_memory(upload_layout, engine.get_preferred_memory_allocation_type(), false);
// Reinterpret the smaller physical allocation as the full constant layout so the
// graph sees the expected shape/layout. This is safe because:
// 1. constant.cpp marks this data node with skip_device_transfer=true (partial_upload.enabled),
// so no host→device memcpy of the full size occurs.
// 2. At runtime, OTD loads on-demand into the first `resident_expert_num` slots only.
- // 3. Model cache serialization uses weightless caching (bin_offset metadata) for these
- // constants — it never reads the buffer contents via mem->buffer_ptr(). OTD requires
- // weights_path to be set, which enables weightless caching for all data nodes.
+ // 3. Weightless cache serialization uses bin_offset metadata for these constants and
+ // never reads the buffer contents via mem->buffer_ptr(). OTD provides weights_path,
+ // but does not enable weightless caching itself.
+ // TODO: Support serialization of OTD partial allocations without weightless caching.
OPENVINO_ASSERT(upload_layout.bytes_count() <= const_layout.bytes_count(),
"Partial upload layout (", upload_layout.bytes_count(),
" bytes) exceeds full constant layout (", const_layout.bytes_count(), " bytes)");
- desc.memory = p.get_engine().reinterpret_buffer(*upload_mem, const_layout);
+ desc.memory = engine.reinterpret_buffer(*upload_mem, const_layout);
desc.upload_bytes = upload_layout.bytes_count();
get_partial_upload_log_state().log(op->get_friendly_name(),
diff --git a/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.hpp b/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.hpp
index 8946b16953e..29b5811e3b1 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.hpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/moe_offload_constant.hpp
@@ -10,8 +10,10 @@
#include <string>
#include "ov_ops/moe_compressed.hpp"
-#include "intel_gpu/plugin/program_builder.hpp"
#include "intel_gpu/runtime/debug_configuration.hpp"
+#include "intel_gpu/runtime/engine.hpp"
+#include "intel_gpu/runtime/execution_config.hpp"
+#include "intel_gpu/runtime/memory.hpp"
#include "openvino/op/constant.hpp"
namespace ov::intel_gpu {
@@ -75,7 +77,8 @@ private:
PartialUploadLogState& get_partial_upload_log_state();
-PartialUploadDesc try_prepare_partial_upload(ProgramBuilder& p,
+PartialUploadDesc try_prepare_partial_upload(cldnn::engine& engine,
+ const ExecutionConfig& config,
const std::shared_ptr<ov::op::v0::Constant>& op,
const ov::Shape& const_shape,
cldnn::data_types out_dtype,
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/cache_serialization_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/cache_serialization_test.cpp
index 281c6879a4a..45fb2837981 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/cache_serialization_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/cache_serialization_test.cpp
@@ -12,6 +12,7 @@
#include "test_utils.h"
#include "intel_gpu/graph/serialization/binary_buffer.hpp"
#include "intel_gpu/graph/serialization/utils.hpp"
+#include "intel_gpu/primitives/data.hpp"
#include <algorithm>
#include <cstdint>
@@ -376,4 +377,35 @@ TEST(cache_serialization, load_weights_rejects_data_size_exceeding_layout) {
// path, so mem is allocated from output_layout and the oversized read would
// overflow it. The cross-check must reject the blob first.
ASSERT_THROW(data_prim.load_weights(ib, /*weights_memory=*/nullptr, /*model_tensor_base=*/nullptr), ov::AssertFailure);
+}
+
+TEST(cache_serialization, otd_partial_allocation_uses_weightless_metadata) {
+ auto& engine = get_test_engine();
+ const layout full_layout({1, 1, 1, 64}, data_types::u8, format::bfyx);
+ const layout resident_layout({1, 1, 1, 16}, data_types::u8, format::bfyx);
+ auto resident_memory = engine.allocate_memory(resident_layout, true);
+ auto partial_memory = engine.reinterpret_buffer(*resident_memory, full_layout);
+
+ data partial_data("partial", partial_memory, true);
+ partial_data.cache_info->set_constant_info(0,
+ full_layout.bytes_count(),
+ ov::element::u8,
+ ov::element::u8,
+ full_layout.get_shape());
+
+ auto full_memory = engine.allocate_memory(full_layout, true);
+ data plain_data("plain", full_memory);
+
+ const auto serialized_size = [](const data& data_prim) {
+ membuf mem_buf;
+ std::ostream out_mem(&mem_buf);
+ BinaryOutputBuffer ob(out_mem);
+ ob.set_stream(get_test_stream_ptr().get());
+ data_prim.save(ob);
+ return static_cast<size_t>(std::distance(mem_buf.begin(), mem_buf.end()));
+ };
+
+ // OTD exposes the full Constant layout while allocating only resident slots.
+ // Weightless caching must serialize metadata instead of reading that full layout.
+ EXPECT_LT(serialized_size(partial_data), serialized_size(plain_data));
}
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/moe_offload_constant_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/moe_offload_constant_test.cpp
index 7780906268b..37149385d17 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/moe_offload_constant_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/moe_offload_constant_test.cpp
@@ -4,8 +4,10 @@
#include <gtest/gtest.h>
+#include "test_utils.h"
#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"
+#include "intel_gpu/runtime/internal_properties.hpp"
#include "ov_ops/moe_compressed.hpp"
#include "plugin/ops/moe_offload_constant.hpp"
@@ -148,3 +150,27 @@ TEST(moe_offload_constant, shared_expert_not_cropped_by_partial_upload) {
<< " must NOT be classified as RoutedExpert (would be wrongly cropped by partial upload)";
}
}
+
+TEST(moe_offload_constant, partial_upload_uses_preferred_allocation_type) {
+ auto& engine = tests::get_test_engine();
+ auto config = tests::get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::offload_ratio(20));
+ auto graph = MoETestGraph::build();
+ auto constant = graph.constants[0];
+ const auto shape = constant->get_output_shape(0);
+ const auto layout = cldnn::layout(shape,
+ cldnn::element_type_to_data_type(constant->get_output_element_type(0)),
+ cldnn::format::get_default_format(shape.size()));
+
+ const auto desc = try_prepare_partial_upload(engine,
+ config,
+ constant,
+ shape,
+ layout.data_type,
+ layout.format,
+ layout);
+
+ ASSERT_TRUE(desc.enabled);
+ EXPECT_LT(desc.upload_bytes, layout.bytes_count());
+ EXPECT_EQ(desc.memory->get_allocation_type(), engine.get_preferred_memory_allocation_type());
+}