validation prints immediatly in case of single job
Validate Operations / validate-operations (push) Has been cancelled
Validate Operations / validate-operations (push) Has been cancelled
This commit is contained in:
@@ -102,13 +102,6 @@ count with `-j` or `--jobs`:
|
|||||||
--jobs 8
|
--jobs 8
|
||||||
```
|
```
|
||||||
|
|
||||||
Each model's output is buffered as one readable block. Independent workspace
|
|
||||||
jobs print their blocks when they finish, so their order may differ from the
|
|
||||||
final table. The final result table is sorted by model path.
|
|
||||||
|
|
||||||
Models in the same directory run sequentially because they share generated
|
|
||||||
workspace paths.
|
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
| Option | Description |
|
| Option | Description |
|
||||||
|
|||||||
@@ -165,9 +165,9 @@ class ProgressReporter:
|
|||||||
if self.enabled:
|
if self.enabled:
|
||||||
self._clear()
|
self._clear()
|
||||||
if color:
|
if color:
|
||||||
print(color + message + Style.RESET_ALL)
|
print(color + message + Style.RESET_ALL, flush=True)
|
||||||
else:
|
else:
|
||||||
print(message)
|
print(message, flush=True)
|
||||||
self._render()
|
self._render()
|
||||||
|
|
||||||
def set_stage(self, model_index, model_total, model_name, stage_name):
|
def set_stage(self, model_index, model_total, model_name, stage_name):
|
||||||
|
|||||||
+55
-41
@@ -6,7 +6,7 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from concurrent.futures import ProcessPoolExecutor, as_completed
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
||||||
from contextlib import redirect_stderr, redirect_stdout
|
from contextlib import nullcontext, redirect_stderr, redirect_stdout
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
@@ -44,36 +44,43 @@ def run_validation_job(job):
|
|||||||
enabled=False,
|
enabled=False,
|
||||||
verbose=options["verbose"],
|
verbose=options["verbose"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate():
|
||||||
|
try:
|
||||||
|
return validate_network(
|
||||||
|
onnx_path,
|
||||||
|
reporter=reporter,
|
||||||
|
model_index=index,
|
||||||
|
model_total=options["model_total"],
|
||||||
|
verbose=options["verbose"],
|
||||||
|
mode=options["mode"],
|
||||||
|
**options["validation_kwargs"],
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
print_validation_error(reporter, rel, exc)
|
||||||
|
return ValidationResult(False, pimsim_status=PIMSIM_NOT_RUN)
|
||||||
|
finally:
|
||||||
|
reporter.finish()
|
||||||
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
saved_stdout = os.dup(1)
|
if log_path is None:
|
||||||
saved_stderr = os.dup(2)
|
result = validate()
|
||||||
try:
|
else:
|
||||||
with open(log_path, "w", encoding="utf-8", buffering=1) as log:
|
saved_stdout = os.dup(1)
|
||||||
os.dup2(log.fileno(), 1)
|
saved_stderr = os.dup(2)
|
||||||
os.dup2(log.fileno(), 2)
|
try:
|
||||||
with redirect_stdout(log), redirect_stderr(log):
|
with open(log_path, "w", encoding="utf-8", buffering=1) as log:
|
||||||
try:
|
os.dup2(log.fileno(), 1)
|
||||||
result = validate_network(
|
os.dup2(log.fileno(), 2)
|
||||||
onnx_path,
|
with redirect_stdout(log), redirect_stderr(log):
|
||||||
reporter=reporter,
|
result = validate()
|
||||||
model_index=index,
|
finally:
|
||||||
model_total=options["model_total"],
|
os.dup2(saved_stdout, 1)
|
||||||
verbose=options["verbose"],
|
os.dup2(saved_stderr, 2)
|
||||||
mode=options["mode"],
|
os.close(saved_stdout)
|
||||||
**options["validation_kwargs"],
|
os.close(saved_stderr)
|
||||||
)
|
completed.append((str(rel), result, str(log_path) if log_path else None))
|
||||||
except Exception as exc:
|
|
||||||
result = ValidationResult(False, pimsim_status=PIMSIM_NOT_RUN)
|
|
||||||
print_validation_error(reporter, rel, exc)
|
|
||||||
finally:
|
|
||||||
reporter.finish()
|
|
||||||
finally:
|
|
||||||
os.dup2(saved_stdout, 1)
|
|
||||||
os.dup2(saved_stderr, 2)
|
|
||||||
os.close(saved_stdout)
|
|
||||||
os.close(saved_stderr)
|
|
||||||
completed.append((str(rel), result, str(log_path)))
|
|
||||||
return completed
|
return completed
|
||||||
|
|
||||||
|
|
||||||
@@ -214,7 +221,7 @@ def main():
|
|||||||
|
|
||||||
print(Style.BRIGHT + f"Found {len(onnx_files)} ONNX file(s) to validate." + Style.RESET_ALL)
|
print(Style.BRIGHT + f"Found {len(onnx_files)} ONNX file(s) to validate." + Style.RESET_ALL)
|
||||||
print(f"Operations root: {operations_dir}")
|
print(f"Operations root: {operations_dir}")
|
||||||
print(f"Parallel jobs: {a.jobs}")
|
print(f"Max parallel jobs: {a.jobs}")
|
||||||
print("=" * 72)
|
print("=" * 72)
|
||||||
|
|
||||||
mode = MODE_FULL
|
mode = MODE_FULL
|
||||||
@@ -268,7 +275,8 @@ def main():
|
|||||||
list(group)
|
list(group)
|
||||||
for _, group in groupby(indexed_files, key=lambda indexed_path: indexed_path[1].parent)
|
for _, group in groupby(indexed_files, key=lambda indexed_path: indexed_path[1].parent)
|
||||||
]
|
]
|
||||||
with TemporaryDirectory(prefix="raptor-validation-") as log_dir:
|
print_directly = min(a.jobs, len(workspace_groups)) == 1
|
||||||
|
with (nullcontext(None) if print_directly else TemporaryDirectory(prefix="raptor-validation-")) as log_dir:
|
||||||
jobs = [
|
jobs = [
|
||||||
(
|
(
|
||||||
[
|
[
|
||||||
@@ -276,7 +284,7 @@ def main():
|
|||||||
index,
|
index,
|
||||||
onnx_path,
|
onnx_path,
|
||||||
onnx_path.relative_to(operations_dir),
|
onnx_path.relative_to(operations_dir),
|
||||||
Path(log_dir) / f"{index}.log",
|
Path(log_dir) / f"{index}.log" if log_dir else None,
|
||||||
)
|
)
|
||||||
for index, onnx_path in workspace_group
|
for index, onnx_path in workspace_group
|
||||||
],
|
],
|
||||||
@@ -289,16 +297,22 @@ def main():
|
|||||||
)
|
)
|
||||||
for workspace_group in workspace_groups
|
for workspace_group in workspace_groups
|
||||||
]
|
]
|
||||||
with ProcessPoolExecutor(max_workers=a.jobs) as executor:
|
with (nullcontext(None) if print_directly else ProcessPoolExecutor(max_workers=a.jobs)) as executor:
|
||||||
futures = [executor.submit(run_validation_job, job) for job in jobs]
|
completed_groups = (
|
||||||
for future in as_completed(futures):
|
map(run_validation_job, jobs)
|
||||||
completed_group = future.result()
|
if print_directly
|
||||||
|
else (future.result() for future in as_completed(
|
||||||
|
executor.submit(run_validation_job, job) for job in jobs
|
||||||
|
))
|
||||||
|
)
|
||||||
|
for completed_group in completed_groups:
|
||||||
for rel, result, log_path in completed_group:
|
for rel, result, log_path in completed_group:
|
||||||
reporter.suspend()
|
if log_path:
|
||||||
output = Path(log_path).read_text(encoding="utf-8", errors="replace")
|
reporter.suspend()
|
||||||
if output:
|
output = Path(log_path).read_text(encoding="utf-8", errors="replace")
|
||||||
print(output, end="" if output.endswith("\n") else "\n")
|
if output:
|
||||||
reporter.resume()
|
print(output, end="" if output.endswith("\n") else "\n")
|
||||||
|
reporter.resume()
|
||||||
reporter.advance()
|
reporter.advance()
|
||||||
reporter.record_result(result.passed)
|
reporter.record_result(result.passed)
|
||||||
results[rel] = result
|
results[rel] = result
|
||||||
|
|||||||
Reference in New Issue
Block a user