code: def _on_backward_end(original_fn, recorder, *args, **kwargs):
      def count_zeros(gradient):
          n = gradient.data.data.cpu().numpy()
          return n.size - np.count_nonzero(n)
  
      original_fn(recorder, *args, **kwargs)
  
      if not PatchFastaiV1._current_task:
          return
  
      # noinspection PyBroadException
      try:
          gradients = [
              x.grad.clone().detach().cpu()
              for x in recorder.learn.model.parameters()
              if x.grad is not None
          ]
          if len(gradients) == 0:
              return
  
          # TODO: Check computation!
          gradient_stats = np.array(
              [
                  (
                      x.data.norm(),
                      count_zeros(x),
                      x.data.mean(),
                      np.median(x.data),
                      x.data.max(),
                      x.data.min(),
                  )
                  for x in gradients
              ]
          )
          stats_report = dict(
              avg_norm=np.mean(gradient_stats[:, 0]),
              median_norm=np.median(gradient_stats[:, 0]),
              max_norm=np.max(gradient_stats[:, 0]),
              min_norm=np.min(gradient_stats[:, 0]),
              num_zeros=gradient_stats[:, 1].sum(),
              avg_gradient=gradient_stats[:, 2].mean(),
              median_gradient=np.median(gradient_stats[:, 3]),
              max_gradient=gradient_stats[:, 4].max(),
              min_gradient=gradient_stats[:, 5].min(),
          )
  
          logger = PatchFastaiV1._current_task.get_logger()
          iteration = kwargs.get("iteration", 0)
          for name, val in stats_report.items():
              logger.report_scalar(
                  title="model_stats_gradients",
                  series=name,
                  value=val,
                  iteration=iteration,
              )
      except Exception:
          pass
  
imports: import sys
  import numpy
  from clearml.utilities.version import Version
  from .None import _patched_call
  from .tensorflow_bind import WeightsGradientHistHelper
  from ..import_bind import PostImportHookPatching
  from ...debugging.log import LoggerRoot
  from .tensorflow_bind import IsTensorboardInit
label_desc: Use image node_id 4 for calling the PatchFastaiV1 obj's underlying member method code with example usage: obj._on_backward_end(original_fn, recorder) and returns: unknown