class_docstr: Plugin for quantizing weights with `bitsandbytes <https://github.com/TimDettmers/bitsandbytes>`__.
  
  .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.
  
  .. note::
      The optimizer is not automatically replaced with ``bitsandbytes.optim.Adam8bit`` or equivalent 8-bit optimizers.
  
  Args:
      mode: The quantization mode to use.
      dtype: The compute dtype to use.
      ignore_modules: The submodules whose Linear layers should not be replaced, for example. ``{"lm_head"}``.
          This might be desirable for numerical stability. The string will be checked in as a prefix, so a value like
          "transformer.blocks" will ignore all linear layers in all of the transformer blocks.
class_docstr_tok: ["Plugin","for","quantizing","weights","with","`","bitsandbytes","<","https",":","\/\/github.com\/TimDettmers\/bitsandbytes",">","`","__",".","..","warning",":",":","This","is","an",":","ref",":","`","experimental","<","versioning",":","Experimental","API",">","`","feature",".","..","note",":",":","The","optimizer","is","not","automatically","replaced","with","``","bitsandbytes.optim.Adam8bit","``","or","equivalent","8-bit","optimizers",".","Args",":","mode",":","The","quantization","mode","to","use",".","dtype",":","The","compute","dtype","to","use",".","ignore_modules",":","The","submodules","whose","Linear","layers","should","not","be","replaced",",","for","example",".","``","{","``","lm_head","''","}","``",".","This","might","be","desirable","for","numerical","stability",".","The","string","will","be","checked","in","as","a","prefix",",","so","a","value","like","``","transformer.blocks","''","will","ignore","all","linear","layers","in","all","of","the","transformer","blocks","."]
code: def convert_module(self, module: torch.nn.Module) -> torch.nn.Module:
      # avoid naive users thinking they quantized their model
      if not any(
          isinstance(m, torch.nn.Linear) for m in module.modules()
      ):
          raise TypeError(
              "You are using the bitsandbytes precision plugin, but your model has no Linear layers. This plugin"
              " won't work for your model."
          )
  
      # convert modules if they haven't been converted already
      bnb = _import_bitsandbytes()
      if not any(
          isinstance(m, (bnb.nn.Linear8bitLt, bnb.nn.Linear4bit))
          for m in module.modules()
      ):
          # this will not quantize the model but only replace the layer classes
          _convert_layers(module, self._linear_cls, self.ignore_modules)
  
      # set the compute dtype if necessary
      for m in module.modules():
          if isinstance(m, bnb.nn.Linear4bit):
              m.compute_dtype = self.dtype
              m.compute_type_is_set = False
      return module
  
imports: import functools
  import logging
  import math
  import os
  import warnings
  from contextlib import ExitStack
  from functools import partial
  from types import ModuleType
  from typing import Any, Callable, ContextManager, Literal, Optional, OrderedDict, Set, Tuple, Type, cast
  import torch
  from lightning_utilities import apply_to_collection
  from lightning_utilities.core.imports import RequirementCache
  from torch import Tensor
  from torch.nn import init
  from torch.nn.modules.module import _IncompatibleKeys
  from typing_extensions import Self, override
  from lightning.fabric.plugins.precision.precision import Precision
  from lightning.fabric.plugins.precision.utils import _ClassReplacementContextManager, _convert_fp_tensor, _DtypeContextManager
  from lightning.fabric.utilities.types import _DEVICE
label_desc: Use image node_id 2 for calling the BitsandbytesPrecision obj's underlying member method code with example usage: obj.convert_module(module) and returns: module