Skip to content
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

[CVS-164415] WS Implement Model Exportation #29526

Draft
wants to merge 76 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
788dfcb
Adding weights I/O prefixes
razvanapetroaie Sep 23, 2024
b3c3574
Parsing I/O weights in the plugin-driver adapter
razvanapetroaie Sep 23, 2024
111aedd
Some more adjustments to acommodate the new I/O prefixes
razvanapetroaie Sep 23, 2024
73c7f1c
Adding the compileWS method
razvanapetroaie Sep 23, 2024
283bb45
Implemented the compileWS method for the plugin-driver adapter
razvanapetroaie Sep 23, 2024
35729af
Using the compileWS method instead of compile one
razvanapetroaie Sep 23, 2024
f5900d5
Enabling the WS path via a new config option
razvanapetroaie Sep 24, 2024
59074ef
Skipping the weights inputs inside the L0 infer request
razvanapetroaie Sep 24, 2024
f345d87
Adding the signatures for the "runInit" calls
razvanapetroaie Sep 24, 2024
eec036d
Switching to reusing the Executor ctor
razvanapetroaie Sep 24, 2024
f5bad76
Rewritten the "runInit" signatures
razvanapetroaie Sep 24, 2024
671de43
Extracting weights pointers
razvanapetroaie Sep 24, 2024
d3452cc
Starting the pipeline construction
razvanapetroaie Sep 27, 2024
e061e3f
Creating remote tensors for init input
razvanapetroaie Sep 30, 2024
0634e56
Setting init outputs as main inputs upon inference request creation
razvanapetroaie Sep 30, 2024
9e5dc3d
First version which is runnable by bapp
razvanapetroaie Oct 3, 2024
f329c21
Small adjustments required for acommodating the most recent compiled …
razvanapetroaie Oct 4, 2024
382893b
Some adjustments
razvanapetroaie Oct 14, 2024
a5b8ed2
Using topological sorting for weights identification
razvanapetroaie Oct 15, 2024
0bd457b
SIT accurate solution on resnet 50, but it's not a nice one
razvanapetroaie Oct 16, 2024
54df505
Adding time checks
razvanapetroaie Oct 21, 2024
9fc8f8b
Use modified model for Init
nikita-kud Oct 23, 2024
04ad63f
Using the "initModel" as a local variable
razvanapetroaie Oct 24, 2024
4fd3039
Moving the compiler object within the CompiledModel class
razvanapetroaie Oct 24, 2024
8a4a7b4
Solving build issues related to batching
razvanapetroaie Oct 28, 2024
f0ab437
Fixing stateful models
razvanapetroaie Oct 29, 2024
a47c4b2
Removing one redundant(?) runNgraphPasses call
razvanapetroaie Oct 29, 2024
32648fc
Moving "run_init" in the "create_infer_request" method
razvanapetroaie Oct 29, 2024
02aac22
Enabling model import
razvanapetroaie Oct 29, 2024
8f7b2a9
Merge commit 'caa1e6af13139692a34cf37787c9c79f949bcaaa' into EISW-138…
razvanapetroaie Nov 5, 2024
f08e886
Solving segfaults on linux
razvanapetroaie Nov 6, 2024
3552618
Forcing the CiP path even if the compiler type was set to "DRIVER"
razvanapetroaie Nov 6, 2024
5ea2cb7
Adding the BENCHMARK_INIT config option in order to allow running the…
razvanapetroaie Nov 6, 2024
dc54291
Merge commit '6c715998b36012c26d59e73fe86fca00fee761d3' into EISW-138…
razvanapetroaie Nov 7, 2024
8cc6098
Using plugin's metadata structures for the "runInit" call instead of …
razvanapetroaie Nov 13, 2024
3315ac0
Moving runInit inside the "CompiledModel" ctor by default. The behvai…
razvanapetroaie Nov 13, 2024
4c85b78
Adding time measurements for the memory copy operations performed on …
razvanapetroaie Nov 20, 2024
d31dac5
Changing "SEPARATE_WEIGHTS": bool -> "SEPARATE_WEIGHTS_VERSION": uint…
razvanapetroaie Nov 20, 2024
6c3f1fc
Using a single remote tensor for all init inputs
razvanapetroaie Nov 25, 2024
42cb2da
Using a single remote tensor for all init outputs
razvanapetroaie Nov 25, 2024
66387ad
Revert "Forcing the CiP path even if the compiler type was set to "DR…
razvanapetroaie Nov 25, 2024
bbcbcb2
Starting work on a CiD solution
razvanapetroaie Nov 25, 2024
b847a4b
Change the unit of several time measurements to microseconds
razvanapetroaie Nov 25, 2024
6d2b567
Merge commit '91a5518347a5e4e55f940b6e3c9b8f00626f09ff' into EISW-138…
razvanapetroaie Nov 26, 2024
b8bbd39
Add method compileWS_v3
nikita-kud Nov 28, 2024
e2a0246
Just replaced some assertions
razvanapetroaie Dec 4, 2024
8833006
Cloning a model for each compileWS_v3 call
razvanapetroaie Dec 4, 2024
8eb2ece
Import/export - changing the data type of several fields
razvanapetroaie Dec 6, 2024
984c3df
Adding a new config option used for notifying the compiler of the "co…
razvanapetroaie Dec 6, 2024
b1d1e25
Implementing WS v3 within the CiD path
razvanapetroaie Dec 6, 2024
9b688b6
Copying the OV passes in the WS CiD path
razvanapetroaie Dec 6, 2024
44f7a0d
Implementing the export path for the CiD branch
razvanapetroaie Dec 6, 2024
9edbe10
Solving some compilation warnings
razvanapetroaie Dec 10, 2024
6403ebd
Changing the default value of the separate weights config entry to 3
razvanapetroaie Dec 11, 2024
4f865c6
Merge commit '99d7cd4bc4492b81a99bc41e2d2469da1a929491' into EISW-138…
razvanapetroaie Dec 12, 2024
8a8ef57
Merge commit 'b982e19525eeecb0cf385591bd1ec182a781cb05' into EISW-138…
razvanapetroaie Jan 15, 2025
7d24ee5
Adding a time measurement for compiler->parse()
razvanapetroaie Jan 15, 2025
b066a03
Fixing the Windows build
razvanapetroaie Jan 20, 2025
147e2db
Add more logs
nikita-kud Dec 17, 2024
f2244fa
Merge commit '8d5f583bc7e56152440192806b3acda619a997fe' into EISW-138…
razvanapetroaie Jan 28, 2025
f8ae920
Change weights prefix
nikita-kud Jan 29, 2025
015dcb4
Merge commit '5aefcd9' into EISW-138991-weights-separation-poc
razvanapetroaie Mar 18, 2025
98f400a
Adding support for the MODEL_PTR property
razvanapetroaie Mar 18, 2025
282d62b
Implementing the import part
razvanapetroaie Mar 18, 2025
ab99a0c
Implementing the export path
razvanapetroaie Mar 18, 2025
4860fd9
Adding OV common passes on model importation
razvanapetroaie Mar 18, 2025
f98c858
Fixing the implementation
razvanapetroaie Mar 25, 2025
da8597a
Adding a workaround for the bapp tool
razvanapetroaie Mar 25, 2025
fd008d5
Adding the same workaround, but for the single image test tool
razvanapetroaie Mar 25, 2025
bade648
Removing a deprecated function
razvanapetroaie Mar 25, 2025
18ececd
Freeing the serialized IR before initializing the L0 graph
razvanapetroaie Mar 25, 2025
6ce7364
Adding reminder
razvanapetroaie Mar 25, 2025
7cecd0f
Changin the type of the MODEL_PTR config option
razvanapetroaie Mar 25, 2025
415adef
Removing the dummy model when the full one is provided
razvanapetroaie Mar 26, 2025
31319d4
Revert "Removing the dummy model when the full one is provided"
razvanapetroaie Mar 26, 2025
b10d2a5
Adding support for the ONNX extension
razvanapetroaie Mar 27, 2025
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
Prev Previous commit
Next Next commit
Changing "SEPARATE_WEIGHTS": bool -> "SEPARATE_WEIGHTS_VERSION": uint…
…32_t
razvanapetroaie committed Nov 21, 2024
commit d31dac5be8b4996a1d1b200bb21bdcef4c7146b0
Original file line number Diff line number Diff line change
@@ -265,13 +265,31 @@ struct BATCH_MODE final : OptionBase<BATCH_MODE, ov::intel_npu::BatchMode> {
static std::string toString(const ov::intel_npu::BatchMode& val);
};

struct SEPARATE_WEIGHTS final : OptionBase<SEPARATE_WEIGHTS, bool> {
struct SEPARATE_WEIGHTS_VERSION final : OptionBase<SEPARATE_WEIGHTS_VERSION, uint32_t> {
static std::string_view key() {
return ov::intel_npu::separate_weights.name();
return ov::intel_npu::separate_weights_version.name();
}

static bool defaultValue() {
return true;
static uint32_t defaultValue() {
return 2;
}

static uint32_t parse(std::string_view val) {
int val_i = -1;
try {
val_i = std::stoi(val.data());
if (val_i >= 0) {
return val_i;
} else {
throw std::logic_error("wrong val");
}
} catch (const std::exception&) {
OPENVINO_THROW("Wrong value of ",
val.data(),
" for property key ",
ov::intel_npu::separate_weights_version.name(),
". Expected only positive integer numbers");
}
}
};

14 changes: 12 additions & 2 deletions src/plugins/intel_npu/src/al/include/intel_npu/icompiler.hpp
Original file line number Diff line number Diff line change
@@ -58,8 +58,18 @@ class ICompiler : public std::enable_shared_from_this<ICompiler> {
* @param config
* @return NetworkDescription
*/
virtual std::vector<std::shared_ptr<NetworkDescription>> compileWS(const std::shared_ptr<ov::Model>& model,
const Config& config) const = 0;
virtual std::vector<std::shared_ptr<NetworkDescription>> compileWS_v1(const std::shared_ptr<ov::Model>& model,
const Config& config) const = 0;

/**
* @brief TODO
*
* @param model
* @param config
* @return NetworkDescription
*/
virtual std::shared_ptr<NetworkDescription> compileWS_v2(const std::shared_ptr<ov::Model>& model,
const Config& config) = 0;

/**
* @brief Returns information about supported layers of the network passed
Original file line number Diff line number Diff line change
@@ -347,7 +347,7 @@ static constexpr ov::Property<BatchMode> batch_mode{"NPU_BATCH_MODE"};
/**
* @brief TODO
*/
static constexpr ov::Property<bool> separate_weights{"NPU_SEPARATE_WEIGHTS"};
static constexpr ov::Property<uint32_t> separate_weights_version{"NPU_SEPARATE_WEIGHTS_VERSION"};

static constexpr ov::Property<bool> benchmark_init{"NPU_BENCHMARK_INIT"};

2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/al/src/config/common.cpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ void intel_npu::registerCommonOptions(OptionsDesc& desc) {
desc.add<CACHE_DIR>();
desc.add<LOADED_FROM_CACHE>();
desc.add<BATCH_MODE>();
desc.add<SEPARATE_WEIGHTS>();
desc.add<SEPARATE_WEIGHTS_VERSION>();
desc.add<BENCHMARK_INIT>();
}

Original file line number Diff line number Diff line change
@@ -643,10 +643,10 @@ std::string DriverCompilerAdapter::serializeConfig(const Config& config,
<< VALUE_DELIMITER;
content = std::regex_replace(content, std::regex(umdcachestring.str()), "");

// SEPARATE_WEIGHTS does not involve the compiler (yet)
// SEPARATE_WEIGHTS_VERSION does not involve the compiler (yet)
std::ostringstream separateWeightsStream;
separateWeightsStream << ov::intel_npu::separate_weights.name() << KEY_VALUE_SEPARATOR << VALUE_DELIMITER << "\\S+"
<< VALUE_DELIMITER;
separateWeightsStream << ov::intel_npu::separate_weights_version.name() << KEY_VALUE_SEPARATOR << VALUE_DELIMITER
<< "\\S+" << VALUE_DELIMITER;
content = std::regex_replace(content, std::regex(separateWeightsStream.str()), "");

std::ostringstream benchmarkInitStream;
Original file line number Diff line number Diff line change
@@ -127,17 +127,34 @@ std::shared_ptr<IGraph> PluginCompilerAdapter::compile(const std::shared_ptr<con
std::move(networkDesc.compiledNetwork),
config);
}

std::vector<std::shared_ptr<IGraph>> PluginCompilerAdapter::compileWS(const std::shared_ptr<ov::Model>& model,
const Config& config) const {
OV_ITT_TASK_CHAIN(COMPILE_BLOB, itt::domains::NPUPlugin, "PluginCompilerAdapter", "compileWS");

std::shared_ptr<NetworkDescription> initNetworkDescription;
std::shared_ptr<NetworkDescription> mainNetworkDescription;

_logger.debug("compile start");
const std::vector<std::shared_ptr<NetworkDescription>> initMainNetworkDescriptions =
_compiler->compileWS(model, config);
_logger.debug("compile end");

auto initNetworkDescription = initMainNetworkDescriptions[0];
auto mainNetworkDescription = initMainNetworkDescriptions[1];
switch (config.get<SEPARATE_WEIGHTS_VERSION>()) {
case 1: {
const std::vector<std::shared_ptr<NetworkDescription>> initMainNetworkDescriptions =
_compiler->compileWS_v1(model, config);

initNetworkDescription = initMainNetworkDescriptions[0];
mainNetworkDescription = initMainNetworkDescriptions[1];
} break;
case 2: {
initNetworkDescription = _compiler->compileWS_v2(model, config);
mainNetworkDescription = _compiler->compileWS_v2(model, config);
} break;
default:
OPENVINO_THROW("Invalid \"SEPARATE_WEIGHTS_VERSION\" value found within the \"compileWS\" call");
break;
}

_logger.debug("compile end");

ze_graph_handle_t initGraphHandle = nullptr;
ze_graph_handle_t mainGraphHandle = nullptr;
13 changes: 7 additions & 6 deletions src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
initialize_properties();
configure_stream_executors();

if (_config.get<SEPARATE_WEIGHTS>() && _initGraph != nullptr) {
if (_config.get<SEPARATE_WEIGHTS_VERSION>() != 0 && _initGraph != nullptr) {
if (_config.get<CREATE_EXECUTOR>() && !_config.get<DEFER_WEIGHTS_LOAD>()) {
begin = std::chrono::steady_clock::now();
_weightsInputs = _device->runInit(_initGraph, _initModel, get_context(), _config);
@@ -77,7 +77,7 @@ std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() co
_device->createInferRequest(shared_from_this(), _config);
syncInferRequest->initialize_states();

if (_config.get<SEPARATE_WEIGHTS>() && _initGraph != nullptr) {
if (_config.get<SEPARATE_WEIGHTS_VERSION>() != 0 && _initGraph != nullptr) {
if (!_config.get<CREATE_EXECUTOR>() || _config.get<DEFER_WEIGHTS_LOAD>()) {
begin = std::chrono::steady_clock::now();
_initGraph->initialize(_config);
@@ -101,9 +101,10 @@ std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() co
end = std::chrono::steady_clock::now();
std::cout << "set_weights_inputs() call "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << "[ms]" << std::endl;
} else if (_config.get<SEPARATE_WEIGHTS>() && _initGraph == nullptr) {
_logger.warning("SEPARATE_WEIGHTS config option was set but no compiled model for the init schedule was found. "
"run_init() will not run.");
} else if (_config.get<SEPARATE_WEIGHTS_VERSION>() != 0 && _initGraph == nullptr) {
_logger.warning(
"SEPARATE_WEIGHTS_VERSION config option was set but no compiled model for the init schedule was found. "
"run_init() will not run.");
}

return std::make_shared<AsyncInferRequest>(syncInferRequest,
@@ -121,7 +122,7 @@ std::shared_ptr<ov::ISyncInferRequest> CompiledModel::create_sync_infer_request(
void CompiledModel::export_model(std::ostream& stream) const {
_logger.debug("CompiledModel::export_model");

if (_config.get<SEPARATE_WEIGHTS>()) {
if (_config.get<SEPARATE_WEIGHTS_VERSION>() != 0) {
_graph->custom_export(stream, _initGraph, _initModel);
return;
}
8 changes: 4 additions & 4 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -619,11 +619,11 @@ Plugin::Plugin()
[](const Config& config) {
return config.getString<BATCH_MODE>();
}}},
{ov::intel_npu::separate_weights.name(),
{ov::intel_npu::separate_weights_version.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.getString<SEPARATE_WEIGHTS>();
return config.getString<SEPARATE_WEIGHTS_VERSION>();
}}},
{ov::intel_npu::benchmark_init.name(),
{false,
@@ -766,7 +766,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
try {
_logger.debug("performing compile");

if (!localConfig.get<SEPARATE_WEIGHTS>()) {
if (localConfig.get<SEPARATE_WEIGHTS_VERSION>() == 0) {
graph = compiler->compile(model, localConfig);
} else {
initModel = model->clone();
@@ -855,7 +855,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
try {
auto compiler = getCompiler(localConfig);

if (!localConfig.get<SEPARATE_WEIGHTS>()) {
if (localConfig.get<SEPARATE_WEIGHTS_VERSION>() == 0) {
auto graphSize = getFileSize(stream);

std::vector<uint8_t> blob(graphSize);