-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Model Registry #20
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
Open
alicup29
wants to merge
6
commits into
main
Choose a base branch
from
amick/create-model-registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
Add comprehensive model registry system for client-side model tracking, including web viewer and complete test suite. Core Features: - ClientModelRegistry class with JSON persistence at ~/.sleap-rtc/models/manifest.json - Atomic write operations (temp file + rename) for crash safety - Corruption recovery with automatic backups - CRUD operations: register, get, list, update, delete, exists - Advanced filtering by type, source, location, and alias presence - Optional metadata support (metrics, hyperparameters, tags, notes) Web Viewer: - Lightweight web interface at http://localhost:8765 - Dashboard with statistics (total models, aliases, worker sync status) - Responsive card-based UI with model details - Filtering by model type and location - REST API endpoints for programmatic access - Zero external dependencies (uses Python http.server) Testing: - 32 comprehensive unit tests (100% passing) - Tests for initialization, CRUD, filtering, atomicity, metadata - Concurrent access testing and best practices documentation - Demo scripts for interactive exploration Documentation: - Complete API documentation with Google-style docstrings - Usage examples and demo scripts - Web viewer guide with API documentation - Organized docs/ and config/ directories Project Organization: - Moved documentation files to docs/ - Moved configuration files to config/ - Added README files for each directory - Cleaned up root directory structure This implements Step 1 (Client Registry Infrastructure) of the add-client-model-registry change proposal. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit implements comprehensive alias management for the client-side model registry, enabling human-readable model names alongside model IDs. Key features: - Alias validation and sanitization with clear error messages - Collision detection with optional force overwrite - Flexible identifier resolution (supports both IDs and aliases) - Auto-suggestion system for generating valid, unique aliases - Complete test coverage for all alias operations - Documentation and demo scripts showing practical usage patterns Changes: - sleap_rtc/client/client_model_registry.py: Added 8 new alias management methods - tests/test_client_model_registry.py: Added 100+ tests for alias functionality - examples/alias_usage_examples.md: Comprehensive usage documentation - examples/demo_alias_management.py: Interactive demo of alias features - Updated demo scripts to use consistent temporary paths 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit implements the model import functionality, completing step 3 of the add-client-model-registry feature. Users can now import pre-trained models into the client registry from local directories. Key features: - Model file detection utilities (find checkpoints, detect type, validate) - Automatic model type detection from training_config.yaml - Generate stable model IDs from config hash (or random if no config) - Support for both symlink (default) and copy import modes - Interactive and non-interactive alias assignment - Comprehensive validation and error handling - Rich CLI output with step-by-step progress New components: - sleap_rtc/client/model_utils.py: Utility functions for model detection - find_checkpoint_files(): Discover .ckpt, .h5, .pth, .pt files - detect_model_type(): Auto-detect from training config - calculate_model_size(): Sum checkpoint file sizes - validate_checkpoint_files(): Verify files are readable - generate_model_id_from_config(): Create stable IDs - format_size(): Human-readable size formatting - sleap_rtc/cli.py: Added import-model command - Accepts model path as required argument - Options: --alias, --model-type, --copy, --registry-path - Interactive prompts for missing information - Collision detection and confirmation prompts - Auto-suggestion for aliases - tests/test_model_utils.py: 26 unit tests covering all utilities - Tests for checkpoint discovery with various formats - Model type detection from different config structures - Size calculation and formatting - Validation and error handling - examples/demo_model_import.py: Comprehensive demo script - Creates mock models for testing - Demonstrates programmatic import workflow - Uses /tmp/sleap-rtc-alias-demo/ as requested - Shows model detection, import, and query operations Usage examples: # Auto-detect model type and create symlink sleap-rtc import-model /path/to/model --alias production-v1 # Specify model type and copy files sleap-rtc import-model /path/to/model --model-type centroid --copy # Import without alias (prompt interactively) sleap-rtc import-model /path/to/model 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit completes step 3 of the client model registry feature,
implementing the model import command with comprehensive config format
support and enhanced web view capabilities.
Major features:
- Model import CLI command with auto-detection and validation
- JSON config support for backward compatibility with older SLEAP
- Interactive path display in web view with copy-to-clipboard
- SLEAP-NN config structure alignment and verification
Components:
1. Model Utilities (sleap_rtc/client/model_utils.py):
- find_checkpoint_files(): Discovers .ckpt, .h5, .pth, .pt files
- detect_model_type(): Auto-detects from SLEAP-NN head_configs
- calculate_model_size(): Sums checkpoint file sizes
- validate_checkpoint_files(): Verifies readability
- generate_model_id_from_config(): Creates stable 8-char hex IDs
- format_size(): Human-readable size formatting
- Supports both YAML and JSON config formats
2. Import Command (sleap_rtc/cli.py):
- sleap-rtc import-model <MODEL_PATH> [OPTIONS]
- Options: --alias, --model-type, --copy, --registry-path
- Auto-detects model type from config (YAML or JSON)
- Creates symlinks (default) or copies files
- Interactive prompts for missing information
- Validates checkpoints before import
- Integrates with alias system
- Collision detection and confirmation prompts
3. Config Format Support:
- SLEAP-NN format: model_config.head_configs structure
- Older SLEAP format: simple model_type field
- Both YAML (.yaml, .yml) and JSON (.json) formats
- Searches 15+ config file name variants
- Verified with real SLEAP-NN training configs
4. Web View Enhancements (sleap_rtc/client/registry_server.py):
- Hover tooltip shows full file paths
- Click-to-copy clipboard functionality for all paths
- Visual feedback with copy icon and success notification
- Displays local path, checkpoint path, and original path
- CSS animations and hover states for better UX
5. Tests (tests/test_model_utils.py):
- 36 comprehensive unit tests (all passing)
- YAML and JSON config detection tests
- Checkpoint discovery and validation tests
- Model ID generation and determinism tests
- Size calculation and formatting tests
6. Demo Script (examples/demo_model_import.py):
- Creates SLEAP-NN style mock models
- Demonstrates programmatic import workflow
- Uses /tmp/sleap-rtc-alias-demo/ directory
- Shows detection, import, listing, and query operations
Model Import Workflow:
1. Validates source directory and finds checkpoints
2. Auto-detects model type from config (or prompts)
3. Generates stable model ID from config hash
4. Creates symlink or copy to ~/.sleap-rtc/models/{type}_{id}/
5. Registers in client registry with metadata
6. Optionally sets alias with validation
Supported Model Types:
- centroid: Single animal centroid detection
- centered_instance: Top-down (centered instance)
- bottomup: Multi-animal bottom-up
- single_instance: Single instance
Registry Storage:
- Default: ~/.sleap-rtc/models/manifest.json (client-side)
- Models stored: ~/.sleap-rtc/models/{type}_{id}/
- on_worker flag: false (client-side import)
Usage Examples:
# Auto-detect and create symlink
sleap-rtc import-model models/centroid_251024_152308 --alias prod-v1
# Specify type and copy files
sleap-rtc import-model /path/to/model --model-type centered_instance --copy
# Custom registry location (testing/demo)
sleap-rtc import-model models/my_model --registry-path /tmp/test/manifest.json
Web View Usage:
python -m sleap_rtc.client.registry_server
# Open http://localhost:8765
# Hover over paths to see full path
# Click paths to copy to clipboard
Testing:
- All 36 unit tests passing
- Verified with real SLEAP-NN configs (centroid.yaml, centered_instance.yaml)
- JSON and YAML parsing tested
- Demo script runs successfully
Architecture Alignment:
- Correctly parses SLEAP-NN model_config.head_configs
- Uses exact SLEAP model type names
- Supports PyTorch Lightning .ckpt format
- Compatible with older SLEAP JSON configs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Add model resolution to client-track CLI command, enabling users to reference models by filesystem path, model ID, or alias. Features: - Model resolution utilities (resolve_model_path, resolve_model_paths) - Support for three identifier types: * Filesystem paths (absolute/relative) * Model IDs (8-character hex strings) * Aliases (user-defined friendly names) - Integration with client-track CLI command - Helpful error messages with actionable suggestions - Custom registry path support via --registry-path option - Backward compatible (direct paths still work) Implementation: - Add resolve_model_path() and resolve_model_paths() to model_utils.py - Update client-track command to resolve models before packaging - Add --registry-path option to CLI - Display clear resolution logs for debugging - Exit with helpful errors if models cannot be resolved Testing: - 14 new unit tests for model resolution (50 total in test_model_utils.py) - All tests passing (100% success rate) - Tested with existing demo registry - Verified resolution by path, ID, and alias - Verified mixed identifier support - Verified error handling for nonexistent models Documentation: - Added "Model Registry" section to README.md - Created TESTING_MODEL_REGISTRY.md with testing guide - Added examples/test_model_registry_integration.py demo script - Updated CLI help text for --model-paths option Example usage: sleap-rtc client-track -d data.slp -m production-v1 --session-string <session> sleap-rtc client-track -d data.slp -m a3b4c5d6 --session-string <session> sleap-rtc client-track -d data.slp -m /path/to/model --session-string <session> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add CLI commands for managing model aliases and metadata (notes/tags). Features: - tag-model command: Set or update aliases for models * Resolve models by ID or existing alias * Sanitize and validate alias names * Collision detection with user prompts * Force flag to override without prompting - update-model command: Manage model metadata * Add/update notes field * Add/remove tags (multiple tag support) * Clear all tags with --clear-tags * Resolve models by ID or alias - Extended registry schema: * Added "notes" field (default: empty string) * Added "tags" field (default: empty list) * Automatically set defaults on model registration Implementation: - tag-model CLI command in cli.py (lines 630-731) - update-model CLI command in cli.py (lines 734-886) - Extended ClientModelRegistry to support notes and tags - Updated register() to set metadata defaults Testing: - 14 new tests for metadata and alias management - Tests for notes: default, update, clear - Tests for tags: default, update, clear - Tests for alias operations: set, update, collision, force - All tests passing (100% success rate) Example usage: sleap-rtc tag-model a3b4c5d6 production-v1 sleap-rtc tag-model old-alias new-alias --force sleap-rtc update-model production-v1 --notes "Best model" sleap-rtc update-model a3b4c5d6 --add-tag validated --add-tag production 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements Step 1 (Client Registry Infrastructure) of the
add-client-model-registrychange proposal. This PR introduces a comprehensive client-side model registry system for tracking downloaded and imported models, complete with a web-based viewer and full test coverage.What's New
🗄️ Core Registry System
sleap_rtc/client/client_model_registry.py(359 lines)~/.sleap-rtc/models/manifest.jsonregister(),get(),list(),update(),delete(),exists()🌐 Web Viewer
sleap_rtc/client/registry_server.py(448 lines)http://localhost:8765/api/models,/api/stats,/api/model/{id})http.server)Usage:
✅ Testing
tests/test_client_model_registry.py(32 tests, 100% passing)Run tests:
📚 Documentation & Examples
Demo Scripts:
examples/demo_client_registry.py- Interactive demonstration of all featuresexamples/populate_demo_registry.py- Populate registry with sample dataexamples/test_concurrent_registries.py- Concurrent access patternsexamples/WEBVIEW_README.md- Complete web viewer guideProject Organization:
docs/directoryconfig/directoryKey Features
📋 Model Tracking
🎯 Metadata Support
🔒 Safety & Reliability
Testing
All 32 tests passing:
$ uv run python -m pytest tests/test_client_model_registry.py -v ================================ 32 passed in 0.17s ================================Test coverage includes:
Demo
Quick demo:
Project Structure
API Examples
Python API:
REST API:
Next Steps
This PR implements Step 1 of the
add-client-model-registryproposal. Future steps include:Breaking Changes
None. This is fully additive and backward compatible.
Checklist
🤖 Generated with Claude Code