Enable dedicated MMSeg full mmcv runtime

This commit is contained in:
2026-06-30 13:23:32 +08:00
parent 4d80ec4d75
commit 2d7d54ba13
10 changed files with 121 additions and 35 deletions

View File

@@ -13,20 +13,53 @@ from typing import Any
from .config import settings
def _run_command(command: list[str], cwd: Path | None = None, timeout: int = 60) -> dict[str, Any]:
try:
result = subprocess.run(
command,
cwd=str(cwd or settings.project_root),
capture_output=True,
text=True,
timeout=timeout,
)
return {
"passed": result.returncode == 0,
"returncode": result.returncode,
"stdout": result.stdout[-4000:],
"stderr": result.stderr[-4000:],
}
except subprocess.TimeoutExpired as exc:
return {
"passed": False,
"returncode": None,
"stdout": (exc.stdout or "")[-4000:] if isinstance(exc.stdout, str) else "",
"stderr": (exc.stderr or "")[-4000:] if isinstance(exc.stderr, str) else "",
"error": f"command timed out after {timeout}s",
}
except Exception as exc:
return {"passed": False, "returncode": None, "stdout": "", "stderr": "", "error": str(exc)}
def _run_snippet(code: str, cwd: Path | None = None, timeout: int = 60) -> dict[str, Any]:
result = subprocess.run(
[sys.executable, "-c", code],
cwd=str(cwd or settings.project_root),
capture_output=True,
text=True,
timeout=timeout,
)
return {
"passed": result.returncode == 0,
"returncode": result.returncode,
"stdout": result.stdout[-4000:],
"stderr": result.stderr[-4000:],
}
return _run_command([sys.executable, "-c", code], cwd=cwd, timeout=timeout)
def _run_conda_snippet(env_name: str, code: str, cwd: Path | None = None, timeout: int = 60) -> dict[str, Any]:
detail = _run_command(["conda", "run", "-n", env_name, "python", "-c", code], cwd=cwd, timeout=timeout)
detail["env"] = env_name
return detail
MMSEG_FULL_BUILD_SNIPPET = (
"from mmseg.utils import register_all_modules; "
"register_all_modules(init_default_scope=True); "
"from mmengine.config import Config; "
"from mmseg.registry import MODELS; "
"import mmcv._ext; "
"cfg=Config.fromfile({config_path!r}); "
"model=MODELS.build(cfg.model); "
"print(type(model).__name__)"
)
def _request_json(method: str, url: str, payload: dict[str, Any] | None = None, timeout: int = 10) -> dict[str, Any]:
@@ -182,13 +215,23 @@ def run_model_family_readiness() -> dict[str, Any]:
"required": True,
"detail": {"passed": mmseg_pretrained.exists(), "path": str(mmseg_pretrained), "size": mmseg_pretrained.stat().st_size if mmseg_pretrained.exists() else 0},
},
{
"name": "mmseg_full_env_imports",
"required": True,
"detail": _run_conda_snippet(
settings.mmseg_conda_env,
"import torch, cv2, mmcv, mmengine, mmseg; "
"import mmcv._ext; "
"print(torch.__version__, torch.version.cuda, cv2.__version__, mmcv.__version__, mmseg.__version__)",
timeout=90,
),
},
{
"name": "mmseg_full_model_build",
"required": False,
"detail": _run_snippet(
"from mmengine.config import Config; from mmseg.registry import MODELS; "
f"cfg=Config.fromfile({str(mmseg_config)!r}); "
"model=MODELS.build(cfg.model); print(type(model).__name__)",
"required": True,
"detail": _run_conda_snippet(
settings.mmseg_conda_env,
MMSEG_FULL_BUILD_SNIPPET.format(config_path=str(mmseg_config)),
timeout=90,
),
},