-
Notifications
You must be signed in to change notification settings - Fork 317
[chore] Revert environment: secrets changes & cleanup finetuned models
#774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+119
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4110323
Revert environment: secrets
gee-senbong 94c843b
Add step to cleanup finetuned models before other tests
gee-senbong fab02ce
Add pip cache clearing before the Snowflake packaging step
gee-senbong 10dbcfc
Remove unicode characters from the console output
gee-senbong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Script to clean up finetuned models older than a specified duration. | ||
| Usage: python scripts/cleanup_finetuned_models.py [--older-than MINUTES] [--dry-run] | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| from argparse import ArgumentParser | ||
| from datetime import datetime, timedelta, timezone | ||
|
|
||
| from nixtla.nixtla_client import NixtlaClient | ||
|
|
||
|
|
||
| def cleanup_models(older_than_minutes: int = 30, dry_run: bool = False) -> int: | ||
| """ | ||
| Clean up finetuned models older than specified duration. | ||
|
|
||
| Args: | ||
| older_than_minutes: Delete models older than this many minutes (default: 30). | ||
| dry_run: If True, only list models without deleting them. | ||
|
|
||
| Returns: | ||
| Number of models deleted. | ||
| """ | ||
| # Collect all credential pairs from environment | ||
| credentials = [ | ||
| (os.environ.get("NIXTLA_API_KEY_CUSTOM"), os.environ.get("NIXTLA_BASE_URL_CUSTOM")), | ||
| (os.environ.get("NIXTLA_API_KEY"), os.environ.get("NIXTLA_BASE_URL")), | ||
| (os.environ.get("NIXTLA_API_KEY_FOR_SF"), os.environ.get("NIXTLA_BASE_URL")), | ||
| ] | ||
|
|
||
| # Filter out None/empty credentials | ||
| credentials = [(key, url) for key, url in credentials if key and url] | ||
|
|
||
| if not credentials: | ||
| print("[WARNING] No credentials found. Skipping cleanup.") | ||
| return 0 | ||
|
|
||
| now = datetime.now(timezone.utc) | ||
| cutoff_time = now - timedelta(minutes=older_than_minutes) | ||
|
|
||
| total_deleted = 0 | ||
| total_failed = 0 | ||
|
|
||
| for api_key, base_url in credentials: | ||
| try: | ||
| client = NixtlaClient(api_key=api_key, base_url=base_url) | ||
| models = client.finetuned_models() | ||
| except Exception: | ||
| # Silently skip if unable to connect | ||
| continue | ||
|
|
||
| # Filter models older than cutoff time | ||
| old_models = [] | ||
| for model in models: | ||
| model_time = model.created_at | ||
| if model_time.tzinfo is None: | ||
| model_time = model_time.replace(tzinfo=timezone.utc) | ||
|
|
||
| if model_time < cutoff_time: | ||
| old_models.append(model) | ||
|
|
||
| if not old_models: | ||
| continue | ||
|
|
||
| if dry_run: | ||
| total_deleted += len(old_models) | ||
| continue | ||
|
|
||
| # Delete old models | ||
| for model in old_models: | ||
| try: | ||
| client.delete_finetuned_model(model.id) | ||
| total_deleted += 1 | ||
| except Exception: | ||
| total_failed += 1 | ||
|
|
||
| if dry_run: | ||
| print(f"[DRY RUN] Found {total_deleted} model(s) older than {older_than_minutes} minute(s)") | ||
| print("[DRY RUN] Models would be deleted without --dry-run flag") | ||
| else: | ||
| print(f"[OK] Cleaned up {total_deleted} finetuned model(s)") | ||
| if total_failed: | ||
| print(f"[WARNING] {total_failed} model(s) failed to delete") | ||
|
|
||
| return total_deleted | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = ArgumentParser(description="Clean up old finetuned models") | ||
| parser.add_argument( | ||
| "--older-than", | ||
| type=int, | ||
| default=30, | ||
| help="Delete models older than this many minutes (default: 30)", | ||
| ) | ||
| parser.add_argument("--dry-run", action="store_true", help="List models without deleting") | ||
| args = parser.parse_args() | ||
|
|
||
| cleanup_models(older_than_minutes=args.older_than, dry_run=args.dry_run) | ||
| sys.exit(0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this fix, better than my suggestion