Cannot load the model from checkpoint

Hello,
Im trying to load my model from a chekpoint, which I trained earlier with pytorch lightning.

I get the error:

TypeError: The classmethod SimCLR_Model.load_from_checkpoint cannot be called on an instance. Please call it on the class type and make sure the return value is used.

I double checked the docs and i cannot see where the error is. Its strange, because it worked before and I updated pytorch lightning and now Im seeing this error.

Here is the code:

    emb_model_path = "models/version_876873/checkpoints/epoch=99-step=31600.ckpt"
    e_model = SimCLR_Model(args, args.embedding_space).load_from_checkpoint(emb_model_path, args=args, emb_space=args.embedding_space)
    e_model.freeze()
    
    
    model = LinearModel(args, e_model)
    print(model)
    trainer = L.Trainer(max_epochs=args.epochs)
    trainer.fit(model, train_loader, val_loader)

And the code from the SimCLR model:

import torch
import lightning as L
from torchvision.models import convnext_base, ConvNeXt_Base_Weights
from simclr_loss import SimCLR_Loss


class SimCLR_Model(L.LightningModule):
    def __init__(self, args, emb_space):
        super().__init__()
        
        self.args = args
        self.encoder = convnext_base(num_classes=emb_space)
        self.loss = SimCLR_Loss(self.args.batch_size)
        
    def forward(self, x): 
        return self.encoder(x)
        
    def configure_optimizers(self):
        optimizer = torch.optim.Adam(self.parameters(), lr=1e-3)
        return optimizer
        
    def training_step(self, batch, batch_idx):
        x, y = batch
        images = torch.cat([x, y], dim=0)
        #put here contiguous(): images.contiguous()
        embeddings = self.encoder(images)
        loss = self.loss(embeddings)
        self.log("train_loss", loss, on_epoch=True)
        return loss
    
    def validation_step(self, batch, batch_idx):
        x, y = batch
        images = torch.cat([x, y], dim=0)
        embeddings = self.encoder(images)
        loss = self.loss(embeddings)
        self.log("val_loss", loss, on_epoch=True)
        return loss

Hey

Change

e_model = SimCLR_Model(args, args.embedding_space).load_from_checkpoint(emb_model_path, args=args, emb_space=args.embedding_space)

to

e_model = SimCLR_Model.load_from_checkpoint(emb_model_path, args=args, emb_space=args.embedding_space)

and that should do the trick.

Great, it worked! Thanks a lot. Now i clearly see, where my mistake was.

Weird, that it still worked with lightning 2.0.8 though

You are welcome. Yes, we added the error recently, because if the user made the mistake you did here, in certain cases it would silently lead to the model weights not being loaded.