code: def _encode(self, sources: mx.nd.NDArray, source_length: int) -> Tuple[List[ModelState], mx.nd.NDArray]:
          
          model_states = []
          ratios = []
          for model in self.models:
              state, ratio = model.run_encoder(sources, source_length)
              model_states.append(state)
              if ratio is not None:
                  ratios.append(ratio)
  
          # num_seq takes batch_size and beam_size into account
          num_seq = model_states[0].states[0].shape[0]
          if self.constant_length_ratio > 0.0:
              # override all ratios with the constant value
              length_ratios = mx.nd.full(val=self.constant_length_ratio, shape=(num_seq, 1), ctx=self.context)
          else:
              if len(ratios) > 0:  # some model predicted a ratio?
                  # average the ratios over the models that actually we able to predict them
                  length_ratios = mx.nd.mean(mx.nd.stack(*ratios, axis=1), axis=1)
              else:
                  length_ratios = mx.nd.zeros((num_seq, 1), ctx=self.context)
  
          encoded_source_length=self.models[0].encoder.get_encoded_seq_len(source_length)
          return model_states, length_ratios * encoded_source_length
docs: Returns a ModelState for each model representing the state of the model after encoding the source.
  
          :param sources: Source ids. Shape: (batch_size, bucket_key, num_factors).
          :param source_length: Bucket key.
          :return: List of ModelStates and the estimated reference length based on ratios averaged over models.