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

VideoReader - how to deallocate pipeline (release the GPU memory)? #1842

Closed
luizgh opened this issue Mar 27, 2020 · 4 comments
Closed

VideoReader - how to deallocate pipeline (release the GPU memory)? #1842

luizgh opened this issue Mar 27, 2020 · 4 comments
Labels
question Further information is requested

Comments

@luizgh
Copy link

luizgh commented Mar 27, 2020

Hi,

I am trying to use a pipeline with VideoReader for an activity detection detection task.

I want to run training and validation in the same script (validation after each epoch), and since the pipeline takes a lot of GPU memory, I cannot initialize both training and validation pipelines at the same time.

I want to initialize the training pipeline in the beginning of the epoch, and release it at the end (so that I can initialize the validation pipeline). However, I can't find a way for the pipeline to release the GPU memory (I saw issue #1048, but the person didn't say how he got it to work). Example code, using GC to delete the pipeline object:

from nvidia.dali.pipeline import Pipeline
import nvidia.dali.ops as ops
import nvidia.dali.types as types
import gc


class VideoPipe(Pipeline):
    def __init__(self, file_list, sequence_length, batch_size, device_id, shuffle):
        super(VideoPipe, self).__init__(batch_size, num_threads=2, device_id=device_id, seed=16, exec_async=False, exec_pipelined=False)

        self.input = ops.VideoReader(device="gpu", file_list=file_list, sequence_length=sequence_length,
                                     shard_id=0, num_shards=1, file_list_frame_num=True, enable_frame_num=True,
                                     random_shuffle=shuffle, initial_fill=16, step=1, dtype=types.DALIDataType.FLOAT)

    def define_graph(self):
        output = self.input(name="Reader")
        return output


pipe = VideoPipe('/disk/events_dali.txt', sequence_length=25, batch_size=8, device_id=0, shuffle=True)
pipe.build()
data = pipe.run()

del data
del pipe

gc.collect()  # Memory is not released

PS: I am setting exec_async and exec_pipelined to false so that I can use pytorch ops for data augmentation, while these are not natively supported in DALI

@JanuszL JanuszL added the question Further information is requested label Mar 27, 2020
@JanuszL
Copy link
Contributor

JanuszL commented Mar 27, 2020

Strange, doesn't work for me either. You can try to:

pipe._pipe = None

Works in my case. @mzient any idea what is going on there?

@luizgh
Copy link
Author

luizgh commented Mar 30, 2020

Thanks @JanuszL . This solves my problem. I'll leave the issue open, in case you want to track this (e.g. why setting pipe = None doesn't collect the memory), but feel free to close it.

@JanuszL JanuszL added this to the Release_0.21.0 milestone Mar 30, 2020
@JanuszL
Copy link
Contributor

JanuszL commented Mar 30, 2020

@luizgh - Indeed there is some reference leak. #1845 should fix this problem.

@JanuszL
Copy link
Contributor

JanuszL commented May 1, 2020

0.21 is available and should fix this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants