This error can be triggered if you try to redefine a member variable that is already defined in the class you inherited.
from pytorch_lightning import LightningModule
class Seq2SeqModel(LightningModule):
def __init__(self, tokenizer, bart, hparams):
super().__init__()
self.tokenizer = tokenizer
self.bart: BartForConditionalGeneration = bart
self.hparams = hparams # This triggers the error
# Changing above line to below removes the error
# self.hp = hparams
As I was new to PyTorch
and PyTorch Lightning
, I did not know the LightningModule
already had a member variable named self.hparams
. As I tried to overwrite it in my code, it caused AttributeError: can't set attribute
.
Just simply renaming my variable from self.hparams
to something else removed the error.
Not the problem in the OP's question, but I'm putting it here to help any searching for the error message directly