|
17 | 17 | ARGMAX_OSS_PRODUCT = "argmax-cli" |
18 | 18 | DEFAULT_CACHE_SUBDIR = Path(".cache") / "openbench" / "argmax-oss" |
19 | 19 |
|
| 20 | +# Process-wide cache of resolved CLI binary paths, keyed by (cache_root, commit_hash). |
| 21 | +# Avoids re-cloning and re-invoking `swift build` when multiple pipelines (e.g. a |
| 22 | +# TTS pipeline + the WER metric's transcription pipeline) build their own engine |
| 23 | +# instances in the same run. |
| 24 | +_CLI_PATH_CACHE: dict[tuple[str, str | None], str] = {} |
| 25 | + |
20 | 26 |
|
21 | 27 | def resolve_argmax_oss_cache_dir(explicit: str | Path | None = None) -> Path: |
22 | 28 | """Absolute cache root for WhisperKit clone + `argmax-cli` build.""" |
@@ -97,9 +103,19 @@ def __init__(self, config: ArgmaxOpenSourceEngineConfig) -> None: |
97 | 103 | self.config = config |
98 | 104 | if config.cli_path: |
99 | 105 | self.cli_path = str(Path(config.cli_path).expanduser().resolve()) |
100 | | - logger.info(f"Using Argmax OSS CLI at {self.cli_path}") |
101 | | - else: |
102 | | - self.cli_path = self._clone_and_build_cli() |
| 106 | + logger.info("Using Argmax OSS CLI at %s", self.cli_path) |
| 107 | + return |
| 108 | + |
| 109 | + cache_root = resolve_argmax_oss_cache_dir(config.cache_dir) |
| 110 | + cache_key = (str(cache_root), config.commit_hash) |
| 111 | + cached_cli_path = _CLI_PATH_CACHE.get(cache_key) |
| 112 | + if cached_cli_path is not None: |
| 113 | + logger.info("Reusing cached Argmax OSS CLI at %s", cached_cli_path) |
| 114 | + self.cli_path = cached_cli_path |
| 115 | + return |
| 116 | + |
| 117 | + self.cli_path = self._clone_and_build_cli(cache_root) |
| 118 | + _CLI_PATH_CACHE[cache_key] = self.cli_path |
103 | 119 |
|
104 | 120 | def _build_cli(self, repo_dir: str) -> str: |
105 | 121 | """Run release build (swift build -c release, not debug) and return the dir containing the binary.""" |
@@ -130,8 +146,7 @@ def _build_cli(self, repo_dir: str) -> str: |
130 | 146 | logger.info("Built Argmax OSS CLI at %s", cli) |
131 | 147 | return bin_dir |
132 | 148 |
|
133 | | - def _clone_and_build_cli(self) -> str: |
134 | | - cache_root = resolve_argmax_oss_cache_dir(self.config.cache_dir) |
| 149 | + def _clone_and_build_cli(self, cache_root: Path) -> str: |
135 | 150 | cache_root.mkdir(parents=True, exist_ok=True) |
136 | 151 | repo_url_parts = ARGMAX_OSS_REPO_URL.rstrip("/").split("/") |
137 | 152 | repo_name = repo_url_parts[-1] |
|
0 commit comments