I can train resnet model without changing the last layer of the model

I’m using a resnet model to train my data which has 4 classes. However, the resnet model in torchvision trained on the Imagenet dataset has 1000 output features. I have not changed the last layer of the resnet to match the classes of my data. However, the model does not raise any errors and starts the training process without issue. I am a beginner and was wondering how this works.

You are basically still training your model to classify images into 1000 classes but your trainingsset just does not include images for 996 of those classes.
There are no errors to raise since this is “technically not wrong”. It’s just like you are using a really shitty dataset.