remove existed dir for output external data (#8887)

This commit is contained in:
Tianlei Wu 2021-08-30 21:23:07 -07:00 committed by GitHub
parent a171d13b19
commit f6e7cd8050
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,7 +7,7 @@
import os
import logging
import torch
import onnx
import shutil
import random
import numpy
import time
@ -777,6 +777,16 @@ class Gpt2Helper:
model_name += "_past"
if new_folder:
# Remove the directories if existed.
for suffix in ["", "_fp32", "_fp16", "_int8"]:
new_dir = os.path.join(output_dir, model_name + suffix)
if os.path.exists(new_dir):
try:
shutil.rmtree(new_dir)
logger.info(f"Removed the existed directory: {new_dir}")
except OSError as e:
logger.info(f"Failed to remove the directory {new_dir}: {e.strerror}")
# store each model to its own directory (for external data format).
return {
"raw": os.path.join(os.path.join(output_dir, model_name), model_name + ".onnx"),