def __init__(self, learning_rate: float, src_tokenizer: RobertaTokenizer, trg_tokenizer: GPT2Tokenizer, num_epochs: int, num_batches: int, num_gpus: int, num_layers_encoder: Optional[int]=None, num_layers_decoder: Optional[int]=None, encoder_name_or_path: Optional[str]=None, decoder_name_or_path: Optional[str]=None, **kwargs):
    super().__init__()
    self._src_tokenizer = src_tokenizer
    self._trg_tokenizer = trg_tokenizer
    self._num_epochs = num_epochs
    self._num_batches = num_batches
    self._num_gpus = num_gpus
    self.learning_rate = learning_rate
    self.save_hyperparameters()
    if ((encoder_name_or_path is not None) and (decoder_name_or_path is not None)):
        encoder = RobertaModel.from_pretrained(encoder_name_or_path)
        encoder.resize_token_embeddings(len(self._src_tokenizer))
        if ((num_layers_encoder is not None) and (num_layers_encoder < encoder.config.num_hidden_layers)):
            encoder = EncoderDecoderModule.remove_layers_from_model(encoder, num_layers_encoder, is_gpt=False)
        config = GPT2Config.from_pretrained(decoder_name_or_path)
        config.is_decoder = True
        config.add_cross_attention = True
        decoder = GPT2LMHeadModel.from_pretrained(decoder_name_or_path, config=config)
        if ((num_layers_decoder is not None) and (num_layers_decoder < decoder.config.n_layer)):
            decoder = EncoderDecoderModule.remove_layers_from_model(decoder, num_layers_decoder, is_gpt=True)
    elif ((num_layers_decoder is not None) and (num_layers_encoder is not None)):
        encoder_config = RobertaConfig()
        encoder_config.num_hidden_layers = num_layers_encoder
        encoder = RobertaModel(config=encoder_config)
        encoder.resize_token_embeddings(len(self._src_tokenizer))
        decoder_config = GPT2Config()
        decoder_config.n_layer = num_layers_decoder
        decoder_config.is_decoder = True
        decoder_config.add_cross_attention = True
        decoder = GPT2LMHeadModel(config=decoder_config)
    else:
        raise ValueError('You have to specify either num_layers for training from scratch                                           or paths for loading pretrained models')
    self.model = EncoderDecoderModel(encoder=encoder, decoder=decoder)
    self.model.decoder.config.use_cache = False
    self.model.config.tie_word_embeddings = False
    self.examples_count = 0
def __init__(self, learning_rate: float, src_tokenizer: RobertaTokenizer, trg_tokenizer: GPT2Tokenizer, num_epochs: int, num_batches: int, num_gpus: int, num_layers_encoder: Optional[int]=None, num_layers_decoder: Optional[int]=None, encoder_name_or_path: Optional[str]=None, decoder_name_or_path: Optional[str]=None, **kwargs):
    super().__init__()
    self._src_tokenizer = src_tokenizer
    self._trg_tokenizer = trg_tokenizer
    self._num_epochs = num_epochs
    self._num_batches = num_batches
    self._num_gpus = num_gpus
    self.learning_rate = learning_rate
    self.save_hyperparameters()
    if ((encoder_name_or_path is not None) and (decoder_name_or_path is not None)):
        encoder = RobertaModel.from_pretrained(encoder_name_or_path)
        encoder.resize_token_embeddings(len(self._src_tokenizer))
        if ((num_layers_encoder is not None) and (num_layers_encoder < encoder.config.num_hidden_layers)):
            encoder = EncoderDecoderModule.remove_layers_from_model(encoder, num_layers_encoder, is_gpt=False)
        config = GPT2Config.from_pretrained(decoder_name_or_path)
        config.is_decoder = True
        config.add_cross_attention = True
        decoder = GPT2LMHeadModel.from_pretrained(decoder_name_or_path, config=config)
        if ((num_layers_decoder is not None) and (num_layers_decoder < decoder.config.n_layer)):
            decoder = EncoderDecoderModule.remove_layers_from_model(decoder, num_layers_decoder, is_gpt=True)
    elif ((num_layers_decoder is not None) and (num_layers_encoder is not None)):
        encoder_config = RobertaConfig()
        encoder_config.num_hidden_layers = num_layers_encoder
        encoder = RobertaModel(config=encoder_config)
        encoder.resize_token_embeddings(len(self._src_tokenizer))
        decoder_config = GPT2Config()
        decoder_config.n_layer = num_layers_decoder
        decoder_config.is_decoder = True
        decoder_config.add_cross_attention = True
        decoder = GPT2LMHeadModel(config=decoder_config)
    else:
        raise ValueError('You have to specify either num_layers for training from scratch                                           or paths for loading pretrained models')
    self.model = EncoderDecoderModel(encoder=encoder, decoder=decoder)
    self.model.decoder.config.use_cache = False
    self.model.config.tie_word_embeddings = False
    self.examples_count = 0