code: def tune_model_weights():
      parser = generate.get_parser_with_args()
      parser = add_tune_args(parser)
      args = options.parse_args_and_arch(parser)
      n_models = len(args.path.split(CHECKPOINT_PATHS_DELIMITER))
      print(n_models)
      print(args.weight_lower_bound)
      print(args.weight_upper_bound)
      print(args.output_json_best_parameters)
      print(args.output_json_best_value)
      print(args.num_trails_ax_opt)
  
      def evaluation_function(parameterization):
          w1 = parameterization.get("w1")
          w2 = parameterization.get("w2")
          w3 = parameterization.get("w3")
          weight = str(w1) + "," + str(w2) + "," + str(w3)
          args.model_weights = weight
          generate.validate_args(args)
          score = generate.generate(args)
          return {"bleu_score": (score, 0.0)}
  
      lower_bound = args.weight_lower_bound
      upper_bound = args.weight_upper_bound
      best_parameters, values, experiment, model = optimize(
          parameters=[
              {
                  "name": "w1",
                  "type": "range",
                  "bounds": [lower_bound, upper_bound],
                  "value_type": "float",
              },
              {
                  "name": "w2",
                  "type": "range",
                  "bounds": [lower_bound, upper_bound],
              },
              {
                  "name": "w3",
                  "type": "range",
                  "bounds": [lower_bound, upper_bound],
              },
          ],
          experiment_name="tune_model_weights",
          objective_name="bleu_score",
          evaluation_function=evaluation_function,
          minimize=True,  # Optional, defaults to False.
          parameter_constraints=[
              "w1 + w2 + w3 <= 1",
              "w1 + w2 + w3 >= 0.99",
          ],  # Optional.
          total_trials=args.num_trails_ax_opt,  # Optional.
      )
  
      json_file = json.dumps(best_parameters)
      with open(args.output_json_best_parameters, "w") as f:
          f.write(json_file)
          f.close()
  
      json_file = json.dumps(values)
      with open(args.output_json_best_value, "w") as f:
          f.write(json_file)
          f.close()
      return best_parameters, values
  
imports: import json
  from ax.service.managed_loop import optimize
  from fairseq import options
  from pytorch_translate import generate
  from pytorch_translate.constants import CHECKPOINT_PATHS_DELIMITER
label_desc: Use image node_id 2 for calling a global function with example usage: tune_model_weights() and returns: best_parameters,  values, dict