From 2bb3f72c0b57912975b1b483b1894803e6b64226 Mon Sep 17 00:00:00 2001 From: Stephen Roller Date: Thu, 29 Apr 2021 21:00:52 -0400 Subject: [PATCH] [fbcode] Add support for PathManager in vacuum (#3635) * [fbcode] Add support for PathManager in vacuum * Move requirements to iopath. --- parlai/scripts/vacuum.py | 5 ++--- parlai/utils/io.py | 4 ++-- requirements.txt | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/parlai/scripts/vacuum.py b/parlai/scripts/vacuum.py index 4f2ef9f285b..6e9db770cc8 100644 --- a/parlai/scripts/vacuum.py +++ b/parlai/scripts/vacuum.py @@ -10,7 +10,6 @@ Assumes we are working with a TorchAgent """ -import os import torch from parlai.core.params import ParlaiParser @@ -46,7 +45,7 @@ def run(self): model_file = self.opt['path'] if not model_file: raise RuntimeError('--model-file argument is required') - if not os.path.isfile(model_file): + if not PathManager.isfile(model_file): raise RuntimeError(f"'{model_file}' does not exist") logging.info(f"Loading {model_file}") with PathManager.open(model_file, 'rb') as f: @@ -55,7 +54,7 @@ def run(self): ) if not self.opt['no_backup']: logging.info(f"Backing up {model_file} to {model_file}.unvacuumed") - os.rename(model_file, model_file + ".unvacuumed") + PathManager.mv(model_file, model_file + ".unvacuumed") for key in [ 'optimizer', 'optimizer_type', diff --git a/parlai/utils/io.py b/parlai/utils/io.py index cf352db40ce..3e20c4de431 100644 --- a/parlai/utils/io.py +++ b/parlai/utils/io.py @@ -11,8 +11,8 @@ from fvcore.common.file_io import PathManagerBase as _PathManager except ImportError: raise ImportError( - "parlai now requires fvcore for some I/O operations. Please run " - "`pip install fvcore==0.1.1.post20200716`" + "parlai now requires iopath for some I/O operations. Please run " + "`pip install iopath`" ) USE_ATOMIC_TORCH_SAVE = True diff --git a/requirements.txt b/requirements.txt index 82aba739966..fd28f62fd2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ emoji==0.5.4 docformatter==1.3.0 flake8-bugbear==19.8.0 flake8==3.7.8 -fvcore==0.1.1.post20200716 +iopath~=0.1.8 gitdb2==2.0.5 GitPython==3.0.3 hydra-core~=1.0.6