Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Post mortem 4.0] Format code files #1681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions calibration/BraTS/brats_cal_images_list.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import numpy as np

np.random.seed(0)
images = []
for i in [0, 2, 3, 4]:
with open("../../v0.7/medical_imaging/3d-unet/folds/fold{:d}_validation.txt".format(i)) as f:
with open(
"../../v0.7/medical_imaging/3d-unet/folds/fold{:d}_validation.txt".format(
i)
) as f:
for line in f:
images.append(line.rstrip())
indices = np.random.permutation(len(images))[:40]
selected = sorted([images[idx] for idx in indices])
with open("brats_cal_images_list.txt", "w") as f:
for img in selected:
print(img, file=f)
print(img, file=f)
134 changes: 98 additions & 36 deletions compliance/nvidia/TEST01/run_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,45 @@
"byte": np.byte,
"float32": np.float32,
"int32": np.int32,
"int64": np.int64
"int64": np.int64,
}

def main():

def main():

py3 = sys.version_info >= (3,0)
py3 = sys.version_info >= (3, 0)
# Parse arguments to identify the path to the accuracy logs from
# the accuracy and performance runs
parser = argparse.ArgumentParser()
parser.add_argument(
"--results_dir", "-r",
"--results_dir",
"-r",
help="Specifies the path to the corresponding results directory that contains the accuracy and performance subdirectories containing the submission logs, i.e. inference_results_v0.7/closed/NVIDIA/results/T4x8/resnet/Offline.",
required=True
required=True,
)
parser.add_argument(
"--compliance_dir", "-c",
"--compliance_dir",
"-c",
help="Specifies the path to the directory containing the logs from the compliance test run.",
required=True
required=True,
)
parser.add_argument(
"--output_dir", "-o",
"--output_dir",
"-o",
help="Specifies the path to the output directory where compliance logs will be uploaded from, i.e. inference_results_v0.7/closed/NVIDIA/compliance/T4x8/resnet/Offline.",
required=True
required=True,
)
parser.add_argument(
"--dtype", default="byte", choices=["byte", "float32", "int32", "int64"], help="data type of the label (not needed in unixmode")
"--dtype",
default="byte",
choices=["byte", "float32", "int32", "int64"],
help="data type of the label (not needed in unixmode",
)
parser.add_argument(
"--unixmode", action="store_true",
help="Use UNIX commandline utilities to verify accuracy (uses less memory but much slower.")
"--unixmode",
action="store_true",
help="Use UNIX commandline utilities to verify accuracy (uses less memory but much slower.",
)

args = parser.parse_args()

Expand All @@ -70,44 +79,81 @@ def main():
unixmode = " --unixmode"
for binary in ["wc", "md5sum", "grep", "awk", "sed", "head", "tail"]:
missing_binary = False
if shutil.which(binary) == None:
print("Error: This script requires the {:} commandline utility".format(binary))
if shutil.which(binary) is None:
print(
"Error: This script requires the {:} commandline utility".format(
binary
)
)
missing_binary = True
if missing_binary:
exit()

dtype = args.dtype

verify_accuracy_binary = os.path.join(os.path.dirname(__file__),"verify_accuracy.py")
verify_accuracy_binary = os.path.join(
os.path.dirname(__file__), "verify_accuracy.py"
)
# run verify accuracy
verify_accuracy_command = "python3 " + verify_accuracy_binary + " --dtype " + args.dtype + unixmode + " -r " + results_dir + "/accuracy/mlperf_log_accuracy.json" + " -t " + compliance_dir + "/mlperf_log_accuracy.json | tee verify_accuracy.txt"
verify_accuracy_command = (
"python3 "
+ verify_accuracy_binary
+ " --dtype "
+ args.dtype
+ unixmode
+ " -r "
+ results_dir
+ "/accuracy/mlperf_log_accuracy.json"
+ " -t "
+ compliance_dir
+ "/mlperf_log_accuracy.json | tee verify_accuracy.txt"
)
try:
os.system(verify_accuracy_command)
except Exception:
print("Exception occurred trying to execute:\n " + verify_accuracy_command)
print(
"Exception occurred trying to execute:\n " +
verify_accuracy_command)
# check if verify accuracy script passes

