Skip to content

Commit

Permalink
Merge branch 'master' into msvc_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mryzhov authored Sep 12, 2024
2 parents b9e247c + 4785767 commit 9877926
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ jobs:
tar -xzf doxygen-$DOXY_VER.linux.bin.tar.gz
echo "$(pwd)/doxygen-$DOXY_VER/bin/" >> $GITHUB_PATH
- name: Validate benchmarks files
run: |
python3 docs/scripts/tests/validate_benchmarks.py docs/sphinx_setup/_static/benchmarks_files/
- name: Build docs
run: |
rm -rf build && mkdir build && cd build
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
alabaster==0.7.14
atomicwrites==1.4.0
attrs==22.1.0
attrs==22.2.0
Babel==2.11.0
beautifulsoup4==4.9.3
breathe==4.35.0
Expand All @@ -14,6 +14,7 @@ importlib-metadata==4.8.0
iniconfig==1.1.1
ipython==8.10.0
Jinja2==3.1.4
jsonschema==4.23.0
lxml>=4.9.2
MarkupSafe==2.1.1
mistune==2.0.3
Expand Down
80 changes: 80 additions & 0 deletions docs/scripts/tests/validate_benchmarks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import json
import requests
import argparse
from jsonschema import Draft7Validator
import sys


def load_json(file_path):
"""Load JSON data from a file."""
with open(file_path, 'r') as file:
return json.load(file)

def validate_json_files(benchmarks_dir):
"""Validate all JSON files in the 'data' subdirectory against the schema."""
# Define the path to the schema file
schema_path = os.path.join(benchmarks_dir, 'schema', 'graph-data-schema.json')

# Fetch the schema
schema = load_json(schema_path)
validator = Draft7Validator(schema)

# Define the path to the 'data' subdirectory containing the JSON files
data_dir = os.path.join(benchmarks_dir, 'data')

# Get all JSON files in the directory
json_files = [f for f in os.listdir(data_dir) if f.endswith('.json')]

invalid_count = 0 # Track the number of invalid JSON objects

# Iterate through each JSON file and validate
for json_file in json_files:
json_file_path = os.path.join(data_dir, json_file)
print(f"Validating {json_file_path}...")

try:
json_data = load_json(json_file_path)
except Exception as e:
print(f"Error loading JSON file {json_file}: {e}")
invalid_count += 1
continue

# Check if the JSON data is a list of objects
if isinstance(json_data, list):
# Iterate through each object in the list
for idx, item in enumerate(json_data):
errors = list(validator.iter_errors(item))
if errors:
print(f"Validation failed for object {idx} in {json_file}:")
for error in errors:
print(f"Error: {error.message}")
invalid_count += 1
else:
# Validate the JSON object itself if it's not a list
errors = list(validator.iter_errors(json_data))
if errors:
print(f"Validation failed for {json_file}:")
for error in errors:
print(f"Error: {error.message}")
invalid_count += 1

return invalid_count

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Validate JSON files against a schema.")
parser.add_argument(
"benchmarks_dir",
type=str,
help="Path to the directory containing the benchmark JSON files"
)
args = parser.parse_args()
invalid_jsons = validate_json_files(args.benchmarks_dir)

if invalid_jsons > 0:
print(f"{invalid_jsons} JSON object(s) are invalid. Failing the build.")
sys.exit(1) # Exit with a non-zero status to fail Jenkins/GitHub Actions
else:
print("All JSON objects are valid.")
sys.exit(0) # Exit with zero status for success

Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,39 @@ bool all_same_value(const T* qp_ptr, size_t size) {
});
}

