feat(server): add --model-path and --hub options to funasr-server#3299
Conversation
- Add --model-path argument for local model or model ID override - Add --hub argument to specify model hub (ms for ModelScope, hf for HuggingFace) - Support custom model loading via AutoModel with specified path and hub - Update API endpoints to handle 'custom' model type Co-authored-by: liudonghua123 <liudonghua123@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request adds support for custom local model paths and model hubs (ModelScope or HuggingFace) to the FunASR server by introducing --model-path and --hub CLI arguments. The review feedback highlights critical issues where loading a custom model via the fallback mechanism would crash due to missing configuration keys, and default models would fail to load because the hub defaults to ModelScope instead of HuggingFace when no custom path is specified.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| return None | ||
| from funasr import AutoModel | ||
| cfg = FALLBACK_CONFIGS[name].copy() |
There was a problem hiding this comment.
If a custom model_path is provided, the model name (e.g., "custom" or "fun-asr-nano") might not be present in FALLBACK_CONFIGS. Currently, _load_fallback will return None for any name not in FALLBACK_CONFIGS, causing a crash when attempting to load or run the custom model. We should allow fallback loading for custom models by returning {} from FALLBACK_CONFIGS and only returning None if app.state.model_path is not set.
| return None | |
| from funasr import AutoModel | |
| cfg = FALLBACK_CONFIGS[name].copy() | |
| if not app.state.model_path: | |
| return None | |
| from funasr import AutoModel | |
| cfg = FALLBACK_CONFIGS.get(name, {}).copy() |
| t0 = time.time() | ||
| # Use custom model_path if provided, otherwise default | ||
| vllm_model = app.state.model_path if app.state.model_path else "FunAudioLLM/Fun-ASR-Nano-2512" | ||
| vllm_hub = app.state.hub if app.state.hub else "hf" |
There was a problem hiding this comment.
The default hub for the fun-asr-nano model is "hf" (HuggingFace). Since app.state.hub defaults to "ms" (ModelScope), if the user does not provide a custom model_path, the server will attempt to load the default "FunAudioLLM/Fun-ASR-Nano-2512" model from ModelScope, which will fail. We should only use app.state.hub if a custom model_path is provided.
| vllm_hub = app.state.hub if app.state.hub else "hf" | |
| vllm_hub = app.state.hub if app.state.model_path else "hf" |
| "model": "FunAudioLLM/Fun-ASR-Nano-2512", | ||
| "hub": "hf", | ||
| "model": app.state.model_path if app.state.model_path else "FunAudioLLM/Fun-ASR-Nano-2512", | ||
| "hub": app.state.hub if app.state.hub else "hf", |
There was a problem hiding this comment.
Similar to the vLLM loader, the fallback loader for fun-asr-nano should only use app.state.hub if a custom model_path is provided, to avoid attempting to load the default HuggingFace model from ModelScope.
| "hub": app.state.hub if app.state.hub else "hf", | |
| "hub": app.state.hub if app.state.model_path else "hf", |
LauraGPT
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I think this needs one more pass before merge: the new custom model path does not appear to load correctly when users run the documented command with only --model-path.
In create_app(..., preload_model="auto", model_path=...), the preload branch calls _load_fallback(preload_model if preload_model != "auto" else "custom"), but custom is not in FALLBACK_CONFIGS. That means _load_fallback("custom") will not have a config to copy. Later, a request with model=custom calls _process_fallback(preload_model, ...), which is still auto for the documented command, so it also does not map cleanly to a loaded model.
Could you add a small test or manual validation log for the two intended paths?
funasr-server --model-path /path/to/model --hub msfunasr-server --model-path FunAudioLLM/Fun-ASR-Nano-2512 --hub hf --model fun-asr-nano
A simpler implementation may be to choose the serving id explicitly when model_path is set, store the custom model under that id, and make /v1/models plus model=custom resolve to the same loaded entry.
LauraGPT
left a comment
There was a problem hiding this comment.
Maintainer follow-up pushed in 1dbf9bfc and synced with current main in 05bc48a9.
This addresses the blocking server-loader review items:
- default
fun-asr-nanonow keeps using the Hugging Face hub unless a custom--model-pathis provided; - AutoModel fallback for default
fun-asr-nanouses the same hub rule; - custom model paths can load through an empty fallback config and are cached under the
customkey.
Validation on ind-gpu8:
python3 -m py_compile funasr/bin/_server_app.py funasr/bin/server.py tests/test_server_app_openai_segments.pypython3 -m pytest -q tests/test_cli.py tests/test_server_app_openai_segments.py -q-> 8 passedgit diff --check
Summary
Type of change
Validation
python -m compileall funasr examples testsUser impact
Nothing.
Notes for reviewers