code: def test_grads_scalar_handler(dummy_model_factory, norm_mock):
      model = dummy_model_factory(
          with_grads=True, with_frozen_layer=False
      )
  
      # define test wrapper to test with and without optional tag
      def _test(tag=None):
          wrapper = GradsScalarHandler(
              model, reduction=norm_mock, tag=tag
          )
          mock_logger = MagicMock(spec=TensorboardLogger)
          mock_logger.writer = MagicMock()
  
          mock_engine = MagicMock()
          mock_engine.state = State()
          mock_engine.state.epoch = 5
          norm_mock.reset_mock()
  
          wrapper(mock_engine, mock_logger, Events.EPOCH_STARTED)
  
          tag_prefix = f"{tag}/" if tag else ""
  
          mock_logger.writer.add_scalar.assert_has_calls(
              [
                  call(tag_prefix + "grads_norm/fc1/weight", ANY, 5),
                  call(tag_prefix + "grads_norm/fc1/bias", ANY, 5),
                  call(tag_prefix + "grads_norm/fc2/weight", ANY, 5),
                  call(tag_prefix + "grads_norm/fc2/bias", ANY, 5),
              ],
              any_order=True,
          )
          assert mock_logger.writer.add_scalar.call_count == 4
          assert norm_mock.call_count == 4
  
      _test()
      _test(tag="tag")
  
imports: import math
  import os
  from unittest.mock import ANY, call, MagicMock, patch
  import pytest
  import torch
  from ignite.contrib.handlers.tensorboard_logger import global_step_from_engine, GradsHistHandler, GradsScalarHandler, OptimizerParamsHandler, OutputHandler, TensorboardLogger, WeightsHistHandler, WeightsScalarHandler
  from ignite.engine import Engine, Events, State
label_desc: Use image node_id 18 for calling a global function with example usage: test_grads_scalar_handler(dummy_model_factory, norm_mock) without return types