|
10 | 10 | vec_inf.client.models : Data models for API responses |
11 | 11 | """ |
12 | 12 |
|
| 13 | +import shutil |
13 | 14 | import time |
14 | 15 | import warnings |
| 16 | +from pathlib import Path |
15 | 17 | from typing import Any, Optional, Union |
16 | 18 |
|
17 | 19 | from vec_inf.client._exceptions import ( |
|
24 | 26 | ModelStatusMonitor, |
25 | 27 | PerformanceMetricsCollector, |
26 | 28 | ) |
27 | | -from vec_inf.client._utils import run_bash_command |
| 29 | +from vec_inf.client._utils import find_matching_dirs, run_bash_command |
28 | 30 | from vec_inf.client.config import ModelConfig |
29 | 31 | from vec_inf.client.models import ( |
30 | 32 | LaunchOptions, |
@@ -60,6 +62,9 @@ class VecInfClient: |
60 | 62 | wait_until_ready(slurm_job_id, timeout_seconds, poll_interval_seconds, log_dir) |
61 | 63 | Wait for a model to become ready |
62 | 64 |
|
| 65 | + cleanup_logs(log_dir, model_name, model_family, job_id, dry_run) |
| 66 | + Remove logs from the log directory. |
| 67 | +
|
63 | 68 | Examples |
64 | 69 | -------- |
65 | 70 | >>> from vec_inf.api import VecInfClient |
@@ -300,3 +305,47 @@ def wait_until_ready( |
300 | 305 |
|
301 | 306 | # Wait before checking again |
302 | 307 | time.sleep(poll_interval_seconds) |
| 308 | + |
| 309 | + def cleanup_logs( |
| 310 | + self, |
| 311 | + log_dir: Optional[Union[str, Path]] = None, |
| 312 | + model_family: Optional[str] = None, |
| 313 | + model_name: Optional[str] = None, |
| 314 | + job_id: Optional[int] = None, |
| 315 | + dry_run: bool = False, |
| 316 | + ) -> list[Path]: |
| 317 | + """Remove logs from the log directory. |
| 318 | +
|
| 319 | + Parameters |
| 320 | + ---------- |
| 321 | + log_dir : str or Path, optional |
| 322 | + Root directory containing log files. Defaults to ~/.vec-inf-logs. |
| 323 | + model_family : str, optional |
| 324 | + Only delete logs for this model family. |
| 325 | + model_name : str, optional |
| 326 | + Only delete logs for this model name. |
| 327 | + job_id : int, optional |
| 328 | + If provided, only match directories with this exact SLURM job ID. |
| 329 | + dry_run : bool |
| 330 | + If True, return matching files without deleting them. |
| 331 | +
|
| 332 | + Returns |
| 333 | + ------- |
| 334 | + list[Path] |
| 335 | + List of deleted (or matched if dry_run) log file paths. |
| 336 | + """ |
| 337 | + log_root = Path(log_dir) if log_dir else Path.home() / ".vec-inf-logs" |
| 338 | + matched = find_matching_dirs( |
| 339 | + log_dir=log_root, |
| 340 | + model_family=model_family, |
| 341 | + model_name=model_name, |
| 342 | + job_id=job_id, |
| 343 | + ) |
| 344 | + |
| 345 | + if dry_run: |
| 346 | + return matched |
| 347 | + |
| 348 | + for path in matched: |
| 349 | + shutil.rmtree(path) |
| 350 | + |
| 351 | + return matched |
0 commit comments