From d72e3e0dc1f1fcdc7ca6a587255eae0722f6a927 Mon Sep 17 00:00:00 2001 From: Kareem <81531392+KareemMusleh@users.noreply.github.com> Date: Sun, 9 Mar 2025 08:51:07 +0700 Subject: [PATCH] move use_modelscope to _utils (#1938) * move use_modelscope to _utils * Update _utils.py * Update loader.py --------- Co-authored-by: Daniel Han --- unsloth/models/_utils.py | 8 ++++++++ unsloth/models/loader.py | 15 ++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 03eb21f4eb..25fa788099 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -25,6 +25,7 @@ __all__ = [ "__version__", "HAS_FLASH_ATTENTION", "HAS_FLASH_ATTENTION_SOFTCAPPING", + "USE_MODELSCOPE", "platform_system", "patch_tokenizer", "get_statistics", @@ -1271,3 +1272,10 @@ for j, function in enumerate(functions): try: exec(f"EMPTY_LOGITS.{function} = raise_{j}", globals(), locals()) except: continue pass + +USE_MODELSCOPE = os.environ.get("UNSLOTH_USE_MODELSCOPE", "0") == "1" +if USE_MODELSCOPE: + if importlib.util.find_spec("modelscope") is None: + raise ImportError(f'You are using the modelscope hub, please install modelscope by `pip install modelscope -U`') + pass +pass diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index 800c016cc8..6eee360d25 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -12,7 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ._utils import is_bfloat16_supported, HAS_FLASH_ATTENTION, HAS_FLASH_ATTENTION_SOFTCAPPING +from ._utils import ( + is_bfloat16_supported, + HAS_FLASH_ATTENTION, + HAS_FLASH_ATTENTION_SOFTCAPPING, + USE_MODELSCOPE, +) from .granite import FastGraniteModel from .llama import FastLlamaModel, logger from .mistral import FastMistralModel @@ -36,14 +41,6 @@ pass from huggingface_hub import HfFileSystem import importlib.util -# [TODO] Move USE_MODELSCOPE to utils -USE_MODELSCOPE = os.environ.get("UNSLOTH_USE_MODELSCOPE", "0") == "1" -if USE_MODELSCOPE: - if importlib.util.find_spec("modelscope") is None: - raise ImportError(f'You are using the modelscope hub, please install modelscope by `pip install modelscope -U`') - pass -pass - # https://github.com/huggingface/transformers/pull/26037 allows 4 bit loading! from unsloth_zoo.utils import Version, _get_dtype transformers_version = Version(transformers_version)