Skip to content

Commit 7106024

Browse files
committed
added --before-job-id argument.
1 parent 8adff23 commit 7106024

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Note that there are other parameters that can also be added to the config but no
102102
* `metrics`: Streams performance metrics to the console.
103103
* `shutdown`: Shutdown a model by providing its Slurm job ID.
104104
* `list`: List all available model names, or view the default/cached configuration of a specific model, `--json-mode` supported.
105-
* `cleanup`: Remove old log directories. You can filter by `--model-family`, `--model-name`, and/or `--job-id`. Use `--dry-run` to preview what would be deleted.
105+
* `cleanup`: Remove old log directories. You can filter by `--model-family`, `--model-name`, `--job-id`, and/or `--before-job-id`. Use `--dry-run` to preview what would be deleted.
106106

107107
For more details on the usage of these commands, refer to the [User Guide](https://vectorinstitute.github.io/vector-inference/user_guide/)
108108

vec_inf/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
* `metrics`: Streams performance metrics to the console.
66
* `shutdown`: Shutdown a model by providing its Slurm job ID.
77
* `list`: List all available model names, or view the default/cached configuration of a specific model, `--json-mode` supported.
8-
* `cleanup`: Remove old log directories. You can filter by `--model-family`, `--model-name`, and/or `--job-id`. Use `--dry-run` to preview what would be deleted.
8+
* `cleanup`: Remove old log directories. You can filter by `--model-family`, `--model-name`, `--job-id`, and/or `--before-job-id`. Use `--dry-run` to preview what would be deleted.
99

1010
Use `--help` to see all available options

vec_inf/cli/_cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,18 @@ def metrics(slurm_job_id: int, log_dir: Optional[str] = None) -> None:
343343
@click.option(
344344
"--job-id", type=int, help="Only remove logs with this exact SLURM job ID"
345345
)
346+
@click.option(
347+
"--before-job-id",
348+
type=int,
349+
help="Remove logs with job ID less than this value",
350+
)
346351
@click.option("--dry-run", is_flag=True, help="List matching logs without deleting")
347352
def cleanup_logs_cli(
348353
log_dir: Optional[str],
349354
model_family: Optional[str],
350355
model_name: Optional[str],
351356
job_id: Optional[int],
357+
before_job_id: Optional[int],
352358
dry_run: bool,
353359
) -> None:
354360
"""Clean up log files based on optional filters.
@@ -363,6 +369,8 @@ def cleanup_logs_cli(
363369
Only delete logs for this model name.
364370
job_id : int, optional
365371
If provided, only match directories with this exact SLURM job ID.
372+
before_job_id : int, optional
373+
If provided, only delete logs with job ID less than this value.
366374
dry_run : bool
367375
If True, return matching files without deleting them.
368376
"""
@@ -373,6 +381,7 @@ def cleanup_logs_cli(
373381
model_family=model_family,
374382
model_name=model_name,
375383
job_id=job_id,
384+
before_job_id=before_job_id,
376385
dry_run=dry_run,
377386
)
378387

vec_inf/client/_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def find_matching_dirs(
292292
model_family: Optional[str] = None,
293293
model_name: Optional[str] = None,
294294
job_id: Optional[int] = None,
295+
before_job_id: Optional[int] = None,
295296
) -> list[Path]:
296297
"""
297298
Find log directories based on filtering criteria.
@@ -306,6 +307,8 @@ def find_matching_dirs(
306307
Filter to only match model names.
307308
job_id : int, optional
308309
Filter to only match this exact SLURM job ID.
310+
before_job_id : int, optional
311+
Filter to only include job IDs less than this value.
309312
310313
Returns
311314
-------
@@ -317,17 +320,16 @@ def find_matching_dirs(
317320
if not log_dir.exists() or not log_dir.is_dir():
318321
raise FileNotFoundError(f"Log directory does not exist: {log_dir}")
319322

320-
if not model_family and not model_name and not job_id:
323+
if not model_family and not model_name and not job_id and not before_job_id:
321324
return [log_dir]
322325

323-
# Iterate over model families
324326
for family_dir in log_dir.iterdir():
325327
if not family_dir.is_dir():
326328
continue
327329
if model_family and family_dir.name != model_family:
328330
continue
329331

330-
if model_family and not model_name and not job_id:
332+
if model_family and not model_name and not job_id and not before_job_id:
331333
return [family_dir]
332334

333335
for job_dir in family_dir.iterdir():
@@ -344,6 +346,9 @@ def find_matching_dirs(
344346
continue
345347
if job_id is not None and parsed_id != job_id:
346348
continue
349+
if before_job_id is not None and parsed_id >= before_job_id:
350+
continue
347351

348352
matched.append(job_dir)
353+
349354
return matched

vec_inf/client/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ def cleanup_logs(
312312
model_family: Optional[str] = None,
313313
model_name: Optional[str] = None,
314314
job_id: Optional[int] = None,
315+
before_job_id: Optional[int] = None,
315316
dry_run: bool = False,
316317
) -> list[Path]:
317318
"""Remove logs from the log directory.
@@ -326,6 +327,8 @@ def cleanup_logs(
326327
Only delete logs for this model name.
327328
job_id : int, optional
328329
If provided, only match directories with this exact SLURM job ID.
330+
before_job_id : int, optional
331+
If provided, only delete logs with job ID less than this value.
329332
dry_run : bool
330333
If True, return matching files without deleting them.
331334
@@ -340,6 +343,7 @@ def cleanup_logs(
340343
model_family=model_family,
341344
model_name=model_name,
342345
job_id=job_id,
346+
before_job_id=before_job_id,
343347
)
344348

345349
if dry_run:

0 commit comments

Comments
 (0)