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] Add tagged log mechanism for dynamic quantization (#39628)
Mingyu Kim8ff77a113464
diff --git a/src/plugins/intel_gpu/docs/gpu_debug_utils.md b/src/plugins/intel_gpu/docs/gpu_debug_utils.mdindex 8a0c5a85093..bc2b0f1eb60 100644--- a/src/plugins/intel_gpu/docs/gpu_debug_utils.md+++ b/src/plugins/intel_gpu/docs/gpu_debug_utils.md@@ -163,6 +163,43 @@ With `OV_VERBOSE=2` or higher, the pass logs changed graph output ports. Example`Region` is the number of operations selected by the filters, `Forced` counts nodes with logged promotions still present in the model, and `Outputs` counts their promoted ports. Unmatched or unchanged nodes have no `FORCED` entry. Logs describe the graph at the end of this pass, before automatic validation and GPU kernel selection; they do not confirm kernel execution precision.+## Tagged verbose logs++Some verbose logs belong to a feature family and carry a tag right after the regular log prefix, so all decisions of one feature can be collected with a single grep:++```+GPU_Debug: dynamic_quantize.cpp:43:should_skip_execution: [dynquan] dynamicquantize:DynamicQuantize_155332 skipped at runtime: ...+```++In code, use `GPU_DEBUG_TAGGED(level, "tag")` where `level` is one of `COUT`, `INFO`, `LOG`, `TRACE`, `TRACE_DETAIL` (the same levels as `OV_VERBOSE`):++```cpp+GPU_DEBUG_TAGGED(TRACE, "dynquan") << node.id() << " turned off: <reason>" << std::endl;+```++Tag naming convention: a short string literal of lowercase letters and digits only, without separators (no `_` or `-`). Reuse an existing tag for the same family and add new tags to the table below.++| Tag | Feature | Useful `OV_VERBOSE` level |+|---|---|---|+| `dynquan` | Dynamic quantization of fully connected activations | `3` |++## Why was dynamic quantization (not) applied?++Dynamic quantization quantizes the activation of a fully connected (FC) layer with compressed (4/8-bit) weights to int8 at runtime, so that the matmul runs in int8. It is enabled by default, but the plugin decides per -FC and per-inference whether to use it. Every decision is logged with the `dynquan` tag:++```+$ OV_VERBOSE=3 OV_GPU_LOG_TO_FILE=dq.log ./benchmark_app ... # or any application+$ grep "\[dynquan\]" dq.log+```++Example of `grep "\[dynquan\]" dq.log` on an XMX GPU:++```+GPU_Debug: transformations_pipeline.cpp:1942:operator(): [dynquan] __module.lm_head/aten::linear/MatMul turned off: N == 1 (activation quantization is unprofitable; keep weight-only quantization with f16 activation)+GPU_Debug: dynamic_quantize_fully_connected.cpp:159:operator(): [dynquan] __module.model.layers.0.mlp.down_proj/aten::linear/MatMul applied: group_size per-token, dt i8, sym+GPU_Debug: dynamic_quantize.cpp:43:should_skip_execution: [dynquan] dynamicquantize:DynamicQuantize_155332 skipped at runtime: token count 1 <= dynamic_quantization_threshold 64+```+## Dump execution graphThe execution graph (also known as a runtime graph) is a device-specific graph after all transformations applied by the plugin. It is a very usefuldiff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hppindex 85d532663b5..266dd6fa856 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp@@ -111,3 +111,8 @@ static constexpr const char* prefix = "GPU_Debug: ";#define GPU_DEBUG_LOG GPU_DEBUG_LOG_RAW(ov::intel_gpu::LogLevel::LOG)#define GPU_DEBUG_TRACE GPU_DEBUG_LOG_RAW(ov::intel_gpu::LogLevel::TRACE)#define GPU_DEBUG_TRACE_DETAIL GPU_DEBUG_LOG_RAW(ov::intel_gpu::LogLevel::TRACE_DETAIL)++// Tagged log that prints "[tag] " after the regular prefix so that logs of a feature family can be collected with grep.+// level: COUT/INFO/LOG/TRACE/TRACE_DETAIL. tag: string literal of lowercase letters/digits only (e.g. "dynquan").+// Known tags are listed in src/plugins/intel_gpu/docs/gpu_debug_utils.md.+#define GPU_DEBUG_TAGGED(level, tag) GPU_DEBUG_##level << "[" tag "] "diff --git a/src/plugins/intel_gpu/src/graph/dynamic_quantize.cpp b/src/plugins/intel_gpu/src/graph/dynamic_quantize.cppindex 3f9d4fee80f..ab77141e623 100644--- a/src/plugins/intel_gpu/src/graph/dynamic_quantize.cpp+++ b/src/plugins/intel_gpu/src/graph/dynamic_quantize.cpp@@ -40,8 +40,8 @@ static bool should_skip_execution(const dynamic_quantize_node& node, const layou}if (node.get_program().get_config().get_dynamic_quantization_threshold() >= input_batch) {- GPU_DEBUG_TRACE << node.id() << " dyn_quan is turned off: input batch size is too small - " << input_batch << " / "- << node.get_program().get_config().get_dynamic_quantization_threshold() << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << node.id() << " skipped at runtime: token count " << input_batch << " <= dynamic_quantization_threshold "+ << node.get_program().get_config().get_dynamic_quantization_threshold() << std::endl;return true;}diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cppindex 3e21f54733d..df309e00853 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/fully_connected/fully_connected_kernel_bf_tiled.cpp@@ -125,9 +125,9 @@ size_t get_dynamic_quantize_group_size(const fully_connected_params& params) {dynamic_quantization_group_size = zp_group_size;}- GPU_DEBUG_LOG << "FC dyn-quantize by per-token. Actual dyn_quan_group_size(" << dynamic_quantization_group_size << ") : From scale_group_size ("- << scale_group_size << ", zp_group_size(" << zp_group_size << "), zp_group_num(" << zp_group_num << "), ifm_size ("- << get_input_bf_size(params).second << ")" << std::endl;+ GPU_DEBUG_TAGGED(LOG, "dynquan") << params.layerID << " per-token requested. Actual group_size " << dynamic_quantization_group_size+ << " from scale_group_size " << scale_group_size << ", zp_group_size " << zp_group_size << ", zp_group_num "+ << zp_group_num << ", ifm_size " << get_input_bf_size(params).second << std::endl;return (size_t)dynamic_quantization_group_size;}}@@ -138,8 +138,8 @@ size_t get_dynamic_quantize_group_size(const fully_connected_params& params) {dynamic_quantization_group_size = group_size;if (dynamic_quantization_group_size > scale_group_size) {- GPU_DEBUG_TRACE_DETAIL << " Scale group size " << scale_group_size << " is smaller than FC dyn-quan group size "- << dynamic_quantization_group_size << ". Reduce FC dyn-quan group size to scale size." << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << params.layerID << " scale_group_size " << scale_group_size << " is smaller than group_size "+ << dynamic_quantization_group_size << ". Reduce group_size to scale_group_size." << std::endl;dynamic_quantization_group_size = scale_group_size;}@@ -154,17 +154,20 @@ bool should_dynamic_quantize(const fully_connected_params& params) {size_t dynamic_quantization_group_size = get_dynamic_quantize_group_size(params);if (params.inputs[0].GetFirstElementOffset() != 0) {+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << params.layerID << " turned off: input has non-zero offset (padding)" << std::endl;return false;}if (dynamic_quantization_group_size < min_quantize_grp_size) {- GPU_DEBUG_TRACE_DETAIL << "Set dynamic_quantize_group_size " << dynamic_quantization_group_size << " is smaller than minimum supported size 32"- << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << params.layerID << " turned off: group_size " << dynamic_quantization_group_size+ << " is smaller than minimum supported size " << min_quantize_grp_size << std::endl;return false;}const size_t scale_group_size = get_scale_group_size(params);if ((scale_group_size % min_quantize_grp_size) != 0) {+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << params.layerID << " turned off: scale_group_size " << scale_group_size << " is not a multiple of "+ << min_quantize_grp_size << std::endl;return false;}@@ -174,17 +177,22 @@ bool should_dynamic_quantize(const fully_connected_params& params) {if ((scale_group_size % simd == 0) && (input_f % dynamic_quantization_group_size == 0) && (params.is_shape_agnostic || input_b > min_slm_size) &¶ms.inputs[0].GetDType() == Datatype::F16 && is_weight_dyn_quantizable(params)) {- GPU_DEBUG_TRACE_DETAIL << " Dynamic quantizing for FC : scale_group_size: " << scale_group_size- << ", Dyn-quan group size: " << dynamic_quantization_group_size- << ", Type(I:" << kernel_selector::toString(params.inputs[0].GetDType())- << ", O:" << kernel_selector::toString(params.outputs[0].GetDType())- << ", W:" << kernel_selector::toString(params.weights.GetDType())- << "), Format(W:" << kernel_selector::toString(params.weights.GetLayout()) << ") B: " << params.inputs[0].Batch().v- << ", F: " << params.inputs[0].Feature().v << ", Y: " << params.inputs[0].Y().v << ", X: " << params.inputs[0].X().v- << ", input_b: " << input_b << ", input_f: " << input_f << std ::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << params.layerID << " applied: scale_group_size " << scale_group_size << ", group_size "+ << dynamic_quantization_group_size << ", Type(I:" << kernel_selector::toString(params.inputs[0].GetDType())+ << ", O:" << kernel_selector::toString(params.outputs[0].GetDType())+ << ", W:" << kernel_selector::toString(params.weights.GetDType())+ << "), Format(W:" << kernel_selector::toString(params.weights.GetLayout())+ << ") B: " << params.inputs[0].Batch().v << ", F: " << params.inputs[0].Feature().v+ << ", Y: " << params.inputs[0].Y().v << ", X: " << params.inputs[0].X().v << ", input_b: " << input_b+ << ", input_f: " << input_f << std ::endl;return true;}+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << params.layerID << " turned off: requires scale_group_size % " << simd << " == 0 (" << scale_group_size+ << "), input_f % group_size == 0 (" << input_f << " / " << dynamic_quantization_group_size+ << "), shape-agnostic or input_b > " << min_slm_size << " (input_b " << input_b << "), f16 input ("+ << kernel_selector::toString(params.inputs[0].GetDType()) << ") and quantizable weight ("+ << kernel_selector::toString(params.weights.GetDType()) << ")" << std::endl;return false;}diff --git a/src/plugins/intel_gpu/src/plugin/transformations/dynamic_quantize_fully_connected.cpp b/src/plugins/intel_gpu/src/plugin/transformations/dynamic_quantize_fully_connected.cppindex c02da98a41d..52ac9a20e1c 100644--- a/src/plugins/intel_gpu/src/plugin/transformations/dynamic_quantize_fully_connected.cpp+++ b/src/plugins/intel_gpu/src/plugin/transformations/dynamic_quantize_fully_connected.cpp@@ -78,8 +78,8 @@ DynamicQuantizeFullyConnected::DynamicQuantizeFullyConnected(uint64_t group_sizeconst size_t wei_scale_group_size = scale_group_count == 0 ? 0 : innermost_size / scale_group_count;const size_t required_group_size = std::min(wei_zp_group_size, wei_scale_group_size);if (adj_group_size > required_group_size) {- GPU_DEBUG_LOG << "Dynamic quantization: adjusting group_size " << adj_group_size- << " to wei_zp_group_size " << wei_zp_group_size << " and wei_scale_group_size " << wei_scale_group_size << std::endl;+ GPU_DEBUG_TAGGED(LOG, "dynquan") << m_fc->get_friendly_name() << " adjusting group_size " << adj_group_size << " to wei_zp_group_size "+ << wei_zp_group_size << " and wei_scale_group_size " << wei_scale_group_size << std::endl;adj_group_size = required_group_size;}const bool is_per_token = adj_group_size == innermost_size;@@ -87,21 +87,22 @@ DynamicQuantizeFullyConnected::DynamicQuantizeFullyConnected(uint64_t group_sizeconfig.precomputed_reduction_dt = element::i32; // it supports i32 only nowconfig.precomputed_reduction = true;} else {- GPU_DEBUG_LOG << "Dynamic quantization: precompute is turned off because group_size " << adj_group_size- << " is not aligned with required_group_size " << required_group_size << std::endl;+ GPU_DEBUG_TAGGED(LOG, "dynquan") << m_fc->get_friendly_name() << " precomputed_reduction is turned off: group_size " << adj_group_size+ << " is not aligned with required_group_size " << required_group_size << std::endl;}}if (adj_group_size != UINT64_MAX &&(adj_group_size == 0 || (innermost_size % adj_group_size != 0 && innermost_size > adj_group_size))) {- GPU_DEBUG_TRACE << "Dynamic quantization: shape is not aligned with group size " << innermost_size << " / " << adj_group_size << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << m_fc->get_friendly_name() << " turned off: K " << innermost_size << " is not aligned with group_size "+ << adj_group_size << std::endl;return false;}const auto rank = m_fc->get_input_partial_shape(0).size();if (adj_group_size < 32) {- GPU_DEBUG_LOG << "Dynamic quantization: quantized activation by group size " << adj_group_size- << " is not supported by onednn matmul if it is less than 32" << std::endl;+ GPU_DEBUG_TAGGED(LOG, "dynquan") << m_fc->get_friendly_name() << " turned off: group_size " << adj_group_size+ << " < 32 is not supported by oneDNN matmul" << std::endl;return false;}@@ -155,6 +156,11 @@ DynamicQuantizeFullyConnected::DynamicQuantizeFullyConnected(uint64_t group_sizem_fc->get_transpose_b_scale(),m_fc->get_transpose_b_zp());+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << m_fc->get_friendly_name() << " applied: group_size "+ << (adj_group_size == UINT64_MAX ? std::string("per-token") : std::to_string(adj_group_size)) << ", dt "+ << config.quantization_dt << (config.quantization_type == QuantizationType::Asymmetric ? ", asym" : ", sym")+ << (config.precomputed_reduction ? ", precomputed_reduction" : "") << std::endl;+ov::replace_node(m_fc, new_fc);new_fc->set_friendly_name(m_fc->get_friendly_name());diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cppindex 3d76b46e9f2..fa2577affc2 100644--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp@@ -2059,7 +2059,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {for (size_t i = 0 ; i < root->get_input_node_shared_ptr(0)->get_output_size(); ++i) {if (root->get_input_node_shared_ptr(0)->get_output_element_type(i) == ov::element::Type_t::f32) {- GPU_DEBUG_TRACE << root->get_friendly_name() << " dyn_quan is turned off: input type is not supported" << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << root->get_friendly_name() << " turned off: f32 input is not supported" << std::endl;return true;}}@@ -2078,7 +2078,8 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {const auto& input_shape = root->get_input_partial_shape(0);const size_t input_rank = input_shape.size();if (input_rank > 3) {- GPU_DEBUG_TRACE << root->get_friendly_name() << " dyn_quan is turned off: input rank is not supported" << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan")+ << root->get_friendly_name() << " turned off: input rank " << input_rank << " > 3 is not supported" << std::endl;return true;}@@ -2089,24 +2090,24 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {const size_t innermost_size = weight_shape[k_axis].get_length();const size_t simd = 16;if (innermost_size < 32 || (innermost_size % (simd * 2) != 0)) {- GPU_DEBUG_TRACE << root->get_friendly_name()- << " dyn_quan is turned off: inner shape is not supported. It is too small or not aligned with simd*2 "- << innermost_size << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << root->get_friendly_name() << " turned off: K " << innermost_size+ << " is smaller than 32 or not aligned to simd*2 (" << simd * 2 << ")" << std::endl;return true;}// AZP does not support grouped size dyn-quanGPU_DEBUG_IF(asymmetric_dyn_quant && (adj_group_size != UINT64_MAX)) {- GPU_DEBUG_TRACE << root->get_friendly_name() << " dyn_quan is turned off: asym quantization does not support grouped quantization" <<- " ('DynamicQuantizeAsym' is enabled with grouped size dyn-quan)" << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan")+ << root->get_friendly_name() << " turned off: asym_dynamic_quantization does not support grouped quantization (group_size "+ << adj_group_size << ")" << std::endl;return true;}bool has_wzp = root->get_input_size() > 4;if (has_wzp && !cldnn::one_of(root->get_input_element_type(4), {ov::element::i8, ov::element::u8, ov::element::i4, ov::element::u4})) {- GPU_DEBUG_TRACE << root->get_friendly_name() << " dyn_quan is turned off:"- " unsupported weight zp type: " << root->get_input_element_type(4) << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan")+ << root->get_friendly_name() << " turned off: unsupported weight zp type " << root->get_input_element_type(4) << std::endl;return true;}@@ -2114,9 +2115,10 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {// the cost of dynamically quantizing its activationconst auto& n_dim = weight_shape[n_axis];if (n_dim.is_static() && n_dim.get_length() == 1) {- GPU_DEBUG_TRACE << root->get_friendly_name() << " dyn_quan is turned off:"- " compressed weight with N==1 (activation quantization is unprofitable;"- " keep weight-only quantization with f16 activation)" << std::endl;+ GPU_DEBUG_TAGGED(TRACE, "dynquan") << root->get_friendly_name()+ << " turned off: N == 1 (activation quantization is unprofitable;"+ " keep weight-only quantization with f16 activation)"+ << std::endl;return true;}@@ -2125,9 +2127,12 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {const bool model_allows_group_size = dynamic_quantization_group_size_max >= dynamic_quantization_group_size;if (!model_allows_group_size) {- GPU_DEBUG_INFO << "dyn_quan is turned off because group_size is larger than max size "- << dynamic_quantization_group_size << "/" << dynamic_quantization_group_size_max << std::endl;+ GPU_DEBUG_TAGGED(INFO, "dynquan") << "turned off for all FCs: group_size " << dynamic_quantization_group_size+ << " is larger than dynamic_quantization_group_size_max " << dynamic_quantization_group_size_max << std::endl;} else {+ if (dynamic_quantization_group_size == 0) {+ GPU_DEBUG_TAGGED(INFO, "dynquan") << "turned off for all FCs: dynamic_quantization_group_size is 0" << std::endl;+ }manager.register_pass<ov::intel_gpu::DynamicQuantizeFullyConnected>(dynamic_quantization_group_size,asymmetric_dyn_quant,precomputed_reduction,@@ -2136,6 +2141,10 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {// Deduplicate identical DynamicQuantize nodes sharing same inputmanager.register_pass<ov::pass::SharedOpOptimization>();}+ } else {+ GPU_DEBUG_TAGGED(INFO, "dynquan") << "graph pass is not used (no XMX or oneDNN disabled); fully_connected_bf_tiled kernel "+ << "quantizes activations internally with group_size " << config.get_dynamic_quantization_group_size()+ << std::endl;}// Remove Pad in front of MaxPool if both the pads_begin and pads_end are zero.