-
Notifications
You must be signed in to change notification settings - Fork 741
update: Improve Model Manager Configuration and CI Integration #830
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
JaredforReal
merged 6 commits into
vllm-project:main
from
JaredforReal:update/model_manager
Dec 15, 2025
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43d8abc
move model_manager configs to config/models_manager/
JaredforReal 4b1a632
add README for model_manager module
JaredforReal 310bb44
update CI
JaredforReal a9648eb
add hr_transfer to requirement
JaredforReal e27755b
accept reviews in README
JaredforReal 177a6a0
Merge branch 'main' into update/model_manager
JaredforReal 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
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,216 @@ | ||
| # Model Manager | ||
|
|
||
| A Python module for automated ML model download, verification, and caching from HuggingFace. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Automated Download**: Download models from HuggingFace Hub with support for specific revisions and file filtering | ||
| - **Integrity Verification**: Verify model integrity using size or SHA256 checksums | ||
| - **Smart Caching**: Skip downloads for already-cached models | ||
| - **CI-Friendly**: Environment variable-based config selection for minimal CI downloads | ||
| - **CLI & Programmatic API**: Use from command line or import as a Python module | ||
|
|
||
| ## Quick Start | ||
|
|
||
|
JaredforReal marked this conversation as resolved.
|
||
| ### CLI Usage | ||
|
|
||
|
JaredforReal marked this conversation as resolved.
|
||
| ```bash | ||
| # Download all models (uses config/model_manager/models.yaml by default) | ||
| python -m model_manager | ||
|
|
||
| # Use a specific config file | ||
| python -m model_manager --config config/model_manager/models.yaml | ||
|
|
||
| # Download a specific model only | ||
| python -m model_manager --model category_classifier_modernbert-base_model | ||
|
|
||
| # List all configured models and their cache status | ||
| python -m model_manager --list | ||
|
|
||
| # Verify existing models without downloading | ||
| python -m model_manager --verify-only | ||
|
|
||
| # Clean all cached models | ||
| python -m model_manager --clean | ||
|
|
||
|
JaredforReal marked this conversation as resolved.
Outdated
|
||
| # Clean a specific model | ||
| python -m model_manager --clean-model category_classifier_modernbert-base_model | ||
|
|
||
| # Verbose output for debugging | ||
| python -m model_manager -v | ||
| ``` | ||
|
|
||
| ### CI Mode | ||
|
|
||
| For CI environments, use the minimal model set to speed up builds and avoid rate limits: | ||
|
|
||
| ```bash | ||
| # Auto-select minimal config | ||
| CI_MINIMAL_MODELS=true python -m model_manager | ||
|
|
||
| # Or explicitly specify | ||
| python -m model_manager --config config/model_manager/models.minimal.yaml | ||
| ``` | ||
|
|
||
| ### Programmatic Usage | ||
|
|
||
| ```python | ||
| from model_manager import ensure_models, ModelManager | ||
|
|
||
| # Simple: ensure all models are downloaded | ||
| ensure_models("config/model_manager/models.yaml") | ||
|
|
||
| # Advanced: use ModelManager for more control | ||
| manager = ModelManager.from_config("config/model_manager/models.yaml") | ||
|
|
||
| # Ensure all models | ||
| paths = manager.ensure_all() | ||
| print(paths) # {'model_id': '/path/to/model', ...} | ||
|
|
||
| # Ensure a specific model | ||
| path = manager.ensure_model("category_classifier_modernbert-base_model") | ||
|
|
||
| # Check if a model is cached | ||
| from model_manager import is_cached, get_model_path | ||
| spec = manager.get_model_spec("category_classifier_modernbert-base_model") | ||
| if is_cached(spec, manager.config.cache_dir): | ||
| print(f"Model cached at: {get_model_path(spec, manager.config.cache_dir)}") | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Models are defined in YAML configuration files. See `config/model_manager/` for examples. | ||
|
|
||
| ### Configuration Schema | ||
|
|
||
| ```yaml | ||
| # Cache directory for downloaded models | ||
| cache_dir: "models" | ||
|
|
||
| # Verification level: "none", "size", or "sha256" | ||
| verify: "sha256" | ||
|
|
||
| # List of models to manage | ||
| models: | ||
| - id: my-model # Unique identifier (required) | ||
| repo_id: org/model-name # HuggingFace repo ID (required) | ||
| revision: main # Git revision (optional, default: main) | ||
| local_dir: custom-name # Override local directory name (optional) | ||
| files: # Specific files to download (optional) | ||
| - config.json | ||
| - model.safetensors | ||
| ``` | ||
|
|
||
| ### Verification Levels | ||
|
|
||
| | Level | Description | Use Case | | ||
| | -------- | -------------------- | ------------------------- | | ||
| | `none` | No verification | Fast, trust HuggingFace | | ||
| | `size` | Verify file sizes | Quick verification for CI | | ||
| | `sha256` | Full SHA256 checksum | Production environments | | ||
|
|
||
| ### Available Configs | ||
|
|
||
| | Config | Description | | ||
| | --------------------- | -------------------------------------------- | | ||
| | `models.yaml` | Full model set for local development | | ||
| | `models.minimal.yaml` | Minimal set for CI (faster, no gated models) | | ||
| | `models.lora.yaml` | LoRA adapters only | | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Description | | ||
| | ------------------- | ---------------------------------------------------------------- | | ||
| | `CI_MINIMAL_MODELS` | Set to `true`, `1`, or `yes` to auto-select minimal config | | ||
| | `HF_TOKEN` | HuggingFace token for gated models (e.g., `embeddinggemma-300m`) | | ||
|
JaredforReal marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## API Reference | ||
|
|
||
| ### Functions | ||
|
|
||
| #### `ensure_models(config_path, cache_dir=None)` | ||
|
|
||
| Main entry point. Downloads and verifies all models from config. | ||
|
|
||
| #### `is_cached(spec, cache_dir)` | ||
|
|
||
| Check if a model is already cached. | ||
|
|
||
| #### `get_model_path(spec, cache_dir)` | ||
|
|
||
| Get the local path for a model. | ||
|
|
||
| #### `download_model(spec, cache_dir)` | ||
|
|
||
| Download a model from HuggingFace. | ||
|
|
||
| #### `verify_model(path, verify_level)` | ||
|
|
||
| Verify model integrity. | ||
|
|
||
| ### Classes | ||
|
|
||
| #### `ModelManager` | ||
|
|
||
| Central manager for model operations. | ||
|
|
||
| - `from_config(config_path)` - Create from config file | ||
| - `ensure_all()` - Ensure all models are ready | ||
| - `ensure_model(model_id)` - Ensure a specific model | ||
| - `get_model_spec(model_id)` - Get model specification | ||
|
|
||
| #### `ModelSpec` | ||
|
|
||
| Specification for a single model. | ||
|
|
||
| - `id` - Unique identifier | ||
| - `repo_id` - HuggingFace repository ID | ||
| - `revision` - Git revision (default: "main") | ||
| - `local_dir` - Override local directory name | ||
| - `files` - Specific files to download | ||
|
|
||
| #### `ModelsConfig` | ||
|
|
||
| Configuration container. | ||
|
|
||
| - `models` - List of ModelSpec | ||
| - `cache_dir` - Cache directory path | ||
| - `verify` - Verification level | ||
|
|
||
| ### Exceptions | ||
|
|
||
| | Exception | Description | | ||
| | -------------------- | ------------------------- | | ||
| | `ModelManagerError` | Base exception | | ||
| | `MissingModelError` | Model not found in config | | ||
| | `BadChecksumError` | Verification failed | | ||
| | `DownloadError` | Download failed | | ||
| | `ConfigurationError` | Invalid config | | ||
|
|
||
| ## Development | ||
|
|
||
| ### Running Tests | ||
|
|
||
| ```bash | ||
| # Run all model_manager tests | ||
| pytest src/model_manager/tests/ -v | ||
|
|
||
| # Run with coverage | ||
| pytest src/model_manager/tests/ --cov=model_manager | ||
| ``` | ||
|
|
||
| ### Project Structure | ||
|
|
||
| ``` | ||
| src/model_manager/ | ||
| ├── __init__.py # Public API and ModelManager class | ||
| ├── __main__.py # CLI entrypoint | ||
| ├── cli.py # CLI implementation | ||
| ├── config.py # Configuration dataclasses | ||
| ├── registry.py # YAML config parsing | ||
| ├── downloader.py # HuggingFace download logic | ||
| ├── verifier.py # Integrity verification | ||
| ├── cache.py # Cache management | ||
| ├── errors.py # Custom exceptions | ||
| └── tests/ # Unit tests | ||
| ``` | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.