Skip to content

Commit 043f5d5

Browse files
EduardoPachclaude
andcommitted
Cache argmax-cli builds across engine instances in the same process
ArgmaxOpenSourceEngine.__init__ now consults a module-level dict keyed by (resolved cache_root, commit_hash) before cloning and building. The second engine constructed in a run — e.g. the WER metric's transcription engine after the TTS engine — reuses the resolved cli_path instead of re-running `swift build`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 62ad197 commit 043f5d5

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/openbench/engine/argmax_oss_engine.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
ARGMAX_OSS_PRODUCT = "argmax-cli"
1818
DEFAULT_CACHE_SUBDIR = Path(".cache") / "openbench" / "argmax-oss"
1919

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+
2026

2127
def resolve_argmax_oss_cache_dir(explicit: str | Path | None = None) -> Path:
2228
"""Absolute cache root for WhisperKit clone + `argmax-cli` build."""
@@ -97,9 +103,19 @@ def __init__(self, config: ArgmaxOpenSourceEngineConfig) -> None:
97103
self.config = config
98104
if config.cli_path:
99105
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
103119

104120
def _build_cli(self, repo_dir: str) -> str:
105121
"""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:
130146
logger.info("Built Argmax OSS CLI at %s", cli)
131147
return bin_dir
132148

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:
135150
cache_root.mkdir(parents=True, exist_ok=True)
136151
repo_url_parts = ARGMAX_OSS_REPO_URL.rstrip("/").split("/")
137152
repo_name = repo_url_parts[-1]

0 commit comments

Comments
 (0)