code: def convert_attributions_proto_to_dict(
      attributions_for_slice: metrics_for_slice_pb2.AttributionsForSlice,
      model_name: Optional[str] = None,
  ) -> Tuple[
      slicer.SliceKeyType, Optional[view_types.AttributionsByOutputName]
  ]:
      """Converts attributions proto to dict."""
      model_metrics_map = {}
      default_model_name = None
      if attributions_for_slice.attributions_keys_and_values:
          for kv in attributions_for_slice.attributions_keys_and_values:
              current_model_name = kv.key.model_name
              if current_model_name not in model_metrics_map:
                  model_metrics_map[current_model_name] = {}
              output_name = kv.key.output_name
              if (
                  output_name
                  not in model_metrics_map[current_model_name]
              ):
                  model_metrics_map[current_model_name][
                      output_name
                  ] = {}
              sub_key_metrics_map = model_metrics_map[
                  current_model_name
              ][output_name]
              if kv.key.HasField("sub_key"):
                  sub_key_id = str(
                      metric_types.SubKey.from_proto(kv.key.sub_key)
                  )
              else:
                  sub_key_id = ""
              if sub_key_id not in sub_key_metrics_map:
                  sub_key_metrics_map[sub_key_id] = {}
              if kv.key.is_diff:
                  if default_model_name is None:
                      default_model_name = current_model_name
                  elif default_model_name != current_model_name:
                      # Setting '' to possibly trigger no match found ValueError below.
                      default_model_name = ""
                  metric_name = "{}_diff".format(kv.key.name)
              else:
                  metric_name = kv.key.name
              attributions = {}
              for k in kv.values:
                  attributions[k] = json_format.MessageToDict(
                      kv.values[k]
                  )
              sub_key_metrics_map[sub_key_id][
                  metric_name
              ] = attributions
  
      metrics_map = None
      keys = list(model_metrics_map)
      tmp_model_name = model_name or default_model_name
      if tmp_model_name in model_metrics_map:
          # Use the provided model name if there is a match.
          metrics_map = model_metrics_map[tmp_model_name]
      elif (not tmp_model_name) and len(keys) == 1:
          # Show result of the only model if no model name is specified.
          metrics_map = model_metrics_map[keys[0]]
      elif keys:
          # No match found.
          raise ValueError(
              "Fail to find attribution metrics for model name: %s . "
              "Available model names are [%s]"
              % (model_name, ", ".join(keys))
          )
  
      return (
          slicer.deserialize_slice_key(
              attributions_for_slice.slice_key
          ),
          metrics_map,
      )
  
imports: import json
  import os
  from typing import Any, Dict, List, Optional, Tuple, Union
  from absl import logging
  from tensorflow_model_analysis.metrics import example_count
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import weighted_example_count
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.view import view_types
  from google.protobuf import json_format
label_desc: Use image node_id 12 for calling a global function with example usage: convert_attributions_proto_to_dict(attributions_for_slice, model_name) and returns: slicer,  metrics_map