Skip to content

Commit

Permalink
Merge branch 'master' into gha/manylinux_jenkins_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
mryzhov authored Nov 14, 2024
2 parents 2a80a1e + b1ff99c commit 17e4f12
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ to see if your case needs any of them.
.. code-block:: python
from openvino import get_cmake_path
from openvino.utils import get_cmake_path
cmake_path = get_cmake_path()
For detailed instructions on how to use these configurations in your build setup, check out the
Expand Down
5 changes: 5 additions & 0 deletions docs/dev/ci/github_actions/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ detailed instructions where necessary.
* [Required workflows](#required-workflows)
* [Workflow structure](#structure-of-the-workflows)
* [Workflow and job organisation](#workflows-and-jobs-organisation)
* [Security considerations](#security-considerations)
* [Finding results, artifacts and logs](#finding-results-artifacts-and-logs)
* [Custom actions overview](#custom-actions)
* [Machines overview](#machines)
Expand Down Expand Up @@ -205,6 +206,10 @@ Overview of the [Linux workflow's](../../../../.github/workflows/ubuntu_22.yml)
* All the steps are executed in the shell specified by the `shell` key under `defaults: run:`
unless a shell is specified directly in a step.

### Security considerations

Please consult [workflow security guidelines](security.md) before submitting a PR with GitHub Actions workflows changes.

## Finding Results, Artifacts, and Logs

### Results
Expand Down
99 changes: 99 additions & 0 deletions docs/dev/ci/github_actions/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Security best practices for GitHub Actions Workflows

There are a few simple steps that we should follow to ensure our workflows are not vulnerable to common attacks.

## Adjust `GITHUB_TOKEN` permissions

Use the `permissions` key to make sure the `GITHUB_TOKEN` is configured with the least privileges for each job.

Start with relatively safe permissions:

```yaml
permissions: read-all
```
If you need more permissions, declare them at the job level when possible, for example:
```yaml
jobs:
stale:
runs-on: ubuntu-latest

# GITHUB_TOKEN will have only these permissions for
# `stale` job
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@f7176fd3007623b69d27091f9b9d4ab7995f0a06

```

Check [GitHub documentation](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token) on this also.

## Reduce the scope of environment variables

Environment variables should be declared at the step level when possible (e.g. the variable is used only in this exact step). Only put variables on the job level when they're used by a few steps, and on the workflow level when they're used by most of the steps.

Example from [the official GitHub documentation](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables):

```yaml
name: Greeting on variable day

on:
workflow_dispatch

# Workflow level variables. Avoid using these.
env:
DAY_OF_WEEK: Monday

jobs:
greeting_job:
runs-on: ubuntu-latest
# Job level variables
env:
Greeting: Hello
steps:
- name: "Say Hello Mona it's Monday"
run: echo "$Greeting $First_Name. Today is $DAY_OF_WEEK!"
# Step level variables. Prefer this approach
env:
First_Name: Mona

```

## Avoid using `pull_request_target`

**Never** use `pull_request_target` trigger event for workflows. If you want to use `pull_request_target`, contact a member of the OpenVINO GitHub Actions task force first. Check [GitHub blog post](https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/) on this as well.

## Handle secrets correctly

**Never ever** use plain-text secrets hard-coded in GitHub Actions Workflow. If you need to use secrets, contact a member of the OpenVINO GitHub Actions task force first.

## Be careful with user input.

Most of GitHub context variables propagated from user input. That means they should be treated as an untrusted and potentially malicious. There are some tactics you can use to mitigate the risk:
- Instead of using inline scripts, create an action and pass the variable as an argument
- Put the value into an environment variable for the step, and use the variable in the script

More details are available in [this](https://securitylab.github.com/resources/github-actions-untrusted-input/) blog post.

## Pin versions for GitHub Actions

When using third-party actions, pin the version with a commit hash rather than a tag to shield your workflow from potential supply-chain compromise.

For example, instead of this:

```yaml
uses: actions/[email protected]
```
use this:
```yaml
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
```
## Further reading
Follow general [recommendations from GitHub itself](https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions)
10 changes: 10 additions & 0 deletions src/inference/src/cpp/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/properties.hpp"

#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
# include <malloc.h>
#endif

#define OV_COMPILED_MODEL_CALL_STATEMENT(...) \
if (_impl == nullptr) \
OPENVINO_THROW("CompiledModel was not initialized."); \
Expand All @@ -23,6 +27,12 @@ namespace ov {

CompiledModel::~CompiledModel() {
_impl = {};
#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
// Linux memory margent doesn't return system memory immediate after release.
// It depends on memory chunk size and allocation history.
// Try return memory from a process to system now to reduce memory usage and not wait to the end of the process.
malloc_trim(0);
#endif
}

CompiledModel::CompiledModel(const std::shared_ptr<ov::ICompiledModel>& impl, const std::shared_ptr<void>& so)
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/intel_cpu/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
ov::element::Type_t::f32,
ov::element::Type_t::f64,
ov::element::Type_t::boolean,
ov::element::Type_t::string};
ov::element::Type_t::string,
ov::element::Type_t::nf4};

if (!supported_precisions.count(input_precision)) {
OPENVINO_THROW_NOT_IMPLEMENTED("CPU plugin: Input image format ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ inline void update_shapes(kernel_selector::Params& p, const kernel_impl_params&
const auto& fused_prim = impl_param.fused_desc[i];
auto& fd = bp.fused_ops[i];
fd.output_tensor = convert_data_tensor(fused_prim.output_layout);
fd.tensors.clear();
for (size_t i = fd.dep_idx_start; i < fd.dep_idx_start + fd.dep_size; i++) {
fd.tensors.push_back(convert_data_tensor(impl_param.get_input_layout(i)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ static bool is_weight_horizontal(const fully_connected_params& params, size_t ou
&& output_f / 4 /* tile_ofm=4 */ > min_num_threads * 1.5);
}

static bool is_weight_small_kn(const fully_connected_params& params, size_t output_f) {
size_t min_num_threads = params.engineInfo.computeUnitsCount * simd;
return output_f / 2 /*most frequently used tile_ofm*/ <= min_num_threads;
}

static bool is_suitable_outer_ofm(const fully_connected_params& params, size_t output_f) {
size_t min_num_threads = params.engineInfo.computeUnitsCount * simd;
return (params.weights.OFM().v > params.weights.IFM().v * 6
Expand Down Expand Up @@ -412,6 +417,11 @@ FullyConnected_bf_tiled::GetAutoTuneParams(const fully_connected_params& params,
} else if (params.weights.GetLayout() == WeightsLayout::os_iyx_osv16) {
return selector.Default(tune_params(1, 1, 4, 4, 1, 1, 1, EXE_MODE_DEFAULT));
}
} else if (is_weight_small_kn(params, output_f)) {
if (params.weights.GetLayout() == WeightsLayout::os_is_yx_osv32_isv2)
return selector.Default(tune_params(1, 1, 4, 2, 1, 1, 1, EXE_MODE_DEFAULT));
else
return selector.Default(tune_params(1, 2, 4, 2, 1, 1, 1, EXE_MODE_DEFAULT));
} else {
if (params.weights.GetLayout() == WeightsLayout::os_iyx_osv16) {
return selector.Default(tune_params(1, 1, 4, 4, 1, 1, 1, EXE_MODE_DEFAULT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,8 @@ void Partitioner::optimize(const std::string& func_name) {
// rewr.add_matcher<ov::npuw::patterns::opt::DQUnpackDictMatMulGQi>(std::ref(ctx));
rewr.add_matcher<ov::npuw::patterns::opt::CompressDictMatMulf32>(std::ref(ctx));
rewr.add_matcher<ov::npuw::patterns::opt::DQParMMGQ>(std::ref(ctx));
// Convert specific convolutions to matmuls
rewr.add_matcher<ov::npuw::patterns::opt::ConvToMatmul>(std::ref(ctx));
rewr.run_on_model(f._model);

// Move Gather to host, if required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "openvino/op/subtract.hpp"
#include "openvino/op/util/op_types.hpp"
#include "openvino/pass/pattern/op/label.hpp" // any_input
#include "openvino/pass/pattern/op/optional.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/util/common_util.hpp"

Expand Down Expand Up @@ -248,7 +249,7 @@ bool DCOFFPassBase::matcher_callback(ov::pass::pattern::Matcher& m) {

auto matched_paramA = std::static_pointer_cast<ov::op::v0::Parameter>(matched_nodeA);
auto element_type = matched_paramA->get_element_type();
if (element_type == ov::element::i4 || element_type == ov::element::i8) {
if (element_type == ov::element::i4 || element_type == ov::element::i8 || element_type == ov::element::nf4) {
LOG_DEBUG("Matched: " << matched_paramA << ", set element type to " << m_dcoff_type);
matched_paramA->set_element_type(m_dcoff_type);

Expand Down Expand Up @@ -296,7 +297,8 @@ bool DCOFFPassBase::matcher_callback(ov::pass::pattern::Matcher& m) {
void DCOFFPassMatMul::build() {
DCOFFPassBase::build();
auto _mmin1 = opp::any_input();
matmul = opp::wrap_type<ov::op::v0::MatMul>({_mmin1, mulply});
cvtopt = opp::optional<ov::op::v0::Convert>({mulply->output(0)});
matmul = opp::wrap_type<ov::op::v0::MatMul>({_mmin1, cvtopt});
register_matcher(std::make_shared<opp::Matcher>(matmul, "TagDCOFFMatMul"),
std::bind(&DCOFFPassMatMul::matcher_callback, this, std::placeholders::_1));
}
Expand All @@ -306,6 +308,13 @@ void DCOFFPassMatMul::reconnect_root_to_convert(ov::pass::pattern::Matcher& m) {
auto& node_to_output = m.get_pattern_value_map();
auto matched_convrt = node_to_output.at(toFP32).get_node_shared_ptr();
auto matched_matmul = node_to_output.at(matmul).get_node_shared_ptr();

auto cvt = std::static_pointer_cast<ov::op::v0::Convert>(matched_convrt);
auto matmul = std::static_pointer_cast<ov::op::v0::MatMul>(matched_matmul);

// NB: In case convert and matmul types don't match
cvt->set_destination_type(matmul->inputs()[1].get_element_type());

matched_matmul->input(1).replace_source_output(matched_convrt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DCOFFPassBase : public ov::pass::MatcherPass {
ov::element::Type m_dcoff_type;
DCOFFParamRef m_params_to;

std::shared_ptr<ov::Node> paramA, paramB, toFP32, mulply;
std::shared_ptr<ov::Node> paramA, paramB, toFP32, mulply, cvtopt;
bool matcher_callback(ov::pass::pattern::Matcher& m);

public:
Expand Down
Loading

0 comments on commit 17e4f12

Please sign in to comment.