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

Is it possible to make validation_step and val_dataloader no-ops? #82

Closed
tc-wolf opened this issue Aug 8, 2019 · 5 comments
Closed
Labels
feature Is an improvement or enhancement help wanted Open to be worked on
Milestone

Comments

@tc-wolf
Copy link

tc-wolf commented Aug 8, 2019

Is your feature request related to a problem? Please describe.
Sometimes I don't have a separate validation split, only a train/test split. I'm trying out pytorch-lightning to prototype / experiment, and trying to see what the best of way of doing this is.

I could make the train dataset and then do torch.utils.data.random_split or use torch.utils.data.SubsetRandomSampler to build a validation set as well, but if I don't have enough data (or just don't want to do a separate validation step) this isn't ideal.

Describe the solution you'd like
I'd like to be able to implement only the training_step, train_dataloader, and test_dataloader methods and then have the validation step and validation metrics be omitted (maybe explicit no-ops). Right now, I'm experimenting with having an empty DataLoader for the validation data.

Describe alternatives you've considered

  • Implement val_dataloader with an empty (dummy) DataLoader
    • Not sure if this will work yet (if lightning will still call validation_step and validation_end).
@tc-wolf tc-wolf added feature Is an improvement or enhancement help wanted Open to be worked on labels Aug 8, 2019
@williamFalcon
Copy link
Contributor

williamFalcon commented Aug 9, 2019

great idea. val call can just be made optional! very easy to do.

do you want to give it a shot?

  1. remove notimplemented warning. add pass instead. (from validation_step)
  2. allow get val_dataloader to be none.
  3. in val loop check if val_loader is none (at very beginning). return if it is none.

@tc-wolf
Copy link
Author

tc-wolf commented Aug 9, 2019

Thanks, I'll take a stab at that this weekend!

@williamFalcon
Copy link
Contributor

live on master now

@singularperturbation
Copy link

Dang, too fast for me :) Thanks for working on this!

@pamparana34
Copy link

Sorry for writing to this thread but how can I use it in my model? Is it enough to do something like:

@pl.data_loader
def val_dataloader(self):
     if has_valset:        
        return self.__dataloader(train=False)
    
    # No validation set
    return None

After that do I need to do something like:

def validation_step(self, batch, batch_idx):
    # Is this check necessary?
    if not has_vaset:
        return
   
   # process the validation batch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement help wanted Open to be worked on
Projects
None yet
Development

No branches or pull requests

4 participants