std::shared_ptr<ov::Node> scalar_parameter(std::shared_ptr<ov::op::v0::Constant> qp) {
template <typename T>
std::shared_ptr<ov::op::v0::Constant>
create_scalar_constant(const std::shared_ptr<ov::op::v0::Constant>& qp) {
auto type = qp->get_element_type();
size_t size = ov::shape_size(qp->get_shape());
bool has_same_value = false;
switch (type) {
case ov::element::u8:
has_same_value = all_same_value(static_cast<const uint8_t*>(qp->get_data_ptr()), size);
break;
case ov::element::i8:
has_same_value = all_same_value(static_cast<const int8_t*>(qp->get_data_ptr()), size);
break;
case ov::element::f16:
has_same_value = all_same_value(static_cast<const ov::float16*>(qp->get_data_ptr()), size);
break;
case ov::element::f32:
has_same_value = all_same_value(static_cast<const float*>(qp->get_data_ptr()), size);
break;
default: OPENVINO_THROW("[GPU] Can't pad quantization parameter for ", type, " element type");
auto shape = qp->get_shape();
if (all_same_value(static_cast<const T*>(qp->get_data_ptr()), ov::shape_size(shape))) {
ov::Shape new_shape(shape.size(), 1);
ov::Tensor new_tensor(type, new_shape);
auto new_qp = std::make_shared<ov::op::v0::Constant>(new_tensor);
auto val = qp->get_vector<T>()[0];
new_qp->fill_data(type, val);
return new_qp;
}
return nullptr;
}

if (has_same_value) {
auto new_shape = qp->get_shape();
std::fill(new_shape.begin(), new_shape.end(), 1);
ov::Tensor new_qp(type, new_shape);
return std::make_shared<ov::op::v0::Constant>(new_qp);
std::shared_ptr<ov::Node> scalar_parameter(std::shared_ptr<ov::op::v0::Constant> qp) {
auto type = qp->get_element_type();
std::shared_ptr<ov::op::v0::Constant> new_qp = nullptr;

if (type == ov::element::u8) {
new_qp = create_scalar_constant<uint8_t>(qp);
} else if (type == ov::element::i8) {
new_qp = create_scalar_constant<int8_t>(qp);
} else if (type == ov::element::f16) {
new_qp = create_scalar_constant<ov::float16>(qp);
} else if (type == ov::element::f32) {
new_qp = create_scalar_constant<float>(qp);
} else {
OPENVINO_THROW("[GPU] Can't pad quantization parameter for ", type, " element type");
}

return nullptr;
return new_qp;
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,61 @@ TEST_F(TransformationTestsF, BroadcastAndPadZeroPointBuffers_3) {
}
}

TEST_F(TransformationTestsF, BroadcastAndPadZeroPointBuffers_scalar_wzp) {
ov::Strides strides{1, 1};
ov::Strides dilations{1, 1};
ov::CoordinateDiff pads_begin{0, 0};
ov::CoordinateDiff pads_end{0, 0};
{
auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::PartialShape{ 1, 8, 11, 12 });
auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{ 8, 8, 3, 3 }, { 1 });
auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
auto azp_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{ 1, 1, 1, 1 }, { 1 });
auto wzp_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{ 1, 8, 1, 1 }, { 12 });
auto compensation = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{ 1, 8, 1, 1 }, { 1 });
auto conv = std::make_shared<ov::intel_gpu::op::Convolution>(input,
weights_const,
no_bias,
azp_const,
wzp_const,
compensation,
strides,
pads_begin,
pads_end,
dilations,
-1,
ov::op::PadType::EXPLICIT,
ov::element::f32);

model = std::make_shared<ov::Model>(ov::NodeVector{ conv }, ov::ParameterVector{ input });
manager.register_pass<BroadcastAndPadZeroPointBuffers>(8, true);
}
{
auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::PartialShape{ 1, 8, 11, 12 });
auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{ 8, 8, 3, 3 }, { 1 });
auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
auto azp_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{ 1, 8, 1, 1 }, { 1 });
auto wzp_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{ 1, 1, 1, 1 }, { 12 });
auto compensation = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{ 1, 8, 1, 1 }, { 1 });
auto conv = std::make_shared<ov::intel_gpu::op::Convolution>(input,
weights_const,
no_bias,
azp_const,
wzp_const,
compensation,
strides,
pads_begin,
pads_end,
dilations,
-1,
ov::op::PadType::EXPLICIT,
ov::element::f32);

model_ref = std::make_shared<ov::Model>(ov::NodeVector{ conv }, ov::ParameterVector{ input });
}
comparator.enable(FunctionsComparator::CmpValues::CONST_VALUES);
}

} // namespace intel_gpu
} // namespace test
} // namespace ov

0 comments on commit 9877926

Please sign in to comment.