Show retrain progress in Android
This commit is contained in:
@@ -54,12 +54,14 @@ def poll_once(args: argparse.Namespace, repo_root: Path, runtime_dir: Path, log_
|
||||
if not job_id:
|
||||
return
|
||||
log(log_path, f"Claimed retrain job {job_id}")
|
||||
report_progress(args, job_id, "running", "claimed", 2, "Задание получено Windows-agent")
|
||||
success = False
|
||||
message = ""
|
||||
summary: dict[str, Any] = {}
|
||||
try:
|
||||
run_retrain(job, repo_root, log_path)
|
||||
run_retrain(args, job_id, job, repo_root, log_path)
|
||||
summary = read_json(runtime_dir / "torch_retrain_guard.json")
|
||||
report_progress(args, job_id, "running", "uploading", 72, "Обучение завершено, загружаю артефакты")
|
||||
for name in ARTIFACT_NAMES:
|
||||
path = runtime_dir / name
|
||||
if path.is_file():
|
||||
@@ -75,7 +77,7 @@ def poll_once(args: argparse.Namespace, repo_root: Path, runtime_dir: Path, log_
|
||||
api_json(args, f"/api/training/jobs/{job_id}/complete", payload)
|
||||
|
||||
|
||||
def run_retrain(job: dict[str, Any], repo_root: Path, log_path: Path) -> None:
|
||||
def run_retrain(args: argparse.Namespace, job_id: str, job: dict[str, Any], repo_root: Path, log_path: Path) -> None:
|
||||
script = repo_root / "tools" / "run_torch_retrain.ps1"
|
||||
if not script.is_file():
|
||||
raise RuntimeError(f"retrain script not found: {script}")
|
||||
@@ -103,6 +105,8 @@ def run_retrain(job: dict[str, Any], repo_root: Path, log_path: Path) -> None:
|
||||
if value not in (None, ""):
|
||||
cmd.extend([ps_arg, str(value)])
|
||||
log(log_path, "Running retrain: " + " ".join(quote_for_log(part) for part in cmd))
|
||||
report_progress(args, job_id, "running", "training", 8, "PyTorch retrain запущен")
|
||||
line_count = 0
|
||||
with subprocess.Popen(
|
||||
cmd,
|
||||
cwd=str(repo_root),
|
||||
@@ -114,10 +118,16 @@ def run_retrain(job: dict[str, Any], repo_root: Path, log_path: Path) -> None:
|
||||
) as process:
|
||||
assert process.stdout is not None
|
||||
for line in process.stdout:
|
||||
log(log_path, line.rstrip())
|
||||
message = line.rstrip()
|
||||
log(log_path, message)
|
||||
line_count += 1
|
||||
if line_count == 1 or line_count % 12 == 0:
|
||||
progress = min(70, 8 + line_count // 3)
|
||||
report_progress(args, job_id, "running", "training", progress, message[-220:])
|
||||
code = process.wait()
|
||||
if code != 0:
|
||||
raise RuntimeError(f"retrain failed with exit code {code}")
|
||||
report_progress(args, job_id, "running", "guard", 70, "Guard завершён, подготавливаю артефакты")
|
||||
|
||||
|
||||
def upload_artifact(args: argparse.Namespace, job_id: str, path: Path, log_path: Path) -> None:
|
||||
@@ -137,6 +147,30 @@ def upload_artifact(args: argparse.Namespace, job_id: str, path: Path, log_path:
|
||||
"data_base64": base64.b64encode(data).decode("ascii"),
|
||||
}
|
||||
api_json(args, f"/api/training/jobs/{job_id}/artifacts/chunk", payload, timeout=120)
|
||||
if index == 0 or index == total - 1 or index % 10 == 0:
|
||||
progress = 72 + int(((index + 1) / total) * 23)
|
||||
report_progress(args, job_id, "running", "uploading", progress, f"Загружаю {path.name}: {index + 1}/{total}")
|
||||
|
||||
|
||||
def report_progress(
|
||||
args: argparse.Namespace,
|
||||
job_id: str,
|
||||
status: str,
|
||||
phase: str,
|
||||
progress_percent: int,
|
||||
message: str,
|
||||
) -> None:
|
||||
api_json(
|
||||
args,
|
||||
f"/api/training/jobs/{job_id}/progress",
|
||||
{
|
||||
"status": status,
|
||||
"phase": phase,
|
||||
"progress_percent": progress_percent,
|
||||
"message": message,
|
||||
"worker": worker_payload(args, Path(args.repo_root).resolve()),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def api_json(args: argparse.Namespace, path: str, payload: dict[str, Any], timeout: int = 30) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user