code: def build_hf_engine(
      path: str,
      engine_config: RaggedInferenceEngineConfig,
      debug_level: int = logging.INFO,
  ) -> InferenceEngineV2:
      """
      Build an InferenceV2 engine for HuggingFace models. This can accept both a HuggingFace
      model name or a path to an Inference-V2 checkpoint.
  
      Arguments:
          path: Path to the checkpoint. This does not need to point to any files in particular,
              just the directory containing the checkpoint.
          engine_config: Engine configuration. See ``RaggedInferenceEngineConfig`` for details.
          debug_level: Logging level to use. Unless you are actively seeing issues, the recommended
              value is ``logging.INFO``.
  
      Returns:
          Fully initialized inference engine ready to serve queries.
      """
  
      if os.path.exists(os.path.join(path, "ds_model_config.pkl")):
          return build_engine_from_ds_checkpoint(
              path, engine_config, debug_level=debug_level
          )
      else:
          # Set up logging
          inference_logger(level=debug_level)
          # get HF checkpoint engine
          checkpoint_engine = HuggingFaceCheckpointEngine(path)
  
          # get model config from HF AutoConfig
          model_config = checkpoint_engine.model_config
  
          # get the policy
          # TODO: generalize this to other models
          if model_config.model_type == "opt":
              if not model_config.do_layer_norm_before:
                  raise ValueError(
                      "Detected OPT-350m model. This model is not currently supported. If this is not the 350m model, please open an issue: https://github.com/microsoft/DeepSpeed-MII/issues"
                  )
              policy = OPTPolicy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          elif model_config.model_type == "llama":
              policy = Llama2Policy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          elif model_config.model_type == "mistral":
              # Ensure we're using the correct version of transformers for mistral
              import transformers
  
              assert version.parse(
                  transformers.__version__
              ) >= version.parse(
                  "4.34.0"
              ), f"Mistral requires transformers >= 4.34.0, you have version {transformers.__version__}"
              policy = MistralPolicy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          elif model_config.model_type == "mixtral":
              # Ensure we're using the correct version of transformers for mistral
              import transformers
  
              assert version.parse(
                  transformers.__version__
              ) >= version.parse(
                  "4.36.1"
              ), f"Mistral requires transformers >= 4.36.1, you have version {transformers.__version__}"
              policy = MixtralPolicy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          elif model_config.model_type == "falcon":
              policy = FalconPolicy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          elif model_config.model_type == "phi-msft":
              policy = PhiPolicy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          elif model_config.model_type == "qwen":
              policy = QwenPolicy(
                  model_config, checkpoint_engine=checkpoint_engine
              )
          else:
              raise ValueError(
                  f"Unsupported model type {model_config.model_type}"
              )
  
          return InferenceEngineV2(policy, engine_config)
  
file_path: DeepSpeed/deepspeed/inference/v2/engine_factory.py
imports: import json
  import logging
  import os
  import pickle
  from packaging import version
  from .engine_v2 import InferenceEngineV2
  from .config_v2 import RaggedInferenceEngineConfig
  from .checkpoint import HuggingFaceCheckpointEngine
  from .logging import inference_logger
  from .model_implementations import OPTPolicy, Llama2Policy, MistralPolicy, MixtralPolicy, FalconPolicy, PhiPolicy, QwenPolicy
  from .model_implementations.inference_policy_base import POLICIES, InferenceV2Policy
  from .model_implementations.flat_model_helpers import make_metadata_filename, ModelMetadata
label_desc: Use image node_id 2 for calling a global function with example usage: build_hf_engine(path, engine_config, debug_level) and returns: build_engine_from_ds_checkpoint, InferenceEngineV2