code: def init_empty_weights(include_buffers: bool = False):
      """
      init_empty_weights is vendored from accelerate. This is a useful function as it allows us to call transformers.AutoModel.from_pretrained without loading
      the actual weights of the model. This grants access to the model class and its attributes without using a significant amount of memory.
  
      A context manager under which models are initialized with all parameters on the meta device, therefore creating an
      empty model. Useful when just initializing the model would blow the available RAM.
  
      Args:
          include_buffers (`bool`, *optional*, defaults to `False`):
              Whether or not to also put all buffers on the meta device while initializing.
  
      Example:
  
      ```pyton
      import torch.nn as nn
      from accelerate import init_empty_weights
  
      # Initialize a model with 100 billions parameters in no time and without using any RAM.
      with init_empty_weights():
          tst = nn.Sequential(*[nn.Linear(10000, 10000) for _ in range(1000)])
      ```
  
      <Tip warning={true}>
  
      Any model created under this context manager has no weights. As such you can't do something like
      `model.to(some_device)` with it. To load weights inside your empty model, see [`load_checkpoint_and_dispatch`].
  
      </Tip>
      """
      old_register_parameter = nn.Module.register_parameter
      if include_buffers:
          old_register_buffer = nn.Module.register_buffer
  
      def register_empty_parameter(module, name, param):
          old_register_parameter(module, name, param)
          if param is not None:
              param_cls = type(module._parameters[name])
              kwargs = module._parameters[name].__dict__
              module._parameters[name] = param_cls(
                  module._parameters[name].to(torch.device("meta")),
                  **kwargs,
              )
  
      def register_empty_buffer(module, name, buffer):
          old_register_buffer(module, name, buffer)
          if buffer is not None:
              module._buffers[name] = module._buffers[name].to(
                  torch.device("meta")
              )
  
      try:
          nn.Module.register_parameter = register_empty_parameter
          if include_buffers:
              nn.Module.register_buffer = register_empty_buffer
          yield
      finally:
          nn.Module.register_parameter = old_register_parameter
          if include_buffers:
              nn.Module.register_buffer = old_register_buffer
  
file_path: BentoML/grpc-client/bentoml/_internal/frameworks/utils/transformers.py
imports: from __future__ import annotations
  import importlib.metadata
  import importlib.util
  import logging
  import re
  import typing
  from contextlib import contextmanager
  from pathlib import Path
  import torch
  import torch.nn
  from packaging import version
label_desc: Use image node_id 5 for calling a global function with example usage: init_empty_weights(include_buffers) without return types