MCPcopy Create free account
hub / github.com/modelscope/modelscope / normalize_model_input

Function normalize_model_input

modelscope/pipelines/builder.py:28–57  ·  view source on GitHub ↗

normalize the input model, to ensure that a model str is a valid local path: in other words, for model represented by a model id, the model shall be downloaded locally

(model,
                          model_revision,
                          third_party=None,
                          ignore_file_pattern=None)

Source from the content-addressed store, hash-verified

26
27
28def normalize_model_input(model,
29 model_revision,
30 third_party=None,
31 ignore_file_pattern=None):
32 """ normalize the input model, to ensure that a model str is a valid local path: in other words,
33 for model represented by a model id, the model shall be downloaded locally
34 """
35 if isinstance(model, str) and is_official_hub_path(model, model_revision):
36 # skip revision download if model is a local directory
37 if not os.path.exists(model):
38 # note that if there is already a local copy, snapshot_download will check and skip downloading
39 user_agent = {Invoke.KEY: Invoke.PIPELINE}
40 if third_party is not None:
41 user_agent[ThirdParty.KEY] = third_party
42 model = snapshot_download(
43 model,
44 revision=model_revision,
45 user_agent=user_agent,
46 ignore_file_pattern=ignore_file_pattern)
47 elif isinstance(model, list) and isinstance(model[0], str):
48 for idx in range(len(model)):
49 if is_official_hub_path(
50 model[idx],
51 model_revision) and not os.path.exists(model[idx]):
52 user_agent = {Invoke.KEY: Invoke.PIPELINE}
53 if third_party is not None:
54 user_agent[ThirdParty.KEY] = third_party
55 model[idx] = snapshot_download(
56 model[idx], revision=model_revision, user_agent=user_agent)
57 return model
58
59
60def build_pipeline(cfg: ConfigDict,

Callers 2

build_trainerFunction · 0.90
pipelineFunction · 0.85

Calls 3

snapshot_downloadFunction · 0.90
is_official_hub_pathFunction · 0.85
existsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…