class_docstr: Interface between a HF Pytorch model and a Thinc Model.
class_docstr_tok: ["Interface","between","a","HF","Pytorch","model","and","a","Thinc","Model","."]
code: def __init__(
      self,
      model: HFObjects,
      config=None,
      optimizer: Any = None,
      mixed_precision: bool = False,
      grad_scaler_config: dict = {},
      config_cls=AutoConfig,
      model_cls=AutoModel,
      tokenizer_cls=AutoTokenizer,
  ):
      self._hfmodel = model
      self.config_cls = config_cls
      self.model_cls = model_cls
      self.tokenizer_cls = tokenizer_cls
  
      # Enable gradient scaling when mixed precision is enabled and gradient
      # scaling is not explicitly disabled in the configuration.
      if "enabled" not in grad_scaler_config:
          grad_scaler_config["enabled"] = mixed_precision
  
      super().__init__(
          model.transformer,
          config,
          optimizer,
          mixed_precision,
          grad_scaler=PyTorchGradScaler(**grad_scaler_config),
      )
  
file_path: spacy-transformers/spacy_transformers/layers/hf_shim.py
imports: from typing import Any, Dict
  from io import BytesIO
  from pathlib import Path
  import srsly
  import torch
  import warnings
  from thinc.api import get_torch_default_device
  from spacy.util import SimpleFrozenDict
  from ..data_classes import HFObjects
  from ..util import make_tempdir
  from thinc.api import PyTorchGradScaler, PyTorchShim
  from transformers import AutoModel, AutoConfig, AutoTokenizer
label_desc: Use image node_id 1 to create a new HFShim object from inherited base classes: PyTorchShim with example: obj = HFShim(model, config, optimizer, mixed_precision, grad_scaler_config, config_cls, model_cls, tokenizer_cls)