Esempio n. 1
0
 def add_args(cls, parser):
     """Add model-specific arguments to the parser."""
     # we want to build the args recursively in this case.
     # do not set defaults so that settings defaults from various architectures still works
     gen_parser_from_dataclass(parser,
                               TransformerConfig(),
                               delete_default=True,
                               with_prefix="")
Esempio n. 2
0
    def build_model(cls, args, task):
        """Build a new model instance."""

        # make sure all arguments are present in older models
        base_architecture(args)

        if args.encoder_layers_to_keep:
            args.encoder_layers = len(args.encoder_layers_to_keep.split(","))
        if args.decoder_layers_to_keep:
            args.decoder_layers = len(args.decoder_layers_to_keep.split(","))

        if getattr(args, "max_source_positions", None) is None:
            args.max_source_positions = DEFAULT_MAX_SOURCE_POSITIONS
        if getattr(args, "max_target_positions", None) is None:
            args.max_target_positions = DEFAULT_MAX_TARGET_POSITIONS

        src_dict, tgt_dict = task.source_dictionary, task.target_dictionary

        if args.share_all_embeddings:
            if src_dict != tgt_dict:
                raise ValueError(
                    "--share-all-embeddings requires a joined dictionary")
            if args.encoder_embed_dim != args.decoder_embed_dim:
                raise ValueError(
                    "--share-all-embeddings requires --encoder-embed-dim to match --decoder-embed-dim"
                )
            if args.decoder_embed_path and (args.decoder_embed_path !=
                                            args.encoder_embed_path):
                raise ValueError(
                    "--share-all-embeddings not compatible with --decoder-embed-path"
                )
            args.share_decoder_input_output_embed = True

        if getattr(args, "offload_activations", False):
            args.checkpoint_activations = True  # offloading implies checkpointing

        if not args.share_all_embeddings:
            args.min_params_to_wrap = getattr(args, "min_params_to_wrap",
                                              DEFAULT_MIN_PARAMS_TO_WRAP)
        cfg = TransformerConfig.from_namespace(args)
        return super().build_model(cfg, task)
 def _copy_keys(args, cls, prefix, seen):
     return TransformerConfig._copy_keys(args, cls, prefix, seen)
Esempio n. 4
0
 def build_decoder(cls, args, tgt_dict, embed_tokens):
     return super().build_decoder(TransformerConfig.from_namespace(args),
                                  tgt_dict, embed_tokens)
Esempio n. 5
0
 def build_embedding(cls, args, dictionary, embed_dim, path=None):
     return super().build_embedding(TransformerConfig.from_namespace(args),
                                    dictionary, embed_dim, path)
Esempio n. 6
0
 def __init__(self, args, encoder, decoder):
     cfg = TransformerConfig.from_namespace(args)
     super().__init__(cfg, encoder, decoder)
     self.args = args
Esempio n. 7
0
 def build_encoder(cls, args, tgt_dict, embed_tokens):
     return DeltaLMEncoder(TransformerConfig.from_namespace(args), tgt_dict,
                           embed_tokens)