save_pretrained: mkdir(exist_ok=True) (#5258)

* all save_pretrained methods mkdir if not os.path.exists
This commit is contained in:
Sam Shleifer
2020-06-28 14:53:47 -04:00
committed by GitHub
parent 12dfbd4f7a
commit 45e26125de
16 changed files with 17 additions and 59 deletions

View File

@@ -132,10 +132,9 @@ class PretrainedConfig(object):
save_directory (:obj:`string`):
Directory where the configuration JSON file will be saved.
"""
assert os.path.isdir(
save_directory
), "Saving path should be a directory where the model and configuration can be saved"
if os.path.isfile(save_directory):
raise AssertionError("Provided path ({}) should be a directory, not a file".format(save_directory))
os.makedirs(save_directory, exist_ok=True)
# If we save using the predefined names, we can load using `from_pretrained`
output_config_file = os.path.join(save_directory, CONFIG_NAME)