nn.Flatten() is part of PyTorch 1.2.0 and later. Either update your pytorch version or you may have to find alternate ways of doing that. More on that here Flatten layer of PyTorch build by sequential container 1