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

[FEAT] support providing DataLoader arguments to optimize GPU usage #1186

Merged
merged 13 commits into from
Nov 8, 2024

Conversation

jasminerienecker
Copy link
Contributor

This is to allow adjusting the torch pin_memory and prefetch_factor variables to optimize gpu usage.

Note: by adjusting these variables I am now able to increase GPU usage to 95% whereas with just the num_workers variable that is currently exposed to the interface, GPU usage hovers around 40-60%.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@CLAassistant
Copy link

CLAassistant commented Oct 21, 2024

CLA assistant check
All committers have signed the CLA.

@jmoralez
Copy link
Member

I'd prefer to introduce a single argument like dataloader_kwargs that gets passed to the dataloaders constructors and deprecate the num_workers_loader argument instead. That way we could also support persistent_workers for example.

@jasminerienecker
Copy link
Contributor Author

I'd prefer to introduce a single argument like dataloader_kwargs that gets passed to the dataloaders constructors and deprecate the num_workers_loader argument instead. That way we could also support persistent_workers for example.

I've updated this - the review is now essentially a direct replacement of the num_workers variables with a dataloader_kwargs dictionary (with default None)

@jmoralez
Copy link
Member

Sorry, by deprecating I meant keeping the argument and then doing something like:

if self.num_workers_loader != 0:  # value is not at its default
    warnings.warn(
        "The `num_workers_loader` argument is deprecated and will be removed in a future version. "
        "Please provide num_workers through `dataloader_kwargs`, e.g. "
        f"`dataloader_kwargs={'num_workers': {self.num_workers_loader}`",
        category=FutureWarning,
    )
dataloader_kwargs['num_workers'] = self.num_workers_loader

@jasminerienecker
Copy link
Contributor Author

Sorry, by deprecating I meant keeping the argument and then doing something like:

if self.num_workers_loader != 0:  # value is not at its default

    warnings.warn(

        "The `num_workers_loader` argument is deprecated and will be removed in a future version. "

        "Please provide num_workers through `dataloader_kwargs`, e.g. "

        f"`dataloader_kwargs={'num_workers': {self.num_workers_loader}`",

        category=FutureWarning,

    )

dataloader_kwargs['num_workers'] = self.num_workers_loader

@jmoralez ah yes I see - I've put that back in now and added the deprecation warnings to the base models class

@jmoralez
Copy link
Member

Thanks! Sorry, I messed up the suggestion, we should do the dataloader_kwargs['num_workers'] = self.num_workers_loader inside the if block, otherwise we'll override them every time, instead of just when the user wants to set it.

@jmoralez jmoralez changed the title [FEAT] enable setting gpu optimization variables [FEAT] support providing DataLoader arguments to optimize GPU usage Oct 30, 2024
@jasminerienecker
Copy link
Contributor Author

@jmoralez makes sense - that should be updated in both cases now!

@jmoralez
Copy link
Member

Thanks! I'm very sorry, I just realized from your changes to BaseRecurrent that we have a similar argument for predict called data_module_kwargs, although I don't think you can provide useful arguments to the data module through it, just batch_size, drop_last and shuffle_train which aren't used during predict.

@cchallu what's the purpose of the data_module_kwargs argument?

@jmoralez
Copy link
Member

@jasminerienecker in the meantime, can you please revert the changes to the predict method of BaseRecurrent? We can limit this PR to adding arguments to the training step.

@jasminerienecker
Copy link
Contributor Author

@jmoralez all good - that's now been updated

Copy link
Member

@jmoralez jmoralez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jmoralez jmoralez requested review from cchallu and elephaint November 4, 2024 18:41
neuralforecast/common/_base_recurrent.py Outdated Show resolved Hide resolved
@jmoralez jmoralez merged commit 5e3ad97 into Nixtla:main Nov 8, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants