code: def replace_8bit_linear(
      model, threshold=6.0, modules_to_not_convert="lm_head"
  ):
      """
      A helper function to replace all `torch.nn.Linear` modules by `bnb.nn.Linear8bit` modules from the `bitsandbytes`
      library. This will enable running your models using mixed int8 precision as described by the paper `GPT3.int8():
      8-bit Matrix Multiplication for Transformers at Scale`. Make sure `bitsandbytes` compiled with the correct CUDA
      version of your hardware is installed before running this function. `pip install -i https://test.pypi.org/simple/
      bitsandbytes`
  
      The function will be run recursively and replace all `torch.nn.Linear` modules except for the `lm_head` that should
      be kept as a `torch.nn.Linear` module. The replacement is done under `init_empty_weights` context manager so no
      CPU/GPU memory is required to run this function. Int8 mixed-precision matrix decomposition works by separating a
      matrix multiplication into two streams: (1) and systematic feature outlier stream matrix multiplied in fp16
      (0.01%), (2) a regular stream of int8 matrix multiplication (99.9%). With this method, int8 inference with no
      predictive degradation is possible for very large models (>=176B parameters).
  
      Parameters:
          model (`torch.nn.Module`):
              Input model or `torch.nn.Module` as the function is run recursively.
          threshold (`float`, *optional*, defaults to 6.0):
              `int8_threshold` for outlier detection as described in the formentioned paper. This parameters is set to
              `6.0` as described by the paper.
          modules_to_not_convert (`str`, *optional*, defaults to `lm_head`):
              Name of the module to not convert in `Linear8bitLt`. In practice we keep the `lm_head` in full precision
              for numerical stability reasons.
      """
      for name, module in model.named_children():
          if len(list(module.children())) > 0:
              replace_8bit_linear(
                  module, threshold, modules_to_not_convert
              )
  
          if (
              isinstance(module, nn.Linear)
              and name not in modules_to_not_convert
          ):
              with init_empty_weights():
                  model._modules[name] = bnb.nn.Linear8bitLt(
                      module.in_features,
                      module.out_features,
                      module.bias is not None,
                      has_fp16_weights=False,
                      threshold=threshold,
                  )
      return model
  
imports: from copy import deepcopy
  from transformers.utils import is_accelerate_available, is_bitsandbytes_available
label_desc: Use image node_id 2 for calling a global function with example usage: replace_8bit_linear(model, threshold, modules_to_not_convert) and returns: model