class_docstr: Autocast context manager for Pytorch Model Inference.
  
  This context manager is used for providing no grad and autocast context,
  which is used for bf16 model.
class_docstr_tok: ["Autocast","context","manager","for","Pytorch","Model","Inference",".","This","context","manager","is","used","for","providing","no","grad","and","autocast","context",",","which","is","used","for","bf16","model","."]
code: def __init__(
      self, thread_num=None, accelerator=None, enable_onednn=False
  ):
      super().__init__(
          thread_num=thread_num,
          accelerator=accelerator,
          enable_onednn=enable_onednn,
      )
      if compare_version("torch", operator.lt, "1.13.0"):
          # In torch1.12, torch.inference_mode(mode=True) will cause bug for jit+bf16
          self.infer_mode = torch.no_grad()
          self.infer_mode_string = "no_grad"
      self.autocast = torch.cpu.amp.autocast(
          enabled=True, dtype=torch.bfloat16
      )
  
imports: import torch
  import operator
  from bigdl.nano.utils.common import compare_version
label_desc: Use image node_id 1 to create a new AutocastContextManager object from inherited base classes: BaseContextManager with example: obj = AutocastContextManager(thread_num, accelerator, enable_onednn)