Loading fairseq/multiprocessing_trainer.py +1 −0 Changes for fairseq/multiprocessing_trainer.py: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -227,6 +227,7 @@ class MultiprocessingTrainer(MultiprocessingEventLoop): self.model.train() self.optimizer.zero_grad() with utils.maybe_no_grad(eval): sample_size, logging_output, oom = 0, {}, False if self._sample is not None: try: Loading fairseq/utils.py +8 −0 Changes for fairseq/utils.py: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ # can be found in the PATENTS file in the same directory. # import contextlib import logging import os import torch Loading Loading @@ -244,3 +245,10 @@ def rstrip_pad(tensor, pad): if strip > 0: return tensor[:-strip] return tensor def maybe_no_grad(condition): if hasattr(torch, 'no_grad') and condition: return torch.no_grad() # no-op context manager return contextlib.ExitStack() generate.py +2 −0 Changes for generate.py: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ def main(): print(args) use_cuda = torch.cuda.is_available() and not args.cpu if hasattr(torch, 'set_grad_enabled'): torch.set_grad_enabled(False) # Load dataset if args.replace_unk is None: Loading Loading
fairseq/multiprocessing_trainer.py +1 −0 Changes for fairseq/multiprocessing_trainer.py: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -227,6 +227,7 @@ class MultiprocessingTrainer(MultiprocessingEventLoop): self.model.train() self.optimizer.zero_grad() with utils.maybe_no_grad(eval): sample_size, logging_output, oom = 0, {}, False if self._sample is not None: try: Loading
fairseq/utils.py +8 −0 Changes for fairseq/utils.py: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ # can be found in the PATENTS file in the same directory. # import contextlib import logging import os import torch Loading Loading @@ -244,3 +245,10 @@ def rstrip_pad(tensor, pad): if strip > 0: return tensor[:-strip] return tensor def maybe_no_grad(condition): if hasattr(torch, 'no_grad') and condition: return torch.no_grad() # no-op context manager return contextlib.ExitStack()
generate.py +2 −0 Changes for generate.py: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ def main(): print(args) use_cuda = torch.cuda.is_available() and not args.cpu if hasattr(torch, 'set_grad_enabled'): torch.set_grad_enabled(False) # Load dataset if args.replace_unk is None: Loading