Fix build nondeterminism.
The zip file entries had real timestamps, which were inconsistent across builds. Passing a ZipInfo uses fixed timestamps. And, the report.html file in the zip file contained nondeterministic tmp file paths, so this replaces those paths with a placeholder so the output is deterministic. PiperOrigin-RevId: 358828255 Change-Id: Id6866922505164f1561ceb4c035cf9f6c17a3f60
This commit is contained in:
parent
9f8d5d0ef4
commit
41ff247456
@ -333,5 +333,6 @@ def generate_multi_set_examples(options, test_sets):
|
||||
|
||||
generate_examples(new_options)
|
||||
|
||||
archive.writestr("manifest.txt", "".join(multi_gen_state.zip_manifest),
|
||||
zipinfo = zipfile.ZipInfo("manifest.txt")
|
||||
archive.writestr(zipinfo, "".join(multi_gen_state.zip_manifest),
|
||||
zipfile.ZIP_DEFLATED)
|
||||
|
@ -23,6 +23,7 @@ from __future__ import print_function
|
||||
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
|
||||
FAILED = "FAILED"
|
||||
SUCCESS = "SUCCESS"
|
||||
@ -76,8 +77,8 @@ log.innerHTML = "<pre>" + data[row][col] + "</pre>";
|
||||
}
|
||||
""")
|
||||
fp.write("var data = \n")
|
||||
logs = json.dumps([[html.escape(x[1]["tf_log"], quote=True),
|
||||
html.escape(x[1]["converter_log"], quote=True)
|
||||
logs = json.dumps([[escape_and_normalize(x[1]["tf_log"]),
|
||||
escape_and_normalize(x[1]["converter_log"])
|
||||
] for x in reports])
|
||||
fp.write(logs)
|
||||
fp.write(";</script>\n")
|
||||
@ -124,3 +125,12 @@ log.innerHTML = "<pre>" + data[row][col] + "</pre>";
|
||||
</body>
|
||||
</html>
|
||||
""")
|
||||
|
||||
|
||||
def escape_and_normalize(log):
|
||||
# These logs contain paths like /tmp/tmpgmypg3xa that are inconsistent between
|
||||
# builds. This replaces these inconsistent paths with a consistent placeholder
|
||||
# so the output is deterministic.
|
||||
log = re.sub(r"/tmp/[^ ]+ ", "/NORMALIZED_TMP_FILE_PATH ", log)
|
||||
log = re.sub(r"/build/work/[^/]+", "/NORMALIZED_BUILD_PATH", log)
|
||||
return html.escape(log, quote=True)
|
||||
|
@ -478,8 +478,8 @@ def make_zip_of_tests(options,
|
||||
report["converter_log"] = toco_log
|
||||
|
||||
if options.save_graphdefs:
|
||||
archive.writestr(zip_path_label + ".pbtxt",
|
||||
text_format.MessageToString(graph_def),
|
||||
zipinfo = zipfile.ZipInfo(zip_path_label + ".pbtxt")
|
||||
archive.writestr(zipinfo, text_format.MessageToString(graph_def),
|
||||
zipfile.ZIP_DEFLATED)
|
||||
|
||||
if tflite_model_binary:
|
||||
@ -487,19 +487,20 @@ def make_zip_of_tests(options,
|
||||
# Set proper min max values according to input dtype.
|
||||
baseline_inputs, baseline_outputs = generate_inputs_outputs(
|
||||
tflite_model_binary, min_value=0, max_value=255)
|
||||
archive.writestr(zip_path_label + ".bin", tflite_model_binary,
|
||||
zipfile.ZIP_DEFLATED)
|
||||
zipinfo = zipfile.ZipInfo(zip_path_label + ".bin")
|
||||
archive.writestr(zipinfo, tflite_model_binary, zipfile.ZIP_DEFLATED)
|
||||
example = {"inputs": baseline_inputs, "outputs": baseline_outputs}
|
||||
|
||||
example_fp = StringIO()
|
||||
write_examples(example_fp, [example])
|
||||
archive.writestr(zip_path_label + ".inputs", example_fp.getvalue(),
|
||||
zipfile.ZIP_DEFLATED)
|
||||
zipinfo = zipfile.ZipInfo(zip_path_label + ".inputs")
|
||||
archive.writestr(zipinfo, example_fp.getvalue(), zipfile.ZIP_DEFLATED)
|
||||
|
||||
example_fp2 = StringIO()
|
||||
write_test_cases(example_fp2, zip_path_label + ".bin", [example])
|
||||
archive.writestr(zip_path_label + "_tests.txt",
|
||||
example_fp2.getvalue(), zipfile.ZIP_DEFLATED)
|
||||
zipinfo = zipfile.ZipInfo(zip_path_label + "_tests.txt")
|
||||
archive.writestr(zipinfo, example_fp2.getvalue(),
|
||||
zipfile.ZIP_DEFLATED)
|
||||
|
||||
zip_manifest_label = zip_path_label + " " + label
|
||||
if zip_path_label == label:
|
||||
@ -529,16 +530,18 @@ def make_zip_of_tests(options,
|
||||
report_io = StringIO()
|
||||
report_lib.make_report_table(report_io, zip_path, convert_report)
|
||||
if options.multi_gen_state:
|
||||
archive.writestr("report_" + options.multi_gen_state.test_name + ".html",
|
||||
report_io.getvalue())
|
||||
zipinfo = zipfile.ZipInfo("report_" + options.multi_gen_state.test_name +
|
||||
".html")
|
||||
archive.writestr(zipinfo, report_io.getvalue())
|
||||
else:
|
||||
archive.writestr("report.html", report_io.getvalue())
|
||||
zipinfo = zipfile.ZipInfo("report.html")
|
||||
archive.writestr(zipinfo, report_io.getvalue())
|
||||
|
||||
if options.multi_gen_state:
|
||||
options.multi_gen_state.zip_manifest.extend(zip_manifest)
|
||||
else:
|
||||
archive.writestr("manifest.txt", "".join(zip_manifest),
|
||||
zipfile.ZIP_DEFLATED)
|
||||
zipinfo = zipfile.ZipInfo("manifest.txt")
|
||||
archive.writestr(zipinfo, "".join(zip_manifest), zipfile.ZIP_DEFLATED)
|
||||
|
||||
# Log statistics of what succeeded
|
||||
total_conversions = len(convert_report)
|
||||
|
Loading…
x
Reference in New Issue
Block a user