Skip to content

feat(onnx): race Hugging Face and hf-mirror for model downloads - #415

Open
liukewia wants to merge 4 commits into
TencentCloud:developfrom
liukewia:feature/onnx-hf-mirror-download
Open

feat(onnx): race Hugging Face and hf-mirror for model downloads#415
liukewia wants to merge 4 commits into
TencentCloud:developfrom
liukewia:feature/onnx-hf-mirror-download

Conversation

@liukewia

Copy link
Copy Markdown
Contributor

Summary

  • Download local ONNX embedding models by racing Hugging Face and hf-mirror, then fetching from the faster source (with fallback).
  • Infer snapshot URLs from the catalog HF repo id (or the model id) so each model does not need a hand-written download URL.
  • Drop the previous official-only snapshot_download path in the ONNX download manager.

Target branch

  • Base is develop (feature / fix — default)
  • Base is main (release/* or hotfix/* only)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactor / chore
  • Release / hotfix

Test plan

  • uv run pytest tests/unit/agents/test_onnx_download.py tests/unit/agents/test_onnx_service.py -q — 28 passed

  • Did not run make all on this branch

  • make all passes locally

  • Added/updated tests

Checklist

  • Updated CHANGELOG.md (if user-facing)
  • README / docs updated (if needed)

Made with Cursor

…ling

- Introduced a new module `onnx_download.py` to handle racing between Hugging Face and hf-mirror for model downloads, improving download efficiency.
- Added a helper function `_hf_repo_from_sources` to streamline Hugging Face repository ID extraction from model metadata.
- Updated `get_onnx_model_meta` and `list_onnx_catalog_models` to utilize the new helper function for cleaner code and better handling of source metadata.
- Added unit tests for the new download functionality and metadata handling to ensure reliability and correctness.
- Introduced a logging mechanism for ONNX model downloads, redirecting progress output to a log file instead of stdout/stderr.
- Added a new method `ensure_log` in `PathLayout` to create and return the log file path.
- Updated unit tests to verify that download progress messages are correctly logged.
- Improved the `_download_hf_snapshot` function to utilize the new logging functionality, enhancing traceability during model downloads.
- Added a new `on_progress` callback to the `download_model_raced` function to report download progress.
- Implemented a `_ui_progress_from_bytes` function to calculate the fraction of downloaded bytes for better UI feedback.
- Updated the `OnnxDownloadManager` to utilize the new progress tracking during model downloads.
- Enhanced unit tests to verify the correct reporting of download progress and ensure that the new functionality works as intended.
- Eliminated the 10-second sleep for URLs starting with the Hugging Face official endpoint, streamlining the probe process.
- This change enhances the efficiency of the `probe_source` function by reducing unnecessary wait times during model downloads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant