OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU][debug] THROW if VALIDATE_OUTPUT_BUFFER=2 (#38553)
Mingyu Kimcec913571f1d
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hppindex ca4e2e85782..f1a73b0c286 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp@@ -220,7 +220,7 @@ static constexpr Property<size_t, ov::PropertyMutability::RW> usm_policy{"GPU_USstatic constexpr Property<ShapePredictor::Settings, ov::PropertyMutability::RW> shape_predictor_settings{"GPU_SHAPE_PREDICTOR_SETTINGS"};static constexpr Property<std::vector<std::string>, ov::PropertyMutability::RW> load_dump_raw_binary{"GPU_LOAD_DUMP_RAW_BINARY"};static constexpr Property<bool, ov::PropertyMutability::RW> could_use_flashattn_v2{"GPU_COULD_USE_FLASHATTN_V2"};-static constexpr Property<bool, ov::PropertyMutability::RW> validate_output_buffer{"GPU_VALIDATE_OUTPUT_BUFFER"};+static constexpr Property<int, ov::PropertyMutability::RW> validate_output_buffer{"GPU_VALIDATE_OUTPUT_BUFFER"};static constexpr Property<float, ov::PropertyMutability::RW> mem_pool_util_threshold{"GPU_MEM_POOL_UTIL_THRESHOLD"};static constexpr Property<bool, ov::PropertyMutability::RW> dump_src_after_exec{"GPU_DUMP_SRC_TENSORS_AFTER_EXEC"};static constexpr Property<bool, ov::PropertyMutability::RW> allow_bypass_xattn{"GPU_ALLOW_BYPASS_XATTN_EXEC"};diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inlindex 65ac9d59ff6..6025b6136ec 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl@@ -122,7 +122,7 @@ OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, disable_memory_reuse, false, "Disable memoOV_CONFIG_DEBUG_OPTION(ov::intel_gpu, disable_runtime_skip_reorder, false, "Disable skip reorder optimization applied in runtime")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, load_dump_raw_binary, std::vector<std::string>{}, "List of layers to load raw binary")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dry_run_path, "", "Enables mode which partially compiles a model and stores runtime model into specified directory")-OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, validate_output_buffer, false, "Validate output buffers of all layers which have fp16 data-type to find 'inf' and 'nan' value.")+OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, validate_output_buffer, 0, "Validate output buffers of all layers which have fp16 data-type to find 'inf' and 'nan' value. If set to 2, an exception will be thrown on detection.")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dynamic_quantization_bisect, std::numeric_limits<int64_t>::max(), "Apply dynamic quantization only up to this count")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dynamic_quantization_single, -1, "Apply dynamic quantization only to this index")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, network_marker, false, "Insert named OpenCL marker kernels at network execution start/finish for CLIntercept tracing")diff --git a/src/plugins/intel_gpu/src/graph/debug_helper.cpp b/src/plugins/intel_gpu/src/graph/debug_helper.cppindex 2382f5c9d5c..fd9fd9b19a7 100644--- a/src/plugins/intel_gpu/src/graph/debug_helper.cpp+++ b/src/plugins/intel_gpu/src/graph/debug_helper.cpp@@ -61,8 +61,9 @@ size_t get_x_pitch(const layout& layout) {}template <class T>-std::pair<float, float> __validate_data_range(memory::ptr mem, stream& stream, const layout& data_layout, std::string& info) {- if (!mem) {+std::pair<float, float> __validate_data_range(memory::ptr mem, stream& stream, const layout& data_layout, std::string& info, bool throw_for_inf_nan) {+ if (!mem || mem->size() == 0 || data_layout.bytes_count() == 0) {+ GPU_DEBUG_INFO << "empty tensor : " << info << " (n=0)" << std::endl;return {0.0f, 0.0f};}@@ -83,7 +84,9 @@ std::pair<float, float> __validate_data_range(memory::ptr mem, stream& stream, cauto val = convert_element(mem_ptr[i]);if (std::isinf(val) || std::isnan(val)) {std::string err_str = std::isinf(val) ? "inf" : "nan";- GPU_DEBUG_COUT << err_str << " WAS FOUND: " << info << " *********************" << std::endl;+ GPU_DEBUG_COUT << "[VALIDATE_OUTPUT_BUFFER: ERROR] " << err_str << " WAS FOUND: " << info << " *********************" << std::endl;+ if (throw_for_inf_nan)+ OPENVINO_THROW("Invalid value found in output buffer: " + info);return {0.0f, 0.0f};}if (val > val_max) {@@ -108,7 +111,9 @@ std::pair<float, float> __validate_data_range(memory::ptr mem, stream& stream, cauto val = convert_element(mem_ptr[input_it]);if (std::isinf(val) || std::isnan(val)) {std::string err_str = std::isinf(val) ? "inf" : "nan";- GPU_DEBUG_COUT << err_str << " WAS FOUND: " << info << " *********************" << std::endl;+ GPU_DEBUG_COUT << "[VALIDATE_OUTPUT_BUFFER: ERROR] " << err_str << " WAS FOUND: " << info << " *********************" << std::endl;+ if (throw_for_inf_nan)+ OPENVINO_THROW("Invalid value found in output buffer: " + info);return {0.0f, 0.0f};}if (val > val_max) {@@ -135,22 +140,22 @@ std::pair<float, float> __validate_data_range(memory::ptr mem, stream& stream, creturn {val_min, val_max};}-std::pair<float, float> validate_data_range(memory::ptr mem, stream& stream, const layout& data_layout, std::string& info) {+std::pair<float, float> validate_data_range(memory::ptr mem, stream& stream, const layout& data_layout, std::string& info, bool throw_for_inf_nan) {auto data_type = data_layout.data_type;if (data_type == cldnn::data_types::f32) {- return __validate_data_range<float>(mem, stream, data_layout, info);+ return __validate_data_range<float>(mem, stream, data_layout, info, throw_for_inf_nan);}if (data_type == cldnn::data_types::f16) {- return __validate_data_range<ov::float16>(mem, stream, data_layout, info);+ return __validate_data_range<ov::float16>(mem, stream, data_layout, info, throw_for_inf_nan);}if (data_type == cldnn::data_types::bf16) {- return __validate_data_range<ov::bfloat16>(mem, stream, data_layout, info);+ return __validate_data_range<ov::bfloat16>(mem, stream, data_layout, info, throw_for_inf_nan);}if (data_type == cldnn::data_types::i8) {- return __validate_data_range<int8_t>(mem, stream, data_layout, info);+ return __validate_data_range<int8_t>(mem, stream, data_layout, info, throw_for_inf_nan);}if (data_type == cldnn::data_types::u8) {- return __validate_data_range<uint8_t>(mem, stream, data_layout, info);+ return __validate_data_range<uint8_t>(mem, stream, data_layout, info, throw_for_inf_nan);}GPU_DEBUG_INFO << "Unsupport data type for validating data range " << data_type << std::endl;return {0.0f, 0.0f};@@ -541,11 +546,12 @@ NodeDebugHelper::~NodeDebugHelper() {const auto& config = m_network.get_config();if (config.get_validate_output_buffer() && !m_network.is_internal()) {+ const bool throw_for_error = config.get_validate_output_buffer() >= 2;m_stream.finish(); // Wait for stream completion before checking output buffersfor (size_t i = 0; i < m_inst.outputs_memory_count(); i++) {auto output_mem = m_inst.output_memory_ptr(i);std::string info = m_inst.id() + "(" + std::to_string(i) + ") at iteration " + std::to_string(m_network.get_current_iteration_num());- validate_data_range(output_mem, m_stream, m_inst.get_output_layout(i), info);+ validate_data_range(output_mem, m_stream, m_inst.get_output_layout(i), info, throw_for_error);}// FP16 mantissa loss early warning for Sin/Cos activation inputs@@ -557,12 +563,14 @@ NodeDebugHelper::~NodeDebugHelper() {auto input_layout = dep.first->get_output_layout(dep.second);if (input_layout.data_type == cldnn::data_types::f16) {std::string input_info = m_inst.id() + " (sincos_input) at iteration " + std::to_string(m_network.get_current_iteration_num());- auto [val_min, val_max] = validate_data_range(input_mem, m_stream, input_layout, input_info);+ auto [val_min, val_max] = validate_data_range(input_mem, m_stream, input_layout, input_info, throw_for_error);float abs_max = std::max(std::abs(val_min), std::abs(val_max));constexpr float threshold = 1024.0f;if (abs_max >= threshold) {- GPU_DEBUG_COUT << "*** FP16 MANTISSA LOSS WARNING *** : " << m_inst.id() << " input max(abs)=" << abs_max << " (threshold=" << threshold+ GPU_DEBUG_COUT << "[VALIDATE_OUTPUT_BUFFER: WARNING] *** FP16 MANTISSA LOSS WARNING *** : " << m_inst.id() << " input max(abs)=" << abs_max << " (threshold=" << threshold<< ")" << " — Sin/Cos output will lose fractional precision" << std::endl;+ if (throw_for_error)+ OPENVINO_THROW("FP16 mantissa loss warning: " + m_inst.id() + " input max(abs)=" + std::to_string(abs_max) + " (threshold=" + std::to_string(threshold) + ") — Sin/Cos output will lose fractional precision");}}}