How to make the Linear layer a pass through layer without any calculation?

Hi, I want to overwrite the classifier layer of Distilbert as a pass through layer that does not do any calculation as I need to extract the pre-classification embeddings…

I did this but it doesn’t work:

model.classifier = torch.nn.Linear(768, 768)

Can anyone help please? Thanks

You could replace it with nn.Identity which will return the input without any modifications.

It worked! Thank you !!