accuracy_pass_command = "grep PASS verify_accuracy.txt"
try:
accuracy_pass = "TEST PASS" in subprocess.check_output(accuracy_pass_command, shell=True).decode("utf-8")
accuracy_pass = "TEST PASS" in subprocess.check_output(
accuracy_pass_command, shell=True
).decode("utf-8")
except Exception:
accuracy_pass = False

# run verify performance
verify_performance_binary = os.path.join(os.path.dirname(__file__),"verify_performance.py")
verify_performance_command = "python3 " + verify_performance_binary + " -r " + results_dir + "/performance/run_1/mlperf_log_summary.txt" + " -t " + compliance_dir + "/mlperf_log_summary.txt | tee verify_performance.txt"
verify_performance_binary = os.path.join(
os.path.dirname(__file__), "verify_performance.py"
)
verify_performance_command = (
"python3 "
+ verify_performance_binary
+ " -r "
+ results_dir
+ "/performance/run_1/mlperf_log_summary.txt"
+ " -t "
+ compliance_dir
+ "/mlperf_log_summary.txt | tee verify_performance.txt"
)
try:
os.system(verify_performance_command)
except Exception:
print("Exception occurred trying to execute:\n " + verify_performance_command)
print(
"Exception occurred trying to execute:\n " +
verify_performance_command)

# check if verify performance script passes
performance_pass_command = "grep PASS verify_performance.txt"
try:
performance_pass = "TEST PASS" in subprocess.check_output(performance_pass_command, shell=True).decode("utf-8")
performance_pass = "TEST PASS" in subprocess.check_output(
performance_pass_command, shell=True
).decode("utf-8")
except Exception:
performance_pass = False

# setup output compliance directory structure
output_accuracy_dir = os.path.join(output_dir, "accuracy")
output_performance_dir = os.path.join(output_dir, "performance", "run_1")
Expand All @@ -123,28 +169,44 @@ def main():
print("Exception occurred trying to create " + output_performance_dir)

# copy compliance logs to output compliance directory
shutil.copy2("verify_accuracy.txt",output_dir)
shutil.copy2("verify_performance.txt",output_dir)
accuracy_file = os.path.join(compliance_dir,"mlperf_log_accuracy.json")
summary_file = os.path.join(compliance_dir,"mlperf_log_summary.txt")
detail_file = os.path.join(compliance_dir,"mlperf_log_detail.txt")
shutil.copy2("verify_accuracy.txt", output_dir)
shutil.copy2("verify_performance.txt", output_dir)
accuracy_file = os.path.join(compliance_dir, "mlperf_log_accuracy.json")
summary_file = os.path.join(compliance_dir, "mlperf_log_summary.txt")
detail_file = os.path.join(compliance_dir, "mlperf_log_detail.txt")

try:
shutil.copy2(accuracy_file,output_accuracy_dir)
shutil.copy2(accuracy_file, output_accuracy_dir)
except Exception:
print("Exception occured trying to copy " + accuracy_file + " to " + output_accuracy_dir)
print(
"Exception occured trying to copy "
+ accuracy_file
+ " to "
+ output_accuracy_dir
)
try:
shutil.copy2(summary_file,output_performance_dir)
shutil.copy2(summary_file, output_performance_dir)
except Exception:
print("Exception occured trying to copy " + summary_file + " to " + output_performance_dir)
print(
"Exception occured trying to copy "
+ summary_file
+ " to "
+ output_performance_dir
)
try:
shutil.copy2(detail_file,output_performance_dir)
shutil.copy2(detail_file, output_performance_dir)
except Exception:
print("Exception occured trying to copy " + detail_file + " to " + output_performance_dir)
print(
"Exception occured trying to copy "
+ detail_file
+ " to "
+ output_performance_dir
)

print("Accuracy check pass: {:}".format(accuracy_pass))
print("Performance check pass: {:}".format(performance_pass))
print("TEST01 verification complete")

if __name__ == '__main__':
main()

if __name__ == "__main__":
main()