code: def build_final_learner(
      learner,
      best_trial_path,
      save_path,
      last_ckpt_path,
      is_matching,
      standalone,
      clean_ckpts,
  ):
      """
      Build the final learner after HPO is finished.
  
      Parameters
      ----------
      learner
          A learner object.
      best_trial_path
          The best trial's saving path.
      save_path
          The saving path.
      last_ckpt_path
          The last checkpoint's path.
      is_matching
          Whether is matching.
  
      Returns
      -------
      The constructed learner.
      """
      if is_matching:
          from ..learners.matching import MultiModalMatcher
  
          # reload the learner metadata
          matcher = MultiModalMatcher._load_metadata(
              matcher=learner, path=best_trial_path
          )
          # construct the model
          (
              matcher._query_model,
              matcher._response_model,
          ) = create_siamese_model(
              query_config=matcher._query_config,
              response_config=matcher._response_config,
              pretrained=False,
          )
          # average checkpoint
          matcher.top_k_average(
              save_path=best_trial_path,
              last_ckpt_path=last_ckpt_path,
              top_k_average_method=matcher._config.optimization.top_k_average_method,
          )
          matcher._save_path = save_path
  
          return matcher
      else:
          from ..learners import BaseLearner
  
          # reload the learner metadata
          learner = BaseLearner._load_metadata(
              learner=learner, path=best_trial_path
          )
          # construct the model
          model = create_fusion_model(
              config=learner._config,
              num_classes=learner._output_shape,
              classes=learner._classes
              if hasattr(learner, "_classes")
              else None,
              num_numerical_columns=len(
                  learner._df_preprocessor.numerical_feature_names
              ),
              num_categories=learner._df_preprocessor.categorical_num_categories,
              pretrained=False,  # set "pretrain=False" to prevent downloading online models
          )
          learner._model = model
          # average checkpoint
          learner.top_k_average(
              save_path=best_trial_path,
              last_ckpt_path=last_ckpt_path,
              top_k_average_method=learner._config.optimization.top_k_average_method,
              standalone=standalone,
              clean_ckpts=clean_ckpts,
          )
  
          learner._save_path = save_path
  
          return learner
  
file_path: autogluon/multimodal/src/autogluon/multimodal/utils/hpo.py
imports: import logging
  import os
  import shutil
  import lightning.pytorch
  import yaml
  from autogluon.common.utils.context import set_torch_num_threads
  from ..constants import BEST_K_MODELS_FILE, RAY_TUNE_CHECKPOINT
  from .matcher import create_siamese_model
  from .model import create_fusion_model
label_desc: Use image node_id 3 for calling a global function with example usage: build_final_learner(learner, best_trial_path, save_path, last_ckpt_path, is_matching, standalone, clean_ckpts) and returns: matcher, learner