MCPcopy Create free account
hub / github.com/SooLab/CGFormer / tie_weights

Method tie_weights

bert/modeling_utils.py:348–356  ·  view source on GitHub ↗

Tie the weights between the input embeddings and the output embeddings. If the `torchscript` flag is set in the configuration, can't handle parameter sharing so we are cloning the weights instead.

(self)

Source from the content-addressed store, hash-verified

346 return None # Overwrite for models with output embeddings
347
348 def tie_weights(self):
349 """
350 Tie the weights between the input embeddings and the output embeddings.
351 If the `torchscript` flag is set in the configuration, can't handle parameter sharing so we are cloning
352 the weights instead.
353 """
354 output_embeddings = self.get_output_embeddings()
355 if output_embeddings is not None:
356 self._tie_or_clone_weights(output_embeddings, self.get_input_embeddings())
357
358 def _tie_or_clone_weights(self, output_embeddings, input_embeddings):
359 """ Tie or clone module weights depending of whether we are using TorchScript or not

Callers 3

init_weightsMethod · 0.95
from_pretrainedMethod · 0.80

Calls 3

get_output_embeddingsMethod · 0.95
_tie_or_clone_weightsMethod · 0.95
get_input_embeddingsMethod · 0.95

Tested by

no test coverage detected