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)
| 26 | |
| 27 | |
| 28 | def 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 | |
| 60 | def build_pipeline(cfg: ConfigDict, |
no test coverage detected
searching dependent graphs…