Hi @ptrblck,
I’m having similar problem , Whenever i run my code i get “cuda out of memory” error …
I’ve checked FairSeq method but i couldn’t figure it out where to put and how to use his method !!
            try:
                _loss, sample_size, logging_output = self.task.valid_step(
                    sample, self.model, self.criterion
                )
            except RuntimeError as e:
                if 'out of memory' in str(e) and not raise_oom:
                    print('| WARNING: ran out of memory, retrying batch')
                    for p in self.model.parameters():
                        if p.grad is not None:
                            del p.grad  # free some memory
                    torch.cuda.empty_cache()
                    return self.valid_step(sample, raise_oom=True)
                else:
                    raise e

Where should i use Try ? when defining my Network ? Plz help .
Thanks.