Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dev_scripts/ci_container_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if [ "$MODELSCOPE_SDK_DEBUG" == "True" ]; then
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set global.extra-index-url https://pypi.org/simple/
pip config set install.trusted-host mirrors.aliyun.com
pip install -r requirements/tests.txt
git config --global --add safe.directory /Maas-lib
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ repos:
examples/|
modelscope/utils/ast_index_file.py|
modelscope/fileio/format/jsonplus.py|
modelscope/msdatasets/utils/_module_factories\.py
modelscope/msdatasets/utils/_module_factories\.py|
modelscope/hub/api\.py
)$
- repo: https://github.com/pre-commit/mirrors-yapf.git
rev: v0.30.0
Expand All @@ -33,7 +34,8 @@ repos:
examples/|
modelscope/utils/ast_index_file.py|
modelscope/fileio/format/jsonplus.py|
modelscope/msdatasets/utils/_module_factories\.py
modelscope/msdatasets/utils/_module_factories\.py|
modelscope/hub/api\.py
)$
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v3.1.0
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile.ascend
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
rm -rf /var/lib/apt/lists/*

RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple && \
pip config set global.extra-index-url "https://pypi.org/simple" && \
pip config set install.trusted-host mirrors.aliyun.com && \
ARCH=$(uname -m) && \
if [ "$ARCH" = "x86_64" ]; then \
pip config set global.extra-index-url "https://download.pytorch.org/whl/cpu/"; \
pip config set global.extra-index-url "https://pypi.org/simple https://download.pytorch.org/whl/cpu/"; \
fi

{extra_content}
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ RUN bash /tmp/install.sh {version_args} && \
pip install --no-cache-dir transformers diffusers 'timm>=0.9.0' && pip cache purge; \
pip install --no-cache-dir omegaconf==2.3.0 && pip cache purge; \
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple && \
pip config set global.extra-index-url https://pypi.org/simple && \
pip config set install.trusted-host mirrors.aliyun.com && \
cp /tmp/resources/ubuntu2204.aliyun /etc/apt/sources.list

Expand Down
1 change: 1 addition & 0 deletions docker/scripts/modelscope_env_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ else
fi

pip config set global.index-url https://mirrors.cloud.aliyuncs.com/pypi/simple
pip config set global.extra-index-url https://pypi.org/simple
pip config set install.trusted-host mirrors.cloud.aliyuncs.com
23 changes: 7 additions & 16 deletions modelscope/cli/base.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
"""CLI base class — re-exports :class:`CLICommand` from ``modelscope_hub``.

from abc import ABC, abstractmethod
from argparse import ArgumentParser
Kept as a thin alias so existing imports such as
``from modelscope.cli.base import CLICommand`` continue to work after the
CLI engine moved into ``modelscope_hub``.
"""

from modelscope_hub.cli.base import CLICommand # noqa: F401

class CLICommand(ABC):
"""
Base class for command line tool.

"""

@staticmethod
@abstractmethod
def define_args(parsers: ArgumentParser):
raise NotImplementedError()

@abstractmethod
def execute(self):
raise NotImplementedError()
__all__ = ['CLICommand']
30 changes: 20 additions & 10 deletions modelscope/cli/clearcache.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
"""Clear-cache CLI command — retained for backward compatibility.

The ``modelscope_hub`` CLI now owns ``clear-cache`` as an alias for
``cache clear``, but this module preserves the legacy :class:`ClearCacheCMD`
class so that existing tests and callers that import it directly continue
to work.
"""
import os
import shutil
from argparse import ArgumentParser

from modelscope.cli.base import CLICommand
from modelscope.hub.constants import TEMPORARY_FOLDER_NAME
from modelscope.hub.utils.utils import get_model_masked_directory
from modelscope.utils.file_utils import (get_dataset_cache_root,
get_model_cache_root,
get_modelscope_cache_dir)
Expand All @@ -24,6 +30,11 @@ def __init__(self, args):
self.args = args
self.cache_dir = get_modelscope_cache_dir()

@staticmethod
def register(subparsers) -> None:
"""Register clear-cache subcommand (CLICommand ABC contract)."""
ClearCacheCMD.define_args(subparsers)

@staticmethod
def define_args(parsers: ArgumentParser):
""" define args for clear-cache command.
Expand All @@ -33,17 +44,15 @@ def define_args(parsers: ArgumentParser):
group.add_argument(
'--model',
type=str,
help=
'The id of the model whose cache will be cleared. For clear-cache, '
'if neither model or dataset id is provided, entire cache will be cleared.'
)
help='The id of the model whose cache will be cleared. '
'If neither model or dataset id is provided, entire cache '
'will be cleared.')
group.add_argument(
'--dataset',
type=str,
help=
'The id of the dataset whose cache will be cleared. For clear-cache, '
'if neither model or dataset id is provided, entire cache will be cleared.'
)
help='The id of the dataset whose cache will be cleared. '
'If neither model or dataset id is provided, entire cache '
'will be cleared.')

parser.set_defaults(func=subparser_func)

Expand All @@ -64,7 +73,8 @@ def _execute_with_confirmation(self):
id = self.args.dataset
prompt = prompt + f'local cache for dataset {id}. '
else:
prompt = prompt + f'entire ModelScope cache at {self.cache_dir}, including ALL models and dataset.\n'
prompt = prompt + (f'entire ModelScope cache at {self.cache_dir}, '
f'including ALL models and dataset.\n')
all = True
user_input = input(
prompt
Expand Down
63 changes: 11 additions & 52 deletions modelscope/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,21 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
"""ModelScope CLI — delegates to the modelscope_hub CLI engine.

import argparse
import logging
The legacy ``modelscope`` / ``ms`` console-script entry points historically
lived here as a hand-rolled argparse tree. The hub CLI in ``modelscope_hub``
now owns command registration, plugin discovery, and error translation;
this module exists solely to preserve the import path used by the
``[project.scripts]`` entries in ``pyproject.toml``.
"""

from modelscope.cli.clearcache import ClearCacheCMD
from modelscope.cli.create import CreateCMD
from modelscope.cli.download import DownloadCMD
from modelscope.cli.llamafile import LlamafileCMD
from modelscope.cli.login import LoginCMD
from modelscope.cli.modelcard import ModelCardCMD
from modelscope.cli.pipeline import PipelineCMD
from modelscope.cli.plugins import PluginsCMD
from modelscope.cli.scancache import ScanCacheCMD
from modelscope.cli.server import ServerCMD
from modelscope.cli.skills import SkillsCMD
from modelscope.cli.studio import StudioCMD
from modelscope.cli.upload import UploadCMD
from modelscope.hub.constants import MODELSCOPE_ASCII
from modelscope.utils.logger import get_logger
from modelscope.version import __version__
import sys

logger = get_logger(log_level=logging.WARNING)
from modelscope_hub.cli.main import run_cmd as _run_cmd


def run_cmd():
print(MODELSCOPE_ASCII)
parser = argparse.ArgumentParser(
'ModelScope Command Line tool', usage='modelscope <command> [<args>]')
parser.add_argument(
'-V',
'--version',
action='version',
version=f'ModelScope CLI {__version__}')
parser.add_argument(
'--token', default=None, help='Specify ModelScope SDK token.')
subparsers = parser.add_subparsers(help='modelscope commands helpers')

CreateCMD.define_args(subparsers)
DownloadCMD.define_args(subparsers)
SkillsCMD.define_args(subparsers)
UploadCMD.define_args(subparsers)
ClearCacheCMD.define_args(subparsers)
PluginsCMD.define_args(subparsers)
PipelineCMD.define_args(subparsers)
ModelCardCMD.define_args(subparsers)
ServerCMD.define_args(subparsers)
LoginCMD.define_args(subparsers)
LlamafileCMD.define_args(subparsers)
ScanCacheCMD.define_args(subparsers)
StudioCMD.define_args(subparsers)

args = parser.parse_args()

if not hasattr(args, 'func'):
parser.print_help()
exit(1)
cmd = args.func(args)
cmd.execute()
"""Delegate to ``modelscope_hub.cli.main.run_cmd`` and propagate its exit code."""
sys.exit(_run_cmd())


if __name__ == '__main__':
Expand Down
Loading
Loading