class_docstr: This context manager is used for Pytorch Model Inference.
  
  Provide no grad, thread control and autocast context which is for bf16 model.
class_docstr_tok: ["This","context","manager","is","used","for","Pytorch","Model","Inference",".","Provide","no","grad",",","thread","control","and","autocast","context","which","is","for","bf16","model","."]
code: def __init__(self, forecaster, thread_num, optimize):
      self.forecaster = forecaster
      self.infer_mode = torch.inference_mode(mode=True)
      if thread_num:
          self.thread_num = thread_num
      elif optimize and self.forecaster.optimized_model_thread_num:
          self.thread_num = self.forecaster.optimized_model_thread_num
      else:
          self.thread_num = None
      self.bf16_enable = (
          self.forecaster.accelerate_method is not None
          and "bf16" in self.forecaster.accelerate_method
      )
      if optimize and self.bf16_enable:
          self.autocast = torch.cpu.amp.autocast(
              enabled=True, dtype=torch.bfloat16
          )
  
file_path: BigDL/python/chronos/src/bigdl/chronos/pytorch/context_manager.py
imports: import torch
  from bigdl.chronos.forecaster.utils import set_pytorch_thread
label_desc: Use image node_id 1 to create a new ForecasterContextManager object from inherited base classes: object with example: obj = ForecasterContextManager(forecaster, thread_num, optimize)