Cuda out of memory because of larger image crop_size in big models

ninesun127: <p>when i set crop_size=48,it works.<br>
while the 96 and 192 occur the cuda errors.I know i can utility more gpus to solve it.<br>
but i do not know how to do specifically.</p>
<p>Anyone can help me?<br>
my model code is below:</p>
<pre><code class="lang-auto">import common

import torch.nn as nn

## Channel Attention (CA) Layer
class CALayer(nn.Module):
    def __init__(self, channel, reduction=16):
        super(CALayer, self).__init__()
        # global average pooling: feature --&gt; point
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        # feature channel downscale and upscale --&gt; channel weight
        self.conv_du = nn.Sequential(
                nn.Conv2d(channel, channel // reduction, 1, padding=0, bias=True),
                nn.ReLU(inplace=True),
                nn.Conv2d(channel // reduction, channel, 1, padding=0, bias=True),
                nn.Sigmoid()
        )

    def forward(self, x):
        y = self.avg_pool(x)
        y = self.conv_du(y)
        return x * y

## Residual Channel Attention Block (RCAB)
class RCAB(nn.Module):
    def __init__(
        self, conv, n_feat, kernel_size, reduction,
        bias=True, bn=False, act=nn.ReLU(True), res_scale=1):

        super(RCAB, self).__init__()
        modules_body = []
        for i in range(2):
            modules_body.append(conv(n_feat, n_feat, kernel_size, bias=bias))
            if bn: modules_body.append(nn.BatchNorm2d(n_feat))
            if i == 0: modules_body.append(act)
        modules_body.append(CALayer(n_feat, reduction))
        self.body = nn.Sequential(*modules_body)
        self.res_scale = res_scale

    def forward(self, x):
        res = self.body(x)
        #res = self.body(x).mul(self.res_scale)
        res += x
        return res

## Residual Group (RG)
class ResidualGroup(nn.Module):
    def __init__(self, conv, n_feat, kernel_size, reduction, act, res_scale, n_resblocks):
        super(ResidualGroup, self).__init__()
        modules_body = []
        modules_body = [
            RCAB(
                conv, n_feat, kernel_size, reduction, bias=True, bn=False, act=nn.ReLU(True), res_scale=1) \
            for _ in range(n_resblocks)]
        modules_body.append(conv(n_feat, n_feat, kernel_size))
        self.body = nn.Sequential(*modules_body)

    def forward(self, x):
        res = self.body(x)
        res += x
        return res

## Residual Channel Attention Network (RCAN)
class RCAN(nn.Module):
    def __init__(self,conv=common.default_conv):
        super(RCAN, self).__init__()
        
        n_resgroups = 10
        n_resblocks = 20
        n_feats = 64
        kernel_size = 3
        reduction = 16 
        scale = 4
        act = nn.ReLU(True)
        n_colors=3
        rgb_range=255
        res_scale=1
        
        # RGB mean for DIV2K
        #rgb_mean = (0.4488, 0.4371, 0.4040)
        rgb_mean=(0.5164,0.5179,0.4987)
        rgb_std = (1.0, 1.0, 1.0)
        self.sub_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std)
        
        # define head module
        modules_head = [conv(n_colors, n_feats, kernel_size)]

        # define body module
        modules_body = [
            ResidualGroup(
                conv, n_feats, kernel_size, reduction, act=act, res_scale=res_scale, n_resblocks=n_resblocks) \
            for _ in range(n_resgroups)]

        modules_body.append(conv(n_feats, n_feats, kernel_size))

        # define tail module
        modules_tail = [
            #common.Upsampler(conv, scale, n_feats, act=False),
            conv(n_feats, n_colors, kernel_size)]

        self.add_mean = common.MeanShift(rgb_range, rgb_mean, rgb_std, 1)

        self.head = nn.Sequential(*modules_head)
        self.body = nn.Sequential(*modules_body)
        self.tail = nn.Sequential(*modules_tail)

    def forward(self, x):
        #x = self.sub_mean(x)
        x = self.head(x)

        res = self.body(x)
        res += x

        x = self.tail(res)
        #x = self.add_mean(x)

        return x 
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/4/451288ba9e3f3527d1ea34ce1945d2a2adfff317.png" data-download-href="https://discuss.pytorch.org/uploads/default/451288ba9e3f3527d1ea34ce1945d2a2adfff317" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/4/451288ba9e3f3527d1ea34ce1945d2a2adfff317_2_690x339.png" alt="image" data-base62-sha1="9R2EAdbSwf1fiPbjHLVoW39RAer" width="690" height="339" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/4/451288ba9e3f3527d1ea34ce1945d2a2adfff317_2_690x339.png, https://discuss.pytorch.org/uploads/default/optimized/2X/4/451288ba9e3f3527d1ea34ce1945d2a2adfff317_2_1035x508.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/4/451288ba9e3f3527d1ea34ce1945d2a2adfff317_2_1380x678.png 2x" data-dominant-color="1D1519"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1406×692 245 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>