You can do something like this:
class EncoderCNN(nn.Module):

    def __init__(self):
        super(EncoderCNN, self).__init__()
        self.vgg = models.vgg16()
        self.vgg.load_state_dict(torch.load(vgg_checkpoint))
        self.vgg.classifier = nn.Sequential(
            *(self.vgg.classifier[i] for i in range(6)))

    def forward(self, images):
        return self.vgg(images)

VGG net can be viewd as the combination of two sub-nets: feature extracting net and classifying net, and each of them is a nn.Sequential module. I just remove the last fc layer in classifying net by constructing a new nn.Sequential module with the pretrained parameters.
For your requirement, I guess you can do it like this:
    def __init__(self):
        super(EncoderCNN, self).__init__()
        self.vgg = models.vgg16()
        self.vgg.load_state_dict(torch.load(vgg_checkpoint))
        self.vgg.features = nn.Sequential(
            *(self.vgg.features[i] for i in range(30))

    def forward(self, images):
        return self.vgg.feature(images)

Sorry that this method looks so ugly. The nn.Sequential object does not support slice so I have to construct a new Sequential by list comprehension.