Merged
Conversation
* Add HF downloader support Signed-off-by: kerthcet <kerthcet@gmail.com> * add bars Signed-off-by: kerthcet <kerthcet@gmail.com> * fix color Signed-off-by: kerthcet <kerthcet@gmail.com> * fix color Signed-off-by: kerthcet <kerthcet@gmail.com> * add download successfully message Signed-off-by: kerthcet <kerthcet@gmail.com> * change the color Signed-off-by: kerthcet <kerthcet@gmail.com> * change the rending shape Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
* support new cache structure Signed-off-by: kerthcet <kerthcet@gmail.com> * support puma rm Signed-off-by: kerthcet <kerthcet@gmail.com> * use readable format Signed-off-by: kerthcet <kerthcet@gmail.com> * remove requests.rs Signed-off-by: kerthcet <kerthcet@gmail.com> * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
* polish the format of the ls command Signed-off-by: kerthcet <kerthcet@gmail.com> * Have a progress manager Signed-off-by: kerthcet <kerthcet@gmail.com> * Reuse caches Signed-off-by: kerthcet <kerthcet@gmail.com> * rename util to utils Signed-off-by: kerthcet <kerthcet@gmail.com> * polish the layout of the download progress Signed-off-by: kerthcet <kerthcet@gmail.com> * revert change Signed-off-by: kerthcet <kerthcet@gmail.com> * add make format Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
* add speed at the end Signed-off-by: kerthcet <kerthcet@gmail.com> * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
* support GPU detect Signed-off-by: kerthcet <kerthcet@gmail.com> * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
* add support for inspect Signed-off-by: kerthcet <kerthcet@gmail.com> * add support for inspect Signed-off-by: kerthcet <kerthcet@gmail.com> * add pull progress bar Signed-off-by: kerthcet <kerthcet@gmail.com> * polish the download progress Signed-off-by: kerthcet <kerthcet@gmail.com> * reorganize the structure Signed-off-by: kerthcet <kerthcet@gmail.com> * optimize the structure Signed-off-by: kerthcet <kerthcet@gmail.com> * fix test Signed-off-by: kerthcet <kerthcet@gmail.com> * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR expands PUMA’s CLI capabilities by adding a local model registry (metadata persistence), Hugging Face download support with progress reporting, and system/cache introspection utilities.
Changes:
- Introduces
registry+systemmodules to track local models and display system/cache information. - Adds
utilsformatting/helpers and a Hugging Face downloader with multi-file progress rendering. - Updates project tooling/docs (CI workflow, Makefile targets, README) and removes the old
utilmodule.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/mod.rs | Defines the new utils module surface (file + format). |
| src/utils/format.rs | Adds formatting helpers (sizes/parameters/time-ago) and unit tests. |
| src/utils/file.rs | Adds cache/home-path helpers and model-name formatting for HF cache layout. |
| src/system/system_info.rs | Implements system info + GPU detection + cache size calculation. |
| src/system/mod.rs | Exposes the system module. |
| src/registry/model_registry.rs | Implements model metadata storage (models.json) and model removal. |
| src/registry/mod.rs | Exposes the registry module. |
| src/main.rs | Wires new modules into the binary and adjusts logger initialization. |
| src/lib.rs | Adds a library target file (currently empty). |
| src/downloader/progress.rs | Adds multi-progress display manager for downloads. |
| src/downloader/mod.rs | Exposes downloader submodules publicly. |
| src/downloader/huggingface.rs | Implements Hugging Face snapshot download + registry integration + tests. |
| src/downloader/downloader.rs | Refactors downloader error types and introduces a Downloader trait. |
| src/cli/commands.rs | Updates CLI commands to use registry/downloader/system info features. |
| README.md | Updates documentation with commands, features, and examples. |
| Makefile | Adds test, lint, and formatting targets. |
| Cargo.toml | Adds new dependencies for registry/system/HF download and bumps indicatif. |
| Cargo.lock | Locks new/updated dependency graph. |
| .github/workflows/rust-ci.yaml | Adds CI jobs for lint and tests. |
| src/util/request.rs | Removed legacy chunked download implementation. |
| src/util/mod.rs | Removed legacy util module. |
| src/util/file.rs | Removed old home-dir helper (superseded by utils::file). |
Comments suppressed due to low confidence (3)
src/downloader/huggingface.rs:134
- This spawns one Tokio task per file in the model repo with no concurrency limiting. Large repos can contain hundreds/thousands of files, which can overwhelm the runtime and Hugging Face API. Consider using a bounded concurrency approach (e.g.,
tokio::sync::Semaphore,FuturesUnordered+buffer_unordered, or batching) while still updating progress bars.
// Process all files in manifest order (cached files show as instantly complete)
let mut tasks = Vec::new();
for sibling in model_info.siblings {
let api_clone = api.clone();
let model_name = name.to_string();
let filename = sibling.rfilename.clone();
let progress_manager_clone = progress_manager.clone();
let snapshot_path_clone = snapshot_path.clone();
let task = tokio::spawn(async move {
let repo = api_clone.model(model_name);
src/downloader/huggingface.rs:278
- These
#[tokio::test]cases hit the real Hugging Face network/API. That makescargo test(and the GitHub Actions workflow) flaky and slow, and can fail in offline/restricted CI environments. Consider converting them to mocked/unit tests, or gating as explicit integration tests (e.g.,#[ignore]+ opt-in env var) so the default test suite stays deterministic.
#[tokio::test]
async fn test_download_model_invalid() {
let downloader = HuggingFaceDownloader::new();
let result = downloader
.download_model("invalid-model-that-does-not-exist-12345")
.await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_download_real_tiny_model() {
let downloader = HuggingFaceDownloader::new();
// Use HF's official tiny test model (only a few KB)
let result = downloader.download_model("InftyAI/tiny-random-gpt2").await;
assert!(
result.is_ok(),
"Failed to download tiny model: {:?}",
result
);
// Cleanup: remove the downloaded files from PUMA cache
let cache_dir = file::huggingface_cache_dir().join("models--InftyAI--tiny-random-gpt2");
if cache_dir.exists() {
let _ = std::fs::remove_dir_all(&cache_dir);
}
}
src/registry/model_registry.rs:195
remove_modeldeletesinfo.cache_pathfrom the registry file without validating it. Sincemodels.jsonis user-editable/corruptible, this can be abused to delete arbitrary directories. Consider restricting deletions to paths under PUMA’s cache root (e.g.,utils::file::cache_dir()), canonicalizing and verifying prefix before callingremove_dir_all, and refusing otherwise.
if let Some(info) = model_info {
// Delete cache directory if it exists
let cache_path = std::path::Path::new(&info.cache_path);
if cache_path.exists() {
fs::remove_dir_all(cache_path)?;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
/lgtm |
Member
Author
|
/kind cleanup |
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
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.
What this PR does / why we need it
Which issue(s) this PR fixes
Fixes #
Special notes for your reviewer
Does this PR introduce a user-facing change?