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 73 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
73 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
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
50 changes: 50 additions & 0 deletions samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
@@ -51,6 +51,41 @@

// clang-format on

#if defined _WIN32

# include <psapi.h>
# include <windows.h>

int64_t getPeakMemoryUsage() {
PROCESS_MEMORY_COUNTERS memCounters;
GetProcessMemoryInfo(GetCurrentProcess(), &memCounters, sizeof(memCounters));
return memCounters.PeakWorkingSetSize / 1000;
}

#else

# include <fstream>
# include <regex>
# include <sstream>

int64_t getPeakMemoryUsage() {
size_t peakMemUsageKB = 0;

std::ifstream statusFile("/proc/self/status");
std::string line;
std::regex vmPeakRegex("VmPeak:");
std::smatch vmMatch;
while (std::getline(statusFile, line)) {
if (std::regex_search(line, vmMatch, vmPeakRegex)) {
std::istringstream iss(vmMatch.suffix());
iss >> peakMemUsageKB;
}
}
return static_cast<int64_t>(peakMemUsageKB);
}

#endif

namespace {

#if defined(_WIN32)
@@ -120,6 +155,9 @@ int64_t get_peak_memory_usage() {

#endif

constexpr std::string_view WEIGHTS_EXTENSION = ".bin";
constexpr std::string_view BLOB_EXTENSION = ".blob";

bool parse_and_check_command_line(int argc, char* argv[]) {
// ---------------------------Parsing and validating input
// arguments--------------------------------------
@@ -862,10 +900,22 @@ int main(int argc, char* argv[]) {
auto startTime = Time::now();

std::ifstream modelStream(FLAGS_m, std::ios_base::binary | std::ios_base::in);
auto importModelMemStart = getPeakMemoryUsage();
if (!modelStream.is_open()) {
throw std::runtime_error("Cannot open model file " + FLAGS_m);
}

device_config.insert(ov::hint::allow_auto_batching(false));

if (!device_config.count(ov::weights_path.name())) {
// Temporary solution: build the path to the weights by leveragin the one towards the binary object
std::string weightsPath = FLAGS_m;
weightsPath.replace(weightsPath.size() - BLOB_EXTENSION.length(),
BLOB_EXTENSION.length(),
WEIGHTS_EXTENSION);
device_config.insert(ov::weights_path(weightsPath));
}

compiledModel = core.import_model(modelStream, device_name, device_config);
modelStream.close();

9 changes: 5 additions & 4 deletions samples/cpp/benchmark_app/utils.cpp
Original file line number Diff line number Diff line change
@@ -287,11 +287,12 @@ size_t get_batch_size(const benchmark_app::InputsInfo& inputs_info) {
size_t batch_size = 0;
for (auto& info : inputs_info) {
if (ov::layout::has_batch(info.second.layout)) {
if (batch_size == 0)
if (batch_size == 0) {
batch_size = info.second.batch();
else if (batch_size != info.second.batch())
throw std::logic_error("Can't deterimine batch size: batch is "
"different for different inputs!");
} else if (batch_size != info.second.batch()) {
batch_size = 0;
break;
}
}
}
if (batch_size == 0) {
Original file line number Diff line number Diff line change
@@ -265,6 +265,72 @@ struct BATCH_MODE final : OptionBase<BATCH_MODE, ov::intel_npu::BatchMode> {
static std::string toString(const ov::intel_npu::BatchMode& val);
};

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

static uint32_t defaultValue() {
return 3;
}

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");
}
}
};

struct BENCHMARK_INIT final : OptionBase<BENCHMARK_INIT, bool> {
static std::string_view key() {
return ov::intel_npu::benchmark_init.name();
}

static bool defaultValue() {
return false;
}
};

struct WS_COMPILE_CALL_NUMBER final : OptionBase<WS_COMPILE_CALL_NUMBER, uint32_t> {
static std::string_view key() {
return ov::intel_npu::ws_compile_call_number.name();
}

static uint32_t defaultValue() {
return 0;
}

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::ws_compile_call_number.name(),
". Expected only positive integer numbers");
}
}
};

} // namespace intel_npu

namespace ov {
Original file line number Diff line number Diff line change
@@ -219,6 +219,34 @@ struct WEIGHTS_PATH final : OptionBase<WEIGHTS_PATH, std::string> {
}
};

//
// MODEL_PTR
//
struct MODEL_PTR final : OptionBase<MODEL_PTR, std::shared_ptr<ov::Model>> {
static std::string_view key() {
return ov::hint::model.name();
}

static constexpr std::string_view getTypeName() {
return "std::shared_ptr<ov::Model>";
}

static std::shared_ptr<ov::Model> defaultValue() {
return nullptr;
}

static std::shared_ptr<ov::Model> parse(std::string_view) {
return nullptr;
}
static std::string toString(const std::shared_ptr<ov::Model>& m) {
return "";
}

static OptionMode mode() {
return OptionMode::RunTime;
}
};

//
// ENABLE_CPU_PINNING
//
36 changes: 36 additions & 0 deletions src/plugins/intel_npu/src/al/include/intel_npu/icompiler.hpp
Original file line number Diff line number Diff line change
@@ -56,6 +56,42 @@ class ICompiler : public std::enable_shared_from_this<ICompiler> {
*/
virtual NetworkDescription compile(const std::shared_ptr<const ov::Model>& model, const Config& config) const = 0;

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

/**
* @brief Sequantial compilation of Init(s) and Main
*
* "Stateful compiler" approach
*/
virtual std::shared_ptr<NetworkDescription> compileWS_v2(const std::shared_ptr<ov::Model>& model,
const Config& config) = 0;

/**
* @brief Sequantial compilation of Init(s) and Main
*
* "Stateless compiler" approach
* We want to get multiple Inits in the case of a large number of weights.
* This allows us to build pipeline:
* Allocate W1 -> Init1
* Allocate W2 -> Init2
* Allocate W3 -> Init2
*
* This is why there is an additional parameter callNumber:
* Compiler should somehow understand wich Init(or Main) to return
* Plugin does not know total numbers og Init schedules
*/
virtual std::shared_ptr<NetworkDescription> compileWS_v3(const std::shared_ptr<ov::Model>& model,
const Config& config,
size_t callNumber) const = 0;

/**
* @brief Returns information about supported layers of the network passed
* @param model The model to be queried
Original file line number Diff line number Diff line change
@@ -64,6 +64,21 @@ struct IODescriptor {
*/
bool isShapeTensor = false;

/**
* @brief TODO
*/
bool isInitInputWeights = false;

/**
* @brief TODO
*/
bool isInitOutputWeights = false;

/**
* @brief TODO
*/
bool isMainInputWeights = false;

/**
* @brief Points towards a related descriptor.
* @details The related descriptors are defined by (state input, state output) or (dynamic tensor, shape tensor)
Original file line number Diff line number Diff line change
@@ -298,6 +298,15 @@ static constexpr ov::Property<ProfilingType> profiling_type{"NPU_PROFILING_TYPE"
*/
static constexpr ov::Property<BatchMode> batch_mode{"NPU_BATCH_MODE"};

/**
* @brief TODO
*/
static constexpr ov::Property<uint32_t> separate_weights_version{"NPU_SEPARATE_WEIGHTS_VERSION"};

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

static constexpr ov::Property<uint32_t> ws_compile_call_number{"WS_COMPILE_CALL_NUMBER"};

/**
* @brief [Only for NPU Plugin]
* Type: integer, default is 1
32 changes: 25 additions & 7 deletions src/plugins/intel_npu/src/al/include/intel_npu/prefix.hpp
Original file line number Diff line number Diff line change
@@ -5,24 +5,42 @@
#pragma once

#include <string>
#include <string_view>

namespace intel_npu {

//
// Prefix for ReadValue and Assign operations in compiler.
// TODO
//
constexpr std::string_view READVALUE_PREFIX = "vpux_ie_read_value_";
constexpr std::string_view ASSIGN_PREFIX = "vpux_ie_assign_";
constexpr std::string_view SHAPE_TENSOR_PREFIX = "vpux_ie_shape_";
constexpr std::string_view INIT_INPUT_WEIGHTS_PREFIX = "in_ov_";
constexpr std::string_view INIT_OUTPUT_WEIGHTS_PREFIX = "out_ov_";
constexpr std::string_view MAIN_INPUT_WEIGHTS_PREFIX = "out_ov_";

inline bool isStateInputName(const std::string& name) {
return !name.compare(0, READVALUE_PREFIX.length(), READVALUE_PREFIX);
inline bool nameHasPrefix(std::string_view name, std::string_view prefix) {
return !name.compare(0, prefix.length(), prefix);
}
inline bool isStateOutputName(const std::string& name) {
return !name.compare(0, ASSIGN_PREFIX.length(), ASSIGN_PREFIX);

inline bool isStateInputName(std::string_view name) {
return nameHasPrefix(name, READVALUE_PREFIX);
}
inline bool isStateOutputName(std::string_view name) {
return nameHasPrefix(name, ASSIGN_PREFIX);
}
inline bool isShapeTensorName(std::string_view name) {
return nameHasPrefix(name, SHAPE_TENSOR_PREFIX);
}

inline bool isInitInputWeightsName(std::string_view name) {
return nameHasPrefix(name, INIT_INPUT_WEIGHTS_PREFIX);
}
inline bool isInitOutputWeightsName(std::string_view name) {
return nameHasPrefix(name, INIT_OUTPUT_WEIGHTS_PREFIX);
}
inline bool isShapeTensorName(const std::string& name) {
return !name.compare(0, SHAPE_TENSOR_PREFIX.length(), SHAPE_TENSOR_PREFIX);
inline bool isMainInputWeightsName(std::string_view name) {
return nameHasPrefix(name, MAIN_INPUT_WEIGHTS_PREFIX);
}

} // namespace intel_npu
3 changes: 3 additions & 0 deletions src/plugins/intel_npu/src/al/src/config/common.cpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@ void intel_npu::registerCommonOptions(OptionsDesc& desc) {
desc.add<CACHE_DIR>();
desc.add<LOADED_FROM_CACHE>();
desc.add<BATCH_MODE>();
desc.add<SEPARATE_WEIGHTS_VERSION>();
desc.add<BENCHMARK_INIT>();
desc.add<WS_COMPILE_CALL_NUMBER>();
}

//
1 change: 1 addition & 0 deletions src/plugins/intel_npu/src/al/src/config/runtime.cpp
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ void intel_npu::registerRunTimeOptions(OptionsDesc& desc) {
desc.add<WORKLOAD_TYPE>();
desc.add<TURBO>();
desc.add<WEIGHTS_PATH>();
desc.add<MODEL_PTR>();
desc.add<BYPASS_UMD_CACHING>();
desc.add<RUN_INFERENCES_SEQUENTIALLY>();
desc.add<DISABLE_VERSION_CHECK>();
11 changes: 10 additions & 1 deletion src/plugins/intel_npu/src/backend/include/zero_device.hpp
Original file line number Diff line number Diff line change
@@ -20,6 +20,15 @@ class ZeroDevice : public IDevice {
public:
ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs);

/**
* @brief TODO
*/
std::pair<std::unordered_map<std::string, std::shared_ptr<ov::ITensor>>, ov::SoPtr<ov::ITensor>> runInit(
const std::shared_ptr<IGraph>& initGraph,
const std::shared_ptr<const ov::Model>& model,
const ov::SoPtr<ov::IRemoteContext>& context,
const Config& config) override;

std::string getName() const override;
std::string getFullDeviceName() const override;
Uuid getUuid() const override;
@@ -45,7 +54,7 @@ class ZeroDevice : public IDevice {
const Config& config,
ov::intel_npu::TensorType tensor_type = ov::intel_npu::TensorType::BINDED,
ov::intel_npu::MemType mem_type = ov::intel_npu::MemType::L0_INTERNAL_BUF,
void* mem = nullptr) override;
const void* mem = nullptr) override;

ov::SoPtr<ov::ITensor> createHostTensor(
std::shared_ptr<ov::IRemoteContext> context,
Original file line number Diff line number Diff line change
@@ -35,6 +35,9 @@ class ZeroInferRequest final : public SyncInferRequest {

void get_result() override;

void set_weights_inputs(
const std::unordered_map<std::string, std::shared_ptr<ov::ITensor>>& weightsInputs) override;

private:
std::vector<ov::ProfilingInfo> get_profiling_info() const override;
std::vector<uint8_t> get_raw_profiling_data() const;
Loading