Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] MaxPool3d causes GPU memory leaking #6222

Closed
xichangzun opened this issue Apr 3, 2018 · 1 comment
Closed

[Bug] MaxPool3d causes GPU memory leaking #6222

xichangzun opened this issue Apr 3, 2018 · 1 comment

Comments

@xichangzun
Copy link

xichangzun commented Apr 3, 2018

When I try to train my model which contains MaxPool3d , It always end up with 'out of memory' error.
my environment info is here:

  • 16.04
  • PyTorch version: 0.4.0a0+da6c3c9
  • installed PyTorch from source
  • python version is 3.6.2
  • CUDA/cuDNN version: 9.1/7.1.2
  • GCC version (if compiling from source):GCC 5.4
  • Build command you used (if compiling from source): as default

I can reproduce this bug by the following script:

import torch
import torch.nn as nn
from torch import optim
from torch.nn.functional import smooth_l1_loss
model = nn.Sequential(
    nn.Conv3d(1,1,kernel_size=3,padding=1),
    nn.ReLU(),
    nn.MaxPool3d(kernel_size=3, stride=2, padding=1),
)
#optimizer = optim.SGD((x for x in model.parameters() if x.requires_grad is True), lr=1e-3, momentum=0.9,nesterov=True)
crit = smooth_l1_loss
model.cuda()
count = 0
while True:
#    optimizer.zero_grad()
    input = torch.rand(30,1,200,200,200).cuda()
    loc_output= model(input)
    loc_outpus = loc_output
    if type(loc_output) == tuple:
        loc_output = loc_output[0]
    targets = torch.rand(loc_output.size()).cuda()
    loss = crit(loc_output,targets)
    loss.backward()
#    optimizer.step()
    del loss,loc_output,targets,input
    torch.cuda.empty_cache()
    count += 1
    print(count)
@zou3519
Copy link
Contributor

zou3519 commented Apr 3, 2018

Thanks for the report, @xichangzun. I can reproduce this and am looking into it.

zou3519 added a commit to zou3519/pytorch that referenced this issue Apr 3, 2018
Fixes pytorch#6222

We don't need to make sure gradInput is contiguous because it's always
passed in as an empty tensor (see CUDAFloatType.cpp after it gets
codegen-ed). This was increasing the reference on gradInput and leaking
it.

I'm not sure if there's a good way to test this. I put together a script
that
1) Prints out when a tensor is allocated and deallocated
2) Checks allocations vs deallocations after running a python script
And verified that each allocation matches each deallocation.
soumith pushed a commit that referenced this issue Apr 3, 2018
Fixes #6222

We don't need to make sure gradInput is contiguous because it's always
passed in as an empty tensor (see CUDAFloatType.cpp after it gets
codegen-ed). This was increasing the reference on gradInput and leaking
it.

I'm not sure if there's a good way to test this. I put together a script
that
1) Prints out when a tensor is allocated and deallocated
2) Checks allocations vs deallocations after running a python script
And verified that each allocation matches each deallocation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants