code: def ensemble_encoder(func):
      def wrapper(self, *args, **kwargs):
          if (
              self.ensemble_models is None
              or len(self.ensemble_models) == 1
          ):
              return func(self, *args, **kwargs)
          encoder_outs = [
              func(model, *args, **kwargs, return_all_hiddens=True)
              for model in self.ensemble_models
          ]
          _encoder_out = encoder_outs[0].copy()
  
          def stack(key):
              outs = [e[key][0] for e in encoder_outs]
              return [
                  torch.stack(outs, -1) if outs[0] is not None else None
              ]
  
          _encoder_out["encoder_out"] = stack("encoder_out")
          _encoder_out["encoder_embedding"] = stack("encoder_embedding")
  
          num_layers = len(_encoder_out["encoder_states"])
          if num_layers > 0:
              _encoder_out["encoder_states"] = [
                  torch.stack(
                      [e["encoder_states"][i] for e in encoder_outs], -1
                  )
                  for i in range(num_layers)
              ]
          return _encoder_out
  
      return wrapper
  
imports: import math
  import torch
  from fairseq.models.transformer import TransformerDecoder, TransformerEncoder, TransformerModel
  from fairseq.modules.transformer_sentence_encoder import init_bert_params
label_desc: Use image node_id 1 for calling a global function with example usage: ensemble_encoder(func) and returns: wrapper, _encoder_out, func, list