How can I modify some parts of the saved model?
My original model as below: <SCODE>class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.encoder = Encoder()
        self.decoder = Decoder()

    def forward(self, x):
        x = self.encoder(x)
        x = F.dropout(x, p = 0.2)
        x = self.decoder(x)
        return x
<ECODE> <SCODE>net = torch.load('net.pth')
class classifier(nn.Module):
    super(classifier, self),__init__()
    self.encoder = nn.Sequential(*list(net.encoder.children()))
    self.fc = nn.Linear(enc_dim, num_class)

    def forward(self, x):
        x = self.encoder(x)
        x = F.dropout(x,p = 0.5)
        x = self.fc(x)
        x = F.log_softmax(x)
        return x
<ECODE> Can you please tell me how I can solve this error ? Also, when I use DataParallel, I think <SCODE>nn.Sequential(*list(ae_net.encoder.children())) 
<ECODE> needs to be modified as like <SCODE>nn.Sequential(*list(ae_net.module.encoder.children()))
<ECODE> Is it right ?
Seungyoung_Park
invalid device ordinal points to you trying to use a CUDA device id that doesn’t exist. For example, trying to use id=2 on a device with only 2 GPUs (0, 1)
smth
I do not understand your explanation. Where can i add gpu id ? I have 4gpus, but at this time i just use only one by using CUDA_VISIBLE_DEVICES.
Seungyoung_Park
CUDA_VISIBLE_DEVICES is 0-indexed, so if you have 4 GPUs, then valid values are 0, 1, 2 or 3. pytorch (actually CUDA) is complaining that you gave an invalid device id to use
smth
apaszke
No, I tried it using CUDA_DEVICES_VISIBLE=1. But, may be i used different gpu when the model was loaded.
Seungyoung_Park
Seungyoung_Park
apaszke
As you suggested, it works! Thanks.
Seungyoung_Park