code: def main(args):
      pawsx_teacher_tasks = args.pawsx_teacher_tasks
      assert all(task in PAWS_TASKS for task in pawsx_teacher_tasks)
      teacher_tasks_id = tasks_to_id(pawsx_teacher_tasks)
      pawsx_student_tasks = args.pawsx_student_tasks
      assert all(task in PAWS_TASKS for task in pawsx_student_tasks)
      student_tasks_id = tasks_to_id(pawsx_student_tasks)
  
      (
          teacher_train_df,
          teacher_val_df,
          teacher_test_dfs,
      ) = getDatasetSplits(pawsx_teacher_tasks)
      (
          student_train_df,
          student_val_df,
          student_test_dfs,
      ) = getDatasetSplits(pawsx_student_tasks)
  
      teacher_predictor_name = f"pawsx-{teacher_tasks_id}-{args.teacher_model.replace('/', '-')}"
      teacher_predictor_path = os.path.join(
          args.save_path, teacher_predictor_name
      )
      nodistill_predictor_name = f"pawsx-{student_tasks_id}-{args.student_model.replace('/', '-')}"
      nodistill_predictor_path = os.path.join(
          args.save_path, nodistill_predictor_name
      )
  
      teacher_result = {}
      nodistill_result = {}
      student_result = {}
  
      ### Train and evaluate the teacher model
      resume_teacher = args.resume
      try:
          teacher_predictor = MultiModalPredictor.load(
              teacher_predictor_path
          )
          print(
              "Using pretrained teacher model: %s"
              % teacher_predictor_path
          )
      except:
          resume_teacher = False
          print("No pretrained model at: %s" % teacher_predictor_path)
      if not resume_teacher:
          teacher_predictor = MultiModalPredictor(
              label="label", eval_metric="accuracy"
          )
          teacher_predictor.fit(
              teacher_train_df,
              tuning_data=teacher_val_df,
              hyperparameters={
                  "env.num_gpus": args.num_gpu,
                  "env.precision": args.precision,
                  "env.per_gpu_batch_size": 6,
                  "model.hf_text.checkpoint_name": args.teacher_model,
                  "optimization.learning_rate": 1.0e-4,
                  "optimization.weight_decay": 1.0e-3,
              },
              time_limit=args.time_limit,
              seed=args.seed,
          )
          teacher_predictor.save(teacher_predictor_path)
      for test_name, test_df in teacher_test_dfs.items():
          teacher_result[test_name] = teacher_predictor.evaluate(
              data=test_df, metrics="accuracy"
          )
      # use same dataset to measure computation time
      start = time()
      for test_name, test_df in student_test_dfs.items():
          teacher_predictor.evaluate(data=test_df, metrics="accuracy")
      teacher_usedtime = time() - start
  
      ### Train and evaluate a smaller pretrained model
      resume_nodistill = args.resume
      try:
          nodistill_predictor = MultiModalPredictor.load(
              nodistill_predictor_path
          )
          print(
              "Using pretrained nodistill model: %s"
              % nodistill_predictor_path
          )
      except:
          print("No pretrained model at: %s" % nodistill_predictor_path)
          resume_nodistill = False
      if not resume_nodistill:
          nodistill_predictor = MultiModalPredictor(
              label="label", eval_metric="accuracy"
          )
          nodistill_predictor.fit(
              student_train_df,
              tuning_data=student_val_df,
              hyperparameters={
                  "env.num_gpus": args.num_gpu,
                  "env.precision": args.precision,
                  "optimization.max_epochs": args.max_epochs,
                  "model.hf_text.checkpoint_name": args.student_model,
                  "optimization.learning_rate": 2.0e-4,
                  "optimization.weight_decay": 2.0e-3,
              },
              time_limit=args.time_limit,
              seed=args.seed,
          )
          nodistill_predictor.save(nodistill_predictor_path)
      for test_name, test_df in student_test_dfs.items():
          nodistill_result[test_name] = nodistill_predictor.evaluate(
              data=test_df, metrics="accuracy"
          )
  
      ### Distill and evaluate a student model
      from autogluon.multimodal.constants import (
          MODEL,
          DATA,
          OPTIMIZATION,
          ENVIRONMENT,
          DISTILLER,
      )
  
      config = {
          MODEL: f"default",
          DATA: "default",
          DISTILLER: "default",
          OPTIMIZATION: "default",
          ENVIRONMENT: "default",
      }
      student_predictor = MultiModalPredictor(
          label="label", eval_metric="accuracy"
      )
      student_predictor.fit(
          student_train_df,
          tuning_data=student_val_df,
          config=config,
          hyperparameters={
              "env.num_gpus": args.num_gpu,
              "env.precision": args.precision,
              "optimization.max_epochs": args.max_epochs,
              "model.hf_text.checkpoint_name": args.student_model,
              "model.hf_text.text_trivial_aug_maxscale": args.aug_scale,
              "optimization.learning_rate": 2.0e-4,
              "optimization.weight_decay": 2.0e-3,
              "distiller.temperature": args.temperature,
              "distiller.hard_label_weight": args.hard_label_weight,
              "distiller.soft_label_weight": args.soft_label_weight,
              "distiller.softmax_regression_weight": args.softmax_regression_weight,
              "distiller.output_feature_loss_weight": args.output_feature_loss_weight,
              "distiller.rkd_distance_loss_weight": args.rkd_distance_loss_weight,
              "distiller.rkd_angle_loss_weight": args.rkd_angle_loss_weight,
              "distiller.soft_label_loss_type": args.soft_label_loss_type,
              "distiller.softmax_regression_loss_type": args.softmax_regression_loss_type,
              "distiller.output_feature_loss_type": args.output_feature_loss_type,
              "model.hf_text.text_trivial_aug_maxscale": args.aug_scale,
              # "optimization.top_k": 1,
              # "optimization.top_k_average_method": "best",
          },
          teacher_predictor=teacher_predictor,
          time_limit=args.time_limit,
          seed=args.seed,
      )
      start = time()
      for test_name, test_df in student_test_dfs.items():
          student_result[test_name] = student_predictor.evaluate(
              data=test_df, metrics="accuracy"
          )
      student_usedtime = time() - start
  
      ### Print distillation's performance
      for test_name in student_test_dfs.keys():
          print("Distillation Result (%s):" % test_name)
          print("Teacher Model: %s" % args.teacher_model)
          print("Student Model: %s" % args.student_model)
          for k in teacher_result[test_name]:
              print(f"For metric {k}:")
              print(
                  "Teacher Model's %s: %.6f"
                  % (k, teacher_result[test_name][k])
              )
              print(
                  "Pretrained Model's %s: %.6f"
                  % (k, nodistill_result[test_name][k])
              )
              print(
                  "Student Model's %s: %.6f"
                  % (k, student_result[test_name][k])
              )
              print(
                  "Distillation Ratio (the fraction of the teacher's performance achieved by the student): %.6f"
                  % (
                      float(
                          student_result[test_name][k]
                          - nodistill_result[test_name][k]
                      )
                      / float(
                          teacher_result[test_name][k]
                          - nodistill_result[test_name][k]
                      )
                  )
              )
      print("Teacher Model's time: %.6f" % teacher_usedtime)
      print("Student Model's time: %.6f" % student_usedtime)
      print("speed up: %.6fx" % (teacher_usedtime / student_usedtime))
  
file_path: autogluon/examples/automm/distillation/automm_distillation_pawsx.py
imports: import argparse
  from autogluon.multimodal import MultiModalPredictor
  from datasets import load_dataset
  from time import time
  import os
  import pandas
label_desc: Use image node_id 3 for calling a global function with example usage: main(args) without return types