code: def combine_models(
      dir,
      num_iters,
      models_to_combine,
      num_chunk_per_minibatch_str,
      egs_dir,
      leaky_hmm_coefficient,
      l2_regularize,
      xent_regularize,
      run_opts,
      max_objective_evaluations=30,
      use_multitask_egs=False,
  ):
      """Function to do model combination
  
      In the nnet3 setup, the logic
      for doing averaging of subsets of the models in the case where
      there are too many models to reliably esetimate interpolation
      factors (max_models_combine) is moved into the nnet3-combine.
      """
      raw_model_strings = []
      logger.info("Combining {0} models.".format(models_to_combine))
  
      models_to_combine.add(num_iters)
  
      for iter in sorted(models_to_combine):
          model_file = "{0}/{1}.mdl".format(dir, iter)
          if os.path.exists(model_file):
              # we used to copy them with nnet3-am-copy --raw=true, but now
              # the raw-model-reading code discards the other stuff itself.
              raw_model_strings.append(model_file)
          else:
              print(
                  "{0}: warning: model file {1} does not exist "
                  "(final combination)".format(sys.argv[0], model_file)
              )
  
      scp_or_ark = "scp" if use_multitask_egs else "ark"
      egs_suffix = ".scp" if use_multitask_egs else ".cegs"
  
      multitask_egs_opts = common_train_lib.get_multitask_egs_opts(
          egs_dir,
          egs_prefix="combine.",
          use_multitask_egs=use_multitask_egs,
      )
  
      # We reverse the order of the raw model strings so that the freshest one
      # goes first.  This is important for systems that include batch
      # normalization-- it means that the freshest batch-norm stats are used.
      # Since the batch-norm stats are not technically parameters, they are not
      # combined in the combination code, they are just obtained from the first
      # model.
      raw_model_strings = list(reversed(raw_model_strings))
  
      common_lib.execute_command(
          """{command} {combine_queue_opt} {dir}/log/combine.log \
                  nnet3-chain-combine \
                  --max-objective-evaluations={max_objective_evaluations} \
                  --l2-regularize={l2} --leaky-hmm-coefficient={leaky} \
                  --verbose=3 {combine_gpu_opt} {dir}/den.fst {raw_models} \
                  "ark,bg:nnet3-chain-copy-egs {multitask_egs_opts} {scp_or_ark}:{egs_dir}/combine{egs_suffix} ark:- | \
                      nnet3-chain-merge-egs --minibatch-size={num_chunk_per_mb} \
                      ark:- ark:- |" - \| \
                  nnet3-am-copy --set-raw-nnet=- {dir}/{num_iters}.mdl \
                  {dir}/final.mdl""".format(
              command=run_opts.command,
              combine_queue_opt=run_opts.combine_queue_opt,
              combine_gpu_opt=run_opts.combine_gpu_opt,
              max_objective_evaluations=max_objective_evaluations,
              l2=l2_regularize,
              leaky=leaky_hmm_coefficient,
              dir=dir,
              raw_models=" ".join(raw_model_strings),
              num_chunk_per_mb=num_chunk_per_minibatch_str,
              num_iters=num_iters,
              egs_dir=egs_dir,
              multitask_egs_opts=multitask_egs_opts,
              scp_or_ark=scp_or_ark,
              egs_suffix=egs_suffix,
          )
      )
  
      # Compute the probability of the final, combined model with
      # the same subset we used for the previous compute_probs, as the
      # different subsets will lead to different probs.
      compute_train_cv_probabilities(
          dir=dir,
          iter="final",
          egs_dir=egs_dir,
          l2_regularize=l2_regularize,
          xent_regularize=xent_regularize,
          leaky_hmm_coefficient=leaky_hmm_coefficient,
          run_opts=run_opts,
          use_multitask_egs=use_multitask_egs,
      )
  
file_path: espnet/egs2/librispeech/ssl1/steps/libs/nnet3/train/chain_objf/acoustic_model.py
imports: from __future__ import division
  from __future__ import print_function
  import logging
  import math
  import os
  import sys
  import libs.common
  import libs.nnet3.train.common
label_desc: Use image node_id 11 for calling a global function with example usage: combine_models(dir, num_iters, models_to_combine, num_chunk_per_minibatch_str, egs_dir, leaky_hmm_coefficient, l2_regularize, xent_regularize, run_opts, max_objective_evaluations, use_multitask_egs) without return types