opennmt/models/model.py
def transfer_weights(
        self, new_model, new_optimizer=None, optimizer=None, ignore_weights=None
    ):
        """Transfers weights (and optionally optimizer slots) from this model to
        another.

        This default implementation assumes that :obj:`self` and :obj:`new_model`
        have exactly the same variables. Subclasses can override this method to
        transfer weights to another model type or architecture. For example,
        :class:`opennmt.models.SequenceToSequence` can transfer weights to a model
        with a different vocabulary.

        All model and optimizer variables are expected to be initialized.

        Args:
          new_model: The new model to transfer weights to.
          new_optimizer: The new optimizer.
          optimizer: The optimizer used for the current model.
          ignore_weights: Optional list of weights to not transfer.
        """
        if type(self) is not type(new_model):
            raise ValueError(
                "Transferring weights to another model type is not supported"
            )
        if ignore_weights is None:
            ignore_weights = set()
        ignore_weights_ref = set(weight.ref() for weight in ignore_weights)
        weights = self.weights
        new_weights = new_model.weights
        for weight, new_weight in zip(weights, new_weights):
            if new_weight.ref() not in ignore_weights_ref:
                new_weight.assign(weight)
                if new_optimizer is not None and optimizer is not None:
                    for slot_name in new_optimizer.get_slot_names():
                        if slot_name not in optimizer.get_slot_names():
                            continue
                        new_slot = new_optimizer.get_slot(new_weight, slot_name)
                        slot = optimizer.get_slot(weight, slot_name)
                        new_slot.assign(slot)
Transfers weights (and optionally optimizer slots) from this model to
        another.

        This default implementation assumes that :obj:`self` and :obj:`new_model`
        have exactly the same variables. Subclasses can override this method to
        transfer weights to another model type or architecture. For example,
        :class:`opennmt.models.SequenceToSequence` can transfer weights to a model
        with a different vocabulary.

        All model and optimizer variables are expected to be initialized.

        Args:
          new_model: The new model to transfer weights to.
          new_optimizer: The new optimizer.
          optimizer: The optimizer used for the current model.
          ignore_weights: Optional list of weights to not transfer.
        
Transfers weights (and optionally optimizer slots) from this model to
another.

This default implementation assumes that :obj:`self` and :obj:`new_model`
have exactly the same variables. Subclasses can override this method to
transfer weights to another model type or architecture. For example,
:class:`opennmt.models.SequenceToSequence` can transfer weights to a model
with a different vocabulary.

All model and optimizer variables are expected to be initialized.
Transfers weights ( and optionally optimizer slots ) from this model to another . This default implementation assumes that : obj : ` self ` and : obj : ` new_model ` have exactly the same variables . Subclasses can override this method to transfer weights to another model type or architecture . For example : class : ` opennmt . models . SequenceToSequence ` can transfer weights to a model with a different vocabulary . All model and optimizer variables are expected to be initialized .
def transfer_weights(
        self, new_model, new_optimizer=None, optimizer=None, ignore_weights=None
    ):
        if type(self) is not type(new_model):
            raise ValueError(
                "Transferring weights to another model type is not supported"
            )
        if ignore_weights is None:
            ignore_weights = set()
        ignore_weights_ref = set(weight.ref() for weight in ignore_weights)
        weights = self.weights
        new_weights = new_model.weights
        for weight, new_weight in zip(weights, new_weights):
            if new_weight.ref() not in ignore_weights_ref:
                new_weight.assign(weight)
                if new_optimizer is not None and optimizer is not None:
                    for slot_name in new_optimizer.get_slot_names():
                        if slot_name not in optimizer.get_slot_names():
                            continue
                        new_slot = new_optimizer.get_slot(new_weight, slot_name)
                        slot = optimizer.get_slot(weight, slot_name)
                        new_slot.assign(slot)
def transfer_weights ( self , new_model , new_optimizer = None , optimizer = None , ignore_weights = None ) : if type ( self ) is not type ( new_model ) : raise ValueError ( "Transferring weights to another model type is not supported" ) if ignore_weights is None : ignore_weights = set ( ) ignore_weights_ref = set ( weight . ref ( ) for weight in ignore_weights ) weights = self . weights new_weights = new_model . weights for weight , new_weight in zip ( weights , new_weights ) : if new_weight . ref ( ) not in ignore_weights_ref : new_weight . assign ( weight ) if new_optimizer is not None and optimizer is not None : for slot_name in new_optimizer . get_slot_names ( ) : if slot_name not in optimizer . get_slot_names ( ) : continue new_slot = new_optimizer . get_slot ( new_weight , slot_name ) slot = optimizer . get_slot ( weight , slot_name ) new_slot . assign ( slot )
Transfers weights (and optionally optimizer slots) from this model to
another.
Transfers weights ( and optionally optimizer slots ) from this model to another .
"""Transfers weights (and optionally optimizer slots) from this model to
        another.

        This default implementation assumes that :obj:`self` and :obj:`new_model`
        have exactly the same variables. Subclasses can override this method to
        transfer weights to another model type or architecture. For example,
        :class:`opennmt.models.SequenceToSequence` can transfer weights to a model
        with a different vocabulary.

        All model and optimizer variables are expected to be initialized.

        Args:
          new_model: The new model to transfer weights to.
          new_optimizer: The new optimizer.
          optimizer: The optimizer used for the current model.
          ignore_weights: Optional list of weights to not transfer.
        """
self
new_model
The new model to transfer weights to.
The new model to transfer weights to .
new_optimizer
The new optimizer.
The new optimizer .
optimizer
The optimizer used for the current model.
The optimizer used for the current model .
ignore_weights
Optional list of weights to not transfer.
Optional list of weights to not transfer .