Feat/modelscope support - #21985
Conversation
|
Thanks for your contribution. Could you avoid modifying the Also, please make sure to fully align with the ModelScope CLI across all OS, especially regarding cache directory layout and environment variables. I’d be surprised if ModelScope handles all these subtleties the same way as HF. |
Thank you for your suggestion. I have received it and will introduce a separate |
| add_opt(common_arg( | ||
| {"-ms", "-msr", "--ms-repo"}, "<user>/<model>[:quant]", | ||
| "ModelScope model repository; quant is optional, case-insensitive, default to Q4_K_M, or falls back to the first file in the repo if Q4_K_M doesn't exist.\n" | ||
| "mmproj is also downloaded automatically if available. to disable, add --no-mmproj\n" | ||
| "example: user/model:Q4_K_M\n" | ||
| "(default: unused)", | ||
| [](common_params & params, const std::string & value) { | ||
| params.model.hf_repo = value; | ||
| params.model.repo_type = LLAMA_REPO_TYPE_MS; | ||
| } | ||
| ).set_env("LLAMA_ARG_MS_REPO")); | ||
| add_opt(common_arg( | ||
| {"-msf", "--ms-file"}, "FILE", | ||
| "ModelScope model file. If specified, it will override the quant in --ms-repo (default: unused)", | ||
| [](common_params & params, const std::string & value) { | ||
| params.model.hf_file = value; | ||
| } | ||
| ).set_env("LLAMA_ARG_MS_FILE")); | ||
| add_opt(common_arg( | ||
| {"-mst", "--ms-token"}, "TOKEN", | ||
| "ModelScope access token (default: value from MS_TOKEN environment variable)", | ||
| [](common_params & params, const std::string & value) { |
There was a problem hiding this comment.
I remember there was a discussion in the past, #12664, in which we agreed not to add a new argument, otherwise it will be too bloated
If we really need it, I think the better way is to add only -ms and re-purpose other flags like --hf-file or --hf-token
There was a problem hiding this comment.
I remember there was a discussion in the past, #12664, in which we agreed not to add a new argument, otherwise it will be too bloated
If we really need it, I think the better way is to add only
-msand re-purpose other flags like--hf-fileor--hf-token
Understood!😄 I will limit the new arguments to only -ms and reuse --hf-file and --hf-token.
One quick question about private models: should we also reuse --hf-token and the HF_TOKEN environment variable for ModelScope authentication? For example, would users set HF_TOKEN="ms-xxxxxxx" when accessing private MS repos? Or should the code internally check for MS_TOKEN env as a fallback?
There was a problem hiding this comment.
I think adding an exception for MS_TOKEN is ok, maybe simply add a logic into common_params_parse_ex, something like:
const char * ms_token = get_env("MS_TOKEN");
if (ms_token) {
params.hf_token = ms_token
}Btw, we should technically change the name of hf_token to something more generic, like download_token, CC @angt if you think that can be a good idea. The CLI arg can stay as --hf-token, and we can add alias --ms-token and --download-token for it
There was a problem hiding this comment.
Absolutely, maybe --bearer-token too.
Ideally, I think only the -hf (and the new -ms flag) should stay.
There was a problem hiding this comment.
No strong opinion, but --bearer-token is a little bit ambiguous I think, someone can misunderstand it as "same with server's --api-key"
Overview
This PR introduces ModelScope integration for model downloading and loading.
Related PR: #20941
Key changes:
Enabled community model downloading via MODEL_ENDPOINT (defaults to https://modelscope.cn/), allowing flexible usage with or without explicit endpoint specification.
Usage examples:
Additional information
Requirements