dawidtang commited on
Commit
6e4b724
·
verified ·
1 Parent(s): 730b540

Call self.post_init() in __init__

Browse files

transformers 5.x sets all_tied_weights_keys inside PreTrainedModel.post_init(), and its loading path then reads that attribute directly, so a model whose __init__ skips post_init() fails with AttributeError on load.

Under 4.x the call is a no-op here: the module tree is empty at __init__ time and the real weights are loaded later by load_variant, so nothing is re-initialised.

Verified: outputs are bit-identical with and without the call under transformers 4.57.6 (max|diff| = 0.0), and the model loads under 5.3.0 only with it.

Files changed (1) hide show
  1. modeling_vjepa2_fmri_encoder.py +1 -0
modeling_vjepa2_fmri_encoder.py CHANGED
@@ -214,6 +214,7 @@ class VJEPA2FMRIEncoderModel(PreTrainedModel):
214
  self.decoders = nn.ModuleList()
215
  self.extractor = None
216
  self.vjepa = None
 
217
 
218
  @classmethod
219
  def from_pretrained(cls, pretrained_model_name_or_path, *args, config=None, variant=None, load_vjepa=None, **kwargs):
 
214
  self.decoders = nn.ModuleList()
215
  self.extractor = None
216
  self.vjepa = None
217
+ self.post_init()
218
 
219
  @classmethod
220
  def from_pretrained(cls, pretrained_model_name_or_path, *args, config=None, variant=None, load_vjepa=None, **kwargs):