I am pickling my entire model in a PKL file. Then, I changed the model code by adding another trainable weight.
Original init:
def init(self,
num_heads,
embedding_dim,
attention_type=“additive”):
self.save_init_params(locals())
super().init()
self.debug_attn = False
self.attention_type = attention_type
assert attention_type in [“dot_product”, “additive”], attention_type
# Create heads for query
self.fc0 = nn.Linear(embedding_dim, num_heads * embedding_dim)
# Project integration into logits
self.fc1 = nn.Linear(embedding_dim, 1)
New init:
def init(self,
num_heads,
embedding_dim,
attention_type=“additive”):
self.save_init_params(locals())
super().init()
self.debug_attn = False
self.attention_type = attention_type
assert attention_type in [“dot_product”, “additive”], attention_type
# Create heads for query
self.fc0 = nn.Linear(embedding_dim, num_heads * embedding_dim)
# Project integration into logits
self.fc1 = nn.Linear(embedding_dim, 1)
self.new_weight = Parameter(torch.Tensor([400]))
I only added this one line, and it doesn’t affect the other weights at all. However, trying to load the pickle now, I get:
size mismatch for fc0.weight: copying a param with shape torch.Size([64, 28]) from checkpoint, the shape in current model is torch.Size([64, 32]).
fc0 is not related to the self.new_weight at all