Skip to content

[CPU] Add test case of setting model_distribution_policy to TENSOR_PARALLEL #29322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ class OPENVINO_RUNTIME_API IStreamsExecutor : virtual public ITaskExecutor {
bool operator==(const Config& config) {
if (_name == config._name && _streams == config._streams &&
_threads_per_stream == config._threads_per_stream &&
_thread_preferred_core_type == config._thread_preferred_core_type) {
_thread_preferred_core_type == config._thread_preferred_core_type &&
_rank == config._rank) {
return true;
} else {
return false;
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/intel_cpu/src/cpu_streams_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ std::vector<std::vector<int>> get_streams_info_table(
stream_table_size = streams_info_table.size();
}
}

if ((total_streams == 1) && (proc_type_table.size() == 1) &&
(hint_model_distribution_policy.find(ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL) !=
hint_model_distribution_policy.end())) {
streams_info_table.push_back(streams_info_table[0]);
streams_info_table.push_back(streams_info_table[0]);
streams_info_table[0][THREADS_PER_STREAM] = streams_info_table[0][THREADS_PER_STREAM] * 2;
streams_info_table[1][NUMBER_OF_STREAMS] = -1;
streams_info_table[2][NUMBER_OF_STREAMS] = -1;
}
}
} else if (proc_type_table.size() == 1) {
if (stream_info[PROC_TYPE] == ALL_PROC) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_cpu/src/infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ void SyncInferRequest::sub_streams_infer() {

if (requests.size() > 0) {
for (const auto& output : outputs) {
auto tensor = requests[0]->get_tensor(output);
set_tensor(output, tensor);
auto tensor = get_tensor(output);
requests[0]->set_tensor(output, tensor);
}
for (size_t i = 0; i < requests_num; i++) {
for (auto& input : inputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <gtest/gtest.h>

#include "common_test_utils/ov_tensor_utils.hpp"
#include "common_test_utils/subgraph_builders/matmul_bias.hpp"
#include "openvino/runtime/compiled_model.hpp"
#include "openvino/runtime/core.hpp"
#include "openvino/runtime/intel_cpu/properties.hpp"
Expand Down Expand Up @@ -518,4 +520,63 @@ TEST_F(OVClassConfigTestCPU, smoke_CpuExecNetworkCheckCPURuntimOptionsWithCorePr
ASSERT_EQ(valueCacheType.as<ov::element::Type>(), ov::element::bf16);
}

TEST_F(OVClassConfigTestCPU, smoke_CpuModelDistributionPolicyTensorParallel) {
ov::Core core;
std::shared_ptr<ov::Model> model = ov::test::utils::make_matmul_bias();
std::set<ov::hint::ModelDistributionPolicy> setModels = {ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL};
ov::AnyMap config = {{ov::hint::model_distribution_policy.name(), setModels},
{ov::num_streams.name(), 1},
{ov::inference_num_threads.name(), 1}};

core.set_property(deviceName, config);
ov::CompiledModel compiledModel = core.compile_model(model, deviceName);

std::set<ov::hint::ModelDistributionPolicy> model_distribution_policy_value = {};
OV_ASSERT_NO_THROW(model_distribution_policy_value = compiledModel.get_property(ov::hint::model_distribution_policy));
ASSERT_EQ(model_distribution_policy_value, setModels);
}

TEST_F(OVClassConfigTestCPU, smoke_CpuModelDistributionPolicyTensorParallelAccurcay) {
Copy link

@dmitry-gorokhov dmitry-gorokhov Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be usual functional subgraph test, which already have all the infra for output comparision and inputs filling.
Besides that we have to cover cases like matmul with compressed weights.
It also worth to verify execution graph to make sure TP was actually applied

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added test case about TP to mat_mul.cpp and shared_matmul_weights_decompression.cpp. Please have a look.

ov::Core core;
std::shared_ptr<ov::Model> model = ov::test::utils::make_matmul_bias();
std::set<ov::hint::ModelDistributionPolicy> setModels = {ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL};
ov::AnyMap config_model = {{ov::hint::model_distribution_policy.name(), setModels},
{ov::num_streams.name(), 1},
{ov::inference_num_threads.name(), 1}};

core.set_property(deviceName, config_model);

std::map<ov::Output<ov::Node>, ov::Tensor> inputs;
for (const auto& input : model->inputs()) {
auto tensor = ov::test::utils::create_and_fill_tensor_normal_distribution(input.get_element_type(),
input.get_shape(),
0.0f,
0.2f,
7235346);
inputs.insert({input, tensor});
}

auto getOutputBlob = [&](ov::Core& core) {
auto compiled_model = core.compile_model(model, deviceName);
auto req = compiled_model.create_infer_request();
for (const auto& input : inputs) {
req.set_tensor(input.first, input.second);
}
auto output_tensor = ov::Tensor(model->output().get_element_type(), model->output().get_shape());
req.set_output_tensor(output_tensor);
req.infer();
return output_tensor;
};

auto outputActual = getOutputBlob(core);

{
ov::Core coreRef;
ov::AnyMap config = {{ov::num_streams.name(), 1}, {ov::inference_num_threads.name(), 1}};
coreRef.set_property(deviceName, config);
auto outputRef = getOutputBlob(coreRef);
ov::test::utils::compare(outputActual, outputRef);
}
}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,32 @@ StreamsCalculationTestCase _2sockets_mock_latency_51 = {
{{16, 16, 0, 0, -1, -1}, {8, 8, 0, 0, 0, 0}, {8, 8, 0, 0, 1, 1}},
{{1, ALL_PROC, 16, -1, -1}, {0, MAIN_CORE_PROC, 8, 0, 0}, {0, MAIN_CORE_PROC, 8, 1, 1}},
};
StreamsCalculationTestCase _1sockets_mock_TP_1 = {
1,
false,
0,
0,
0,
"LATENCY",
{ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL},
{{8, 8, 0, 0, 0, 0}},
{{1, MAIN_CORE_PROC, 16, 0, 0},
{-1, MAIN_CORE_PROC, 8, 0, 0},
{-1, MAIN_CORE_PROC, 8, 0, 0}},
};
StreamsCalculationTestCase _1sockets_mock_TP_2 = {
1,
false,
1,
0,
0,
"LATENCY",
{ov::hint::ModelDistributionPolicy::TENSOR_PARALLEL},
{{8, 8, 0, 0, 0, 0}},
{{1, MAIN_CORE_PROC, 2, 0, 0},
{-1, MAIN_CORE_PROC, 1, 0, 0},
{-1, MAIN_CORE_PROC, 1, 0, 0}},
};

TEST_P(StreamsCalculationTests, StreamsCalculation) {}

Expand Down Expand Up @@ -2843,6 +2869,8 @@ INSTANTIATE_TEST_SUITE_P(StreamsInfoTable,
_1sockets_mock_latency_3,
_1sockets_mock_latency_4,
_1sockets_mock_latency_5,
_1sockets_mock_latency_6));
_1sockets_mock_latency_6,
_1sockets_mock_TP_1,
_1sockets_mock_TP_2));

} // namespace
Loading