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

Grab one sample from pipeline for shaping and reset pipeline #5275

Open
1 task done
jramapuram opened this issue Jan 10, 2024 · 6 comments
Open
1 task done

Grab one sample from pipeline for shaping and reset pipeline #5275

jramapuram opened this issue Jan 10, 2024 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@jramapuram
Copy link

Describe the question.

Is it possible to grab a single sample of (imgs, labels) from the pipeline and reset it? This is mainly for shape checking.

I see in the docs that:

  • pipe.reset() is only usable at the end of iteration?
  • If I iterate the pipeline for one step the pipeline is missing 1 minibatch for training.

Why?

  • Want to grab shaping / labels for model creation, etc.

Check for duplicates

  • I have searched the open bugs/issues and have found no duplicates for this bug report
@jramapuram jramapuram added the question Further information is requested label Jan 10, 2024
@JanuszL
Copy link
Contributor

JanuszL commented Jan 10, 2024

Hi @jramapuram,

Thank you for reaching out.
In your case, you can either recreate the pipeline to fully reset it, or keep the output of the first iteration and reuse it in further training.
Also in many cases, the pipeline definition determines the output shape - it is a common pattern to use resize/crop operation to have a fixed shape at the data processing output.
Can you also describe in more detail your use case and why you need to run the processing to determine the shape?

@jramapuram
Copy link
Author

jramapuram commented Jan 10, 2024

Heya @JanuszL -- hope you are well!

Also in many cases, the pipeline definition determines the output shape - it is a common pattern to use resize/crop operation to have a fixed shape at the data processing output.

Good point. This might be the smarter option actually. Will be there any issues with memory if the pipeline is re-init?

Can you also describe in more detail your use case and why you need to run the processing to determine the shape?

It is mainly to handle pipelines that return augmentation multiplicity > 1 (eg: DINO and other self-supervised algorithms use 2 images of resolution1 and 10x images of resolution2 in a minibatch). But you are right. This should be determinable apriori.

@jramapuram
Copy link
Author

jramapuram commented Jan 13, 2024

@JanuszL : I tried deleting the pipeline and re-creating it, however there seems to be a weird oddity with GPU memory over the entire training run 😬

GPU Memory (%) del dataloader; gc.collect()
68.76% N/A (baseline single pipeline creation)
77.1% yes
76.9% yes

These are on an A100 80G x8 instance.

@JanuszL
Copy link
Contributor

JanuszL commented Jan 15, 2024

Hi @jramapuram,

If you want to release DALI memory that is kept in the pool, please check this API.

@jramapuram
Copy link
Author

Still not working as expected @JanuszL -- memory at 77%. Any thoughts?

    class DataLoader:
        self.train_loader, self.test_loader, self.valid_loader = self._recreate_dataloaders()

        # ...

        self._delete_loaders()
        self.train_loader, self.test_loader, self.valid_loader = self._recreate_dataloaders()

    def _delete_loaders(self):
        """Delete loaders if they exist."""
        if self.train_loader is not None:
            del self.train_loader

        if self.test_loader is not None:
            del self.test_loader

        if self.valid_loader is not None:
            del self.valid_loader

        # Release memory in pool
        ReleaseUnusedMemory()

        # Force garbage collection
        gc.collect()

@JanuszL
Copy link
Contributor

JanuszL commented Jan 15, 2024

@jramapuram,

Can you provide a standalone repro for the case you see? Now I can only guess what may be going on, and I can just miss details that differentiate your code from the case I have in mind.. It can even be a toy example using data from https://github.com/NVIDIA/DALI_extra.

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