problem with RAM allocating in FasterRCNN
See original GitHub issueHello. First of all I’d like to thank for adding object detection models to torchvision, it’s a great help for the community.
However, I encountered a problem while trying to use them. I just copied the example code from https://github.com/pytorch/vision/blob/3d5610391eaef38ae802ffe8b693ac17b13bd5d1/torchvision/models/detection/faster_rcnn.py#L102-L140
to a jupyter notebook and realized that during each execution of model(x)
(on CPU) more than 2 GB of RAM is grabbed and not released afterwards. Running del model
does not release RAM, only restarting the kernel does.
I met the same problem for the model defined in the following way:
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
in_features = model.roi_heads.box_predictor.cls_score.in_features
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
as stated in https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html
What to do to get rid of this problem? Thanks in advance.
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (11 by maintainers)
@buus2 this is not a leak, and you shouldn’t face OOM errors because of that.
As workarounds, use
torch.no_grad()
, and maybe usejemalloc
when running your programs.@fmassa you are right, with
no_grad
RAM does not clog. Could you please suggest a workaround for forwardpropagation during training?