code: def _quant_dequant_gradient_hook(
      self, target_space: QuantizationTargetSpace
  ) -> None:
      def quant_dequant_gradient(module: nn.Module, grad_output):
          tracked_max = torch.tensor(
              1.0 + 0.5 / (2**target_space.quant_bits - 1)
          ).to(grad_output[0].device)
          tracked_min = torch.tensor(
              0 - 0.5 / (2**target_space.quant_bits - 1)
          ).to(grad_output[0].device)
          scale, zero_point = init_scale_zp(
              tracked_max,
              tracked_min,
              target_space.qmax,
              target_space.qmin,
              "affine",
          )
          new_grad_output = []
          for g_o in grad_output:
              grad_o = torch.abs(g_o.clone().detach())
              dim_lis = list(range(len(grad_o.shape)))
              dim_lis.pop(0)
              max_grad = torch.amax(grad_o, dim=dim_lis, keepdim=True)
              # generate uniform noise
              uniform_k = torch.zeros_like(max_grad).to(g_o.device)
              N_k = uniform_k.uniform_(-0.5, 0.5) / (
                  2 ** (target_space.quant_bits) - 1
              )
              q_grad_o = g_o / (2 * max_grad) + 0.5 + N_k
              quantized_grad = zero_point + q_grad_o / scale
              quantized_grad = torch.round(
                  torch.clamp(
                      quantized_grad,
                      target_space.qmin,
                      target_space.qmax,
                  )
              )
              dequantized_grad = (quantized_grad - zero_point) * scale
              new_grad_output.append(
                  (dequantized_grad - 0.5) * 2 * max_grad
              )
  
          return tuple(new_grad_output)
  
      target_space._wrapper.module.register_full_backward_pre_hook(
          quant_dequant_gradient
      )
  
imports: from __future__ import annotations
  import logging
  from typing import List, Dict, Union, overload
  import torch
  import torch.nn
  from torch import Tensor
  from nni.common.version import torch_version_is_2
  from ..base.compressor import Compressor, Quantizer
  from ..base.wrapper import ModuleWrapper
  from ..utils import Evaluator, _EVALUATOR_DOCSTRING
  from ..base.target_space import TargetType, QuantizationTargetSpace
label_desc: Use image node_id 6 for calling the DoReFaQuantizer obj's underlying member method code with example usage: obj._quant_dequant_gradient_hook(target_space) and returns: tuple