code: def test_bitsandbytes_plugin(monkeypatch):
      module = lightning.fabric.plugins.precision.bitsandbytes
      monkeypatch.setattr(
          module, "_BITSANDBYTES_AVAILABLE", lambda: True
      )
      bitsandbytes_mock = Mock()
      monkeypatch.setitem(
          sys.modules, "bitsandbytes", bitsandbytes_mock
      )
  
      class ModuleMock(torch.nn.Linear):
          def __init__(
              self, in_features, out_features, bias=True, *_, **__
          ):
              super().__init__(in_features, out_features, bias)
  
      bitsandbytes_mock.nn.Linear8bitLt = ModuleMock
      bitsandbytes_mock.nn.Linear4bit = ModuleMock
      bitsandbytes_mock.nn.Params4bit = object
  
      precision = BitsandbytesPrecision("nf4", dtype=torch.float16)
      connector = _Connector(plugins=precision)
      assert connector.precision is precision
      assert precision.dtype == torch.float16
  
      # same logic as in `test_default_dtype_is_restored`
      assert torch.get_default_dtype() is torch.float32
      with pytest.raises(
          RuntimeError, match="foo"
      ), precision.module_init_context():
          assert torch.get_default_dtype() is not torch.float32
          raise RuntimeError("foo")
      assert torch.get_default_dtype() is torch.float32
  
      class SubModule(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.l = torch.nn.Linear(1, 3)
  
      class MyModule(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.l1 = torch.nn.Linear(16, 48)
              self.l2 = SubModule()
  
      _NF4Linear = vars(module)["_NF4Linear"]
      quantize_mock = lambda self, p, w, d: p
      _NF4Linear.quantize = quantize_mock
  
      with precision.module_init_context():
          assert torch.get_default_dtype() == torch.float16
          model = MyModule()
      assert isinstance(model.l1, _NF4Linear)
      assert isinstance(model.l2.l, _NF4Linear)
      model = precision.convert_module(model)
      assert model.l1.compute_dtype is precision.dtype
      assert model.l2.l.compute_dtype is precision.dtype
  
      model = MyModule()
      precision.convert_module(model)
      assert isinstance(model.l1, _NF4Linear)
      assert isinstance(model.l2.l, _NF4Linear)
  
      precision.ignore_modules = {"l2"}
      model = MyModule()
      precision.convert_module(model)
      assert isinstance(model.l1, _NF4Linear)
      assert isinstance(model.l2.l, torch.nn.Linear)
  
      model = torch.nn.Conv1d(1, 1, 1)
      with pytest.raises(TypeError, match="your model has no Linear"):
          precision.convert_module(model)
  
file_path: pytorch-lightning/tests/tests_fabric/plugins/precision/test_bitsandbytes.py
imports: import sys
  from unittest.mock import Mock
  import lightning.fabric
  import pytest
  import torch
  import torch.distributed
  from lightning.fabric import Fabric
  from lightning.fabric.connector import _Connector
  from lightning.fabric.plugins.precision.bitsandbytes import _BITSANDBYTES_AVAILABLE, BitsandbytesPrecision
  from lightning.fabric.utilities.init import _materialize_meta_tensors
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 1 for calling a global function with example usage: test_bitsandbytes_plugin(monkeypatch) without return types