(name)
| 119 | extra_objects[_import] = getattr(hf_util, _import) |
| 120 | |
| 121 | def try_import_from_hf(name): |
| 122 | hf_pkgs = ['transformers', 'peft', 'diffusers', 'kernels'] |
| 123 | module = None |
| 124 | matched_pkg = None |
| 125 | for pkg in hf_pkgs: |
| 126 | try: |
| 127 | module = getattr(importlib.import_module(pkg), name) |
| 128 | matched_pkg = pkg |
| 129 | break |
| 130 | except Exception: # noqa |
| 131 | pass |
| 132 | |
| 133 | if module is None: |
| 134 | raise AttributeError( |
| 135 | f'Cannot import available module of {name} in modelscope,' |
| 136 | f' or related packages({hf_pkgs})') |
| 137 | |
| 138 | if matched_pkg == 'kernels': |
| 139 | if callable(module): |
| 140 | from modelscope.utils.hf_util.patcher import \ |
| 141 | _wrap_kernels_callable |
| 142 | return _wrap_kernels_callable(name) |
| 143 | return module |
| 144 | |
| 145 | module = _patch_pretrained_class([module], wrap=True) |
| 146 | return module[0] |
| 147 | |
| 148 | import sys |
| 149 |
nothing calls this directly
no test coverage detected
searching dependent graphs…