Intel® DevCloud
Help for those needing help starting or connecting to the Intel® DevCloud
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
681 Discussions

AttributeError: module 'torch' has no attribute 'is_cuda'

Tchouanga__Franck
2,949 Views

--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-17-71ae8829a053> in <module> 1 get_ipython().system('pip3 install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html') ----> 2 torch.is_cuda AttributeError: module 'torch' has no attribute 'is_cuda'

 

please help with this error 

0 Kudos
10 Replies
JananiC_Intel
Moderator
2,948 Views

Hi,

Thank you for posting your questions.

First of all use torch.cuda.is_available() to detemine the CUDA availability also we need more details to figure out the issue.Could you provide us the commands and steps you followed?

 

 

Tchouanga__Franck
2,948 Views

I  am actually pruning my model using a particular torch library for pruning

then this is what happens

model structure 

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
class C3D(nn.Module):
    """
    The C3D network.
    """

    def __init__(self, num_classes, pretrained=False):
        super(C3D, self).__init__()
             
        self.conv1 = nn.quantized.Conv3d(3, 64, kernel_size=(3, 3, 3), padding=(1, 1, 1))#.....54.14ms
        self.pool1 = nn.MaxPool3d(kernel_size=(1, 2, 2), stride=(1, 2, 2))

        self.conv2 = nn.quantized.Conv3d(64, 128, kernel_size=(3, 3, 3), padding=(1, 1, 1))#**...395.749ms**
        self.pool2 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))

        self.conv3a = nn.quantized.Conv3d(128, 256, kernel_size=(3, 3, 3), padding=(1, 1, 1))#.....208.237ms
        self.conv3b = nn.quantized.Conv3d(256, 256, kernel_size=(3, 3, 3), padding=(1, 1, 1))#***..348.491ms***
        self.pool3 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))

        self.conv4a = nn.quantized.Conv3d(256, 512, kernel_size=(3, 3, 3), padding=(1, 1, 1))#.....64.714ms
        self.conv4b = nn.quantized.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1, 1, 1))#.....169.855ms
        self.pool4 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2))

        self.conv5a = nn.quantized.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1, 1, 1))#....27.173ms
        self.conv5b = nn.quantized.Conv3d(512, 512, kernel_size=(3, 3, 3), padding=(1, 1, 1))#....25.972ms
        self.pool5 = nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=(0, 1, 1))

        self.fc6 = nn.Linear(8192, 4096)#......21.852ms
        self.fc7 = nn.Linear(4096, 4096)#.......10.288ms
        self.fc8 = nn.Linear(4096, num_classes)#...0.023ms

        self.dropout = nn.Dropout(p=0.5)

        self.relu = nn.ReLU()
        self.softmax = nn.Softmax(dim=1)

        self.__init_weight()

    def forward(self, x):

        x = self.relu(self.conv1(x))
        x = least_squares(self.pool1(x))

        x = self.relu(self.conv2(x))
        x = least_squares(self.pool2(x))

        x = self.relu(self.conv3a(x))
        x = self.relu(self.conv3b(x))
        x = least_squares(self.pool3(x))

        x = self.relu(self.conv4a(x))
        x = self.relu(self.conv4b(x))
        x = least_squares(self.pool4(x))

        x = self.relu(self.conv5a(x))
        x = self.relu(self.conv5b(x))
        x = least_squares(self.pool5(x))

        x = x.view(-1, 8192)
        x = self.relu(self.fc6(x))
        x = self.dropout(x)
        x = self.relu(self.fc7(x))
        x = self.dropout(x)

        logits = self.fc8(x)

        #probs = self.softmax(logits)

        return logits

    def __init_weight(self):
        for m in self.modules():
            if isinstance(m, nn.Conv3d):
                init.xavier_normal_(m.weight.data)
                init.constant_(m.bias.data, 0.01)
            elif isinstance(m, nn.Linear):
                init.xavier_normal_(m.weight.data)
                init.constant_(m.bias.data, 0.01)

 

 

then later on when I prune the model

 

import torch.nn.utils.prune as prune
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = C3D(num_classes=2).to(device=device) 
prune.random_unstructured(module, name="weight", amount=0.3)

parameters_to_prune = (
    (model.conv2, 'weight'),
    (model.conv3a, 'weight'),
    (model.conv3b, 'weight'),
    (model.conv4a, 'weight'),
    (model.conv4b, 'weight'),
    (model.conv5a, 'weight'),
    (model.conv5b, 'weight'),
    (model.fc6, 'weight'),
    (model.fc7, 'weight'),
    (model.fc8, 'weight'),
)

prune.global_unstructured(
    parameters_to_prune,
    pruning_method=prune.L1Unstructured,
    amount=0.2
)

 

 

 

 

This is the error I get 

 

--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-21-e36bdf219c8c> in <module> 19 parameters_to_prune, 20 pruning_method=prune.L1Unstructured, ---> 21 amount=0.2 22 ) ~/.local/lib/python3.7/site-packages/torch/nn/utils/prune.py in global_unstructured(parameters, pruning_method, **kwargs) 1017 1018 # flatten parameter values to consider them all at once in global pruning -> 1019 t = torch.nn.utils.parameters_to_vector([getattr(*p) for p in parameters]) 1020 # similarly, flatten the masks (if they exist), or use a flattened vector 1021 # of 1s of the same dimensions as t ~/.local/lib/python3.7/site-packages/torch/nn/utils/convert_parameters.py in parameters_to_vector(parameters) 18 for param in parameters: 19 # Ensure the parameters are located in the same device ---> 20 param_device = _check_param_device(param, param_device) 21 22 vec.append(param.view(-1)) ~/.local/lib/python3.7/site-packages/torch/nn/utils/convert_parameters.py in _check_param_device(param, old_param_device) 71 # Meet the first parameter 72 if old_param_device is None: ---> 73 old_param_device = param.get_device() if param.is_cuda else -1 74 else: 75 warn = False AttributeError: 'function' object has no attribute 'is_cuda'

 

 

 

 

please help

Tchouanga__Franck
2,948 Views

prune.global_unstructured when I use prune.global_unstructure I get that error

 

please help

JananiC_Intel
Moderator
2,948 Views

Hi Franck,

Thanks for the update.

To figure out the exact issue we need your code and steps to test from our end.Could you share the entire code and steps in a zip file?

Tchouanga__Franck
2,948 Views

ok

Tchouanga__Franck
2,948 Views

please help I just sent the iynb model

Tchouanga__Franck
2,948 Views

Sorry for late response 

JananiC_Intel
Moderator
2,937 Views

Hi,

Sorry for the late response.

We tried running your code.The issue seems to be with the quantized.Conv3d, instead you can use normal convolution3d.

Since this issue is not related to Intel Devcloud can we close the case?


JananiC_Intel
Moderator
2,920 Views

Hi,

Could you give us an update?


JananiC_Intel
Moderator
2,853 Views

Hi,

We are closing the case assuming that your issue got resolved.Please raise a new thread in case of any further issues.

Thanks.



Reply