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

Function _wrap_kernels_callable

modelscope/utils/hf_util/patcher.py:649–662  ·  view source on GitHub ↗

Return a wrapper around `kernels. ` that scopes the ModelScope patch on `kernels.utils._get_hf_api` to the call itself, so `from kernels import ` stays on HuggingFace unless the user explicitly calls `patch_hub()` / `patch_context()`.

(attr_name)

Source from the content-addressed store, hash-verified

647
648
649def _wrap_kernels_callable(attr_name):
650 """Return a wrapper around `kernels.<attr_name>` that scopes the ModelScope
651 patch on `kernels.utils._get_hf_api` to the call itself, so
652 `from kernels import <attr_name>` stays on HuggingFace unless the user
653 explicitly calls `patch_hub()` / `patch_context()`.
654 """
655
656 def _wrapped(*args, **kwargs):
657 import kernels
658 with _kernels_patch_scope():
659 return getattr(kernels, attr_name)(*args, **kwargs)
660
661 _wrapped.__name__ = _wrapped.__qualname__ = attr_name
662 return _wrapped
663
664
665def _patch_hub():

Callers 1

try_import_from_hfFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…