yongqiang commited on
Commit ·
83c76bb
1
Parent(s): ba96580
launcher_axmodel 移除对编译上下文的依赖
Browse files297 unmodified lines29829930030130230329 unmodified lines333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365297 unmodified linesif spec.label not in self._session_cache:path = self._expected_path(spec)self._session_cache[spec.label] = AxInferenceSession(path.as_posix())return self._session_cache[spec.label]def close(self) -> None:29 unmodified linesdef _load_auto_specs(self) -> List[SubGraphSpec]:specs: List[SubGraphSpec] = []for path in sorted(self.model_dir.glob("auto_*.axmodel")):# Ax compiler有两种输出目录命名:compiled_{stem} 或 compiled_auto_XXcandidates = [path.parent / f"compiled_{path.stem}"]# 兼容实际产物 compiled_auto_00 这类名称parts = path.stem.split("_", 3)if len(parts) >= 2:candidates.append(path.parent / f"compiled_{parts[0]}_{parts[1]}")ctx_path = Nonefor cand in candidates:candidate_ctx = cand / "build_context.json"if candidate_ctx.exists():ctx_path = candidate_ctxbreakif ctx_path is None:logger.warning(f"跳过 {path.name},缺少 build_context.json (尝试: {[c.as_posix() for c in candidates]})")continueif not ctx_path.exists():logger.warning(f"跳过 {path.name},缺少 build_context.json")continuetry:with ctx_path.open("r", encoding="utf-8") as f:ctx = json.load(f)inputs = [p.get("tensor_name") for p in ctx.get("cfg", {}).get("input_processors", []) if p.get("tensor_name")]outputs = [p.get("tensor_name") for p in ctx.get("cfg", {}).get("output_processors", []) if p.get("tensor_name")]except Exception as exc: # pragma: no cover - defensivelogger.warning(f"解析 {ctx_path} 失败: {exc}")continueif not inputs or not outputs:297 unmodified lines29829930030130230330429 unmodified lines334335336337338339340341342343344345346347297 unmodified linesif spec.label not in self._session_cache:path = self._expected_path(spec)self._session_cache[spec.label] = AxInferenceSession(path.as_posix())logger.info(f"加载子图 session: {spec.label} from {path.name}")return self._session_cache[spec.label]def close(self) -> None:29 unmodified linesdef _load_auto_specs(self) -> List[SubGraphSpec]:specs: List[SubGraphSpec] = []for path in sorted(self.model_dir.glob("auto_*.axmodel")):try:session = AxInferenceSession(path.as_posix())inputs = [info.name for info in session.get_inputs() if getattr(info, "name", None)]outputs = [info.name for info in session.get_outputs() if getattr(info, "name", None)]# 缓存 session,避免重复打开self._session_cache[path.stem] = sessionexcept Exception as exc: # pragma: no cover - defensivelogger.warning(f"跳过 {path.name},加载/解析 IO 失败: {exc}")continueif not inputs or not outputs:
VideoX-Fun/examples/z_image_fun/launcher_axmodel.py+7-25