common : refactor downloading system, handle mmproj with -hf option #12694
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.
Ref comment: #12664 (comment)
Changes in this PR:
common_get_hf_file--mmproj-url; if-hf-repois specify, we default to the value returned by HF backendThe goal is to make vision examples a bit more simple to play with, for example:
llama-gemma3-cli -hf bartowski/google_gemma-3-4b-it-GGUFnow works without specifying--mmprojThe download system is now moved to
arg.cpp. A new structcommon_params_modelis added to store the path/url of the model. The logic is as follow:View text caption
model.path,model.url, or hf_repo/hf_file is supplied from CLIcommon_params_handle_modelfirstly fill in and make sure the values are correct:hf_repois in therepo/user:tagformat, it ask the HF backend for thehf_filehf_repoandhf_fileis there, we construct themodel.urlmodel.urlis there but nomodel.path, we setmodel.pathto default cache directorycommon_params_handle_modelthen callcommon_download_modelto download the actual filecommon_download_file_singleto download the first shardcommon_download_file_multipleto download the remaining shardsAfter
common_params_handle_modelreturns, themodel.pathis ready to be loaded.Diagram generated by Claude:
sequenceDiagram actor CLI as common_params_parse_ex participant HMDL as common_params_handle_model participant DWN as common_download_model participant S1 as common_download_file_single participant SM as common_download_file_multiple CLI->>HMDL: model.path/model.url/hf_repo/hf_file Note over HMDL: Process inputs alt hf_repo in repo/user:tag format HMDL->>HMDL: Query HF backend for hf_file end alt both hf_repo & hf_file exist HMDL->>HMDL: Construct model.url end alt model.url exists but no model.path HMDL->>HMDL: Set model.path to default cache end HMDL->>DWN: Download model.url to model.path DWN->>S1: Download first shard S1-->>DWN: First shard downloaded alt Multiple shards exist DWN->>SM: Download remaining shards SM-->>DWN: All shards downloaded end DWN-->>HMDL: Download complete HMDL-->>CLI: model.path ready to be loaded