MCPcopy Create free account
hub / github.com/huggingface/transformers / init_weights

Method init_weights

src/transformers/modeling_utils.py:446–456  ·  view source on GitHub ↗

Initialize and prunes weights if needed.

(self)

Source from the content-addressed store, hash-verified

444 return new_embeddings
445
446 def init_weights(self):
447 """ Initialize and prunes weights if needed. """
448 # Initialize weights
449 self.apply(self._init_weights)
450
451 # Prune heads if needed
452 if self.config.pruned_heads:
453 self.prune_heads(self.config.pruned_heads)
454
455 # Tie weights if needed
456 self.tie_weights()
457
458 def prune_heads(self, heads_to_prune: Dict):
459 """ Prunes heads of the base model.

Callers 15

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 3

prune_headsMethod · 0.95
tie_weightsMethod · 0.95
applyMethod · 0.80

Tested by

no test coverage detected