Skip to content

funasr_wss_server.py ignores --asr_model and --asr_model_revision: the offline model is always paraformer-zh v2.0.4 #3886

Description

@tanishqbaweja

runtime/python/websocket/funasr_wss_server.py parses --asr_model and --asr_model_revision (funasr_wss_server.py:45-51), and the README lists --asr_model in the server's API reference (runtime/python/websocket/README.md:29). But the server builds its offline model from fixed values (funasr_wss_server.py:237-245):

model_asr = AutoModel(
    model="paraformer-zh",
    model_revision="v2.0.4",
    ngpu=args.ngpu,
    ...

So both options have no effect. A server started with --asr_model paraformer-en, or with the directory of a fine-tuned model, still runs paraformer-zh for its offline and 2pass-offline results. The default of --asr_model names yet another model, the Contextual Paraformer (iic/speech_paraformer-large-contextual_asr_nat-zh-cn-16k-common-vocab8404), which the server does not load either. The streaming, VAD and punctuation models are built from their options (--asr_model_online, --vad_model, --punc_model and their revisions).

The fixed values came with #2791. Before it, the server called AutoModel(model=args.asr_model, model_revision=args.asr_model_revision, ...).

Reproduction on main (6f52414), no model files. The server builds its models when it is imported, so this runs the real server module with AutoModel replaced by a recorder and prints the offline model for three command lines. It needs only numpy. Run it from the root of a FunASR checkout:

import contextlib
import importlib.util
import io
import sys
import types

# The server builds its models with AutoModel when it is imported. Replace AutoModel with a
# recorder (each call returns its keyword arguments), and the modules that the server only
# uses to serve requests (websockets, scipy, torch) with empty stand-ins.
funasr = types.ModuleType("funasr")
funasr.AutoModel = types.SimpleNamespace
sys.modules["funasr"] = funasr
for name in ("websockets", "torch", "scipy", "scipy.spatial", "scipy.spatial.distance"):
    sys.modules[name] = types.ModuleType(name)
sys.modules["scipy.spatial.distance"].cosine = None

SERVER = "runtime/python/websocket/funasr_wss_server.py"
for options in [
    [],
    ["--asr_model", "paraformer-en"],
    ["--asr_model", "/models/my-paraformer", "--asr_model_revision", "master"],
]:
    sys.argv = [SERVER, *options]
    spec = importlib.util.spec_from_file_location("funasr_wss_server", SERVER)
    server = importlib.util.module_from_spec(spec)
    with contextlib.redirect_stdout(io.StringIO()):  # "model loading" ...
        spec.loader.exec_module(server)
    server.EXECUTOR.shutdown()
    print(f"options {options}")
    print(f"  offline model: {server.model_asr.model} {server.model_asr.model_revision}")

Output:

options []
  offline model: paraformer-zh v2.0.4
options ['--asr_model', 'paraformer-en']
  offline model: paraformer-zh v2.0.4
options ['--asr_model', '/models/my-paraformer', '--asr_model_revision', 'master']
  offline model: paraformer-zh v2.0.4

Expected: the model that --asr_model and --asr_model_revision name (paraformer-en v2.0.4, /models/my-paraformer master), and paraformer-zh v2.0.4, as now, when they are not given.

Environment: Windows 11, Python 3.11.17, numpy 1.26.4, sources from main.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions