mirror of
https://github.com/modelscope/modelscope.git
synced 2026-05-18 05:05:00 +02:00
ok Merge branch 'master' of github.com:modelscope/modelscope into release/1.36
This commit is contained in:
@@ -1,64 +1,51 @@
|
||||
FROM {base_image}
|
||||
|
||||
# Use bash so that `source` and other bash builtins work in all following RUN steps.
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
ENV PIP_DEFAULT_TIMEOUT=300
|
||||
ENV PIP_RETRIES=10
|
||||
ENV TRANSFORMERS_VERBOSITY=error
|
||||
ENV TRANSFORMERS_NO_ADVISORY_WARNINGS=1
|
||||
|
||||
RUN rm -f /etc/apt/apt.conf.d/docker-clean && \
|
||||
find /etc/apt/apt.conf.d -maxdepth 1 -type f | xargs -r grep -l "APT::Update::Post-Invoke\|docker-clean" | xargs -r rm -f && \
|
||||
apt-get update -y && \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
gcc g++ cmake ninja-build libnuma-dev libgl1 libglib2.0-0 libsm6 libxext6 libxrender1 \
|
||||
wget git curl jq vim build-essential ca-certificates && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple && \
|
||||
pip config set install.trusted-host mirrors.aliyun.com
|
||||
|
||||
# Prepare required system dependencies
|
||||
RUN apt-get update -y && \
|
||||
apt-get install -y --no-install-recommends gcc g++ cmake libnuma-dev wget git curl jq vim build-essential && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
|
||||
pip install --upgrade pip setuptools packaging && \
|
||||
pip cache purge
|
||||
|
||||
{extra_content}
|
||||
|
||||
# Prepare repositories with low update frequency
|
||||
RUN ARCH=$(uname -m) && \
|
||||
# Set extra pip index for x86_64 platform
|
||||
echo "[LOG INFO] Detected architecture: $ARCH" && \
|
||||
if [ "$ARCH" = "x86_64" ]; then \
|
||||
pip config set global.extra-index-url "https://download.pytorch.org/whl/cpu/"; \
|
||||
fi && \
|
||||
# Clone libs
|
||||
git clone --depth 1 --branch v0.11.0 https://github.com/vllm-project/vllm && \
|
||||
git clone --depth 1 --branch v0.11.0rc1 https://github.com/vllm-project/vllm-ascend.git && \
|
||||
git clone https://gitcode.com/Ascend/MindSpeed.git && \
|
||||
cd MindSpeed && git checkout f2b0977e && cd .. && \
|
||||
git clone --depth 1 --branch core_v0.12.1 https://github.com/NVIDIA/Megatron-LM.git
|
||||
# Reuse the vllm-ascend base image and only add the extra repos we need.
|
||||
# --depth 1 keeps the image smaller; branch/tag names work with shallow clone.
|
||||
RUN git clone --depth 1 --branch v0.15.3 https://github.com/NVIDIA/Megatron-LM.git /Megatron-LM && \
|
||||
git clone --depth 1 --branch core_r0.15.3 https://gitcode.com/Ascend/MindSpeed.git /MindSpeed && \
|
||||
GIT_LFS_SKIP_SMUDGE=1 git clone --depth 1 -b {swift_branch} --single-branch https://github.com/modelscope/ms-swift.git /ms-swift && \
|
||||
git clone --depth 1 https://github.com/modelscope/mcore-bridge.git /mcore-bridge
|
||||
|
||||
# Install repositories with low update frequency
|
||||
RUN ARCH=$(uname -m) && \
|
||||
# Export and source env
|
||||
if [ "$ARCH" = "aarch64" ]; then \
|
||||
export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/8.3.RC1/aarch64-linux/devlib/linux/aarch64:$LD_LIBRARY_PATH; \
|
||||
elif [ "$ARCH" = "x86_64" ]; then \
|
||||
export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/8.3.RC1/x86_64-linux/devlib/linux/x86_64/:$LD_LIBRARY_PATH; \
|
||||
fi && \
|
||||
source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
|
||||
source /usr/local/Ascend/nnal/atb/set_env.sh && \
|
||||
# Install torch & torch_npu & torchvision
|
||||
pip install torch==2.7.1 torch_npu==2.7.1 torchvision==0.22.1 && \
|
||||
# Install vllm
|
||||
cd vllm && VLLM_TARGET_DEVICE=empty pip install -v -e . && cd .. && \
|
||||
# Install vllm-ascend
|
||||
cd vllm-ascend && pip install -v -e . && cd .. && \
|
||||
# Install MindSpeed & Megatron
|
||||
pip install -e MindSpeed && \
|
||||
# Clear extra files
|
||||
rm -rf /tmp/* /var/tmp/* && \
|
||||
RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
|
||||
if [ -f /usr/local/Ascend/nnal/atb/set_env.sh ]; then source /usr/local/Ascend/nnal/atb/set_env.sh; fi && \
|
||||
cd /MindSpeed && pip install --no-cache-dir -e . && \
|
||||
cd /mcore-bridge && pip install --no-cache-dir -e . && \
|
||||
pip cache purge
|
||||
|
||||
ENV PYTHONPATH ${PYTHONPATH}:/Megatron-LM
|
||||
|
||||
ARG INSTALL_MS_DEPS={install_ms_deps}
|
||||
|
||||
ENV MEGATRON_LM_PATH=/Megatron-LM
|
||||
ENV PYTHONPATH=/Megatron-LM:${PYTHONPATH}
|
||||
# install dependencies
|
||||
COPY requirements /var/modelscope
|
||||
|
||||
RUN pip uninstall ms-swift modelscope -y && pip --no-cache-dir install pip==23.* -U && \
|
||||
RUN pip uninstall ms-swift modelscope -y && pip install --no-cache-dir pip==23.* -U && \
|
||||
if [ "$INSTALL_MS_DEPS" = "True" ]; then \
|
||||
pip --no-cache-dir install omegaconf==2.0.6 && \
|
||||
pip install --no-cache-dir omegaconf==2.0.6 && \
|
||||
pip install 'editdistance==0.8.1' && \
|
||||
pip install --no-cache-dir 'cython<=0.29.36' versioneer 'numpy<2.0' && \
|
||||
pip install --no-cache-dir -r /var/modelscope/framework.txt && \
|
||||
@@ -68,7 +55,7 @@ if [ "$INSTALL_MS_DEPS" = "True" ]; then \
|
||||
pip install --no-cache-dir https://modelscope.oss-cn-beijing.aliyuncs.com/packages/imageio_ffmpeg-0.4.9-py3-none-any.whl --no-dependencies --force && \
|
||||
pip install --no-cache-dir 'scipy<1.13.0' && \
|
||||
pip install --no-cache-dir funtextprocessing typeguard==2.13.3 scikit-learn && \
|
||||
pip install --no-cache-dir decord>=0.6.0 mpi4py paint_ldm ipykernel fasttext && \
|
||||
pip install --no-cache-dir 'decord>=0.6.0' mpi4py paint_ldm ipykernel fasttext && \
|
||||
pip install --no-cache-dir 'blobfile>=1.0.5' && \
|
||||
pip uninstall MinDAEC -y && \
|
||||
pip install https://modelscope.oss-cn-beijing.aliyuncs.com/releases/dependencies/MinDAEC-0.0.2-py3-none-any.whl && \
|
||||
@@ -81,17 +68,22 @@ fi
|
||||
ARG CUR_TIME={cur_time}
|
||||
RUN echo $CUR_TIME
|
||||
|
||||
RUN pip install --no-cache-dir -U funasr scikit-learn && \
|
||||
pip install --no-cache-dir -U qwen_vl_utils qwen_omni_utils librosa timm transformers accelerate peft trl safetensors && \
|
||||
cd /tmp && GIT_LFS_SKIP_SMUDGE=1 git clone -b {swift_branch} --single-branch https://github.com/modelscope/ms-swift.git && \
|
||||
cd ms-swift && pip install .[llm] && \
|
||||
pip install .[eval] && pip install evalscope -U --no-dependencies && pip install ms-agent -U --no-dependencies && \
|
||||
cd / && rm -fr /tmp/ms-swift && pip cache purge; \
|
||||
cd /tmp && GIT_LFS_SKIP_SMUDGE=1 git clone -b {modelscope_branch} --single-branch https://github.com/modelscope/modelscope.git && \
|
||||
RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
|
||||
if [ -f /usr/local/Ascend/nnal/atb/set_env.sh ]; then source /usr/local/Ascend/nnal/atb/set_env.sh; fi && \
|
||||
pip install --no-cache-dir -U funasr scikit-learn && \
|
||||
pip install --no-cache-dir -U qwen_vl_utils qwen_omni_utils librosa 'timm>=0.9.0' transformers accelerate peft trl safetensors && \
|
||||
cd /ms-swift && pip install --no-cache-dir -e '.[llm]' && \
|
||||
pip install --no-cache-dir -e '.[eval]' && pip install evalscope -U --no-dependencies && pip install ms-agent -U --no-dependencies && \
|
||||
cd /tmp && GIT_LFS_SKIP_SMUDGE=1 git clone -b {modelscope_branch} --single-branch https://github.com/modelscope/modelscope.git && \
|
||||
cd modelscope && pip install . -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html && \
|
||||
cd / && rm -fr /tmp/modelscope && pip cache purge; \
|
||||
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;
|
||||
cd / && rm -fr /tmp/modelscope && \
|
||||
pip install --no-cache-dir diffusers && \
|
||||
pip install --no-cache-dir omegaconf==2.3.0 && \
|
||||
pip cache purge
|
||||
|
||||
RUN echo 'source /usr/local/Ascend/ascend-toolkit/set_env.sh' >> /root/.bashrc && \
|
||||
echo '[ -f /usr/local/Ascend/nnal/atb/set_env.sh ] && source /usr/local/Ascend/nnal/atb/set_env.sh' >> /root/.bashrc && \
|
||||
echo 'set +H' >> /root/.bashrc
|
||||
|
||||
ENV SETUPTOOLS_USE_DISTUTILS=stdlib
|
||||
ENV VLLM_USE_MODELSCOPE=True
|
||||
@@ -100,5 +92,6 @@ ENV MODELSCOPE_CACHE=/mnt/workspace/.cache/modelscope/hub
|
||||
|
||||
# Show install results
|
||||
RUN pip list
|
||||
WORKDIR /workspace
|
||||
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
CMD ["/bin/bash"]
|
||||
|
||||
@@ -463,8 +463,8 @@ class AscendImageBuilder(StableGPUImageBuilder):
|
||||
|
||||
def init_args(self, args) -> Any:
|
||||
if not args.base_image:
|
||||
# other vision search for: https://hub.docker.com/r/ascendai/cann/tags
|
||||
args.base_image = 'swr.cn-south-1.myhuaweicloud.com/ascendhub/cann:8.3.rc1-a3-ubuntu22.04-py3.11'
|
||||
# Reuse the prebuilt vllm-ascend image to avoid rebuilding its stack.
|
||||
args.base_image = 'quay.io/ascend/vllm-ascend:v0.14.0rc1-a3'
|
||||
return super().init_args(args)
|
||||
|
||||
def generate_dockerfile(self) -> str:
|
||||
|
||||
@@ -12,7 +12,7 @@ import numpy as np
|
||||
#
|
||||
import torch
|
||||
from matplotlib.figure import Figure
|
||||
from swift import LoRAConfig, Swift
|
||||
from swift.tuners import LoRAConfig, Swift
|
||||
from tensorboard.backend.event_processing.event_accumulator import \
|
||||
EventAccumulator
|
||||
from torch import Tensor
|
||||
|
||||
@@ -35,7 +35,7 @@ attention.deprecate = lambda *arg, **kwargs: None
|
||||
__tuner_MAP__ = {'lora': LoRATuner, 'control_lora': ControlLoRATuner}
|
||||
|
||||
if is_swift_available():
|
||||
from swift import AdapterConfig, LoRAConfig, PromptConfig, Swift
|
||||
from swift.tuners import AdapterConfig, LoRAConfig, PromptConfig, Swift
|
||||
|
||||
|
||||
@MODELS.register_module(
|
||||
|
||||
@@ -281,7 +281,10 @@ def external_engine_for_llm_checker(model: Union[str, List[str], Model,
|
||||
|
||||
llm_framework = kwargs.get('llm_framework', '')
|
||||
if llm_framework == 'swift':
|
||||
from swift.llm import get_model_info_meta
|
||||
try:
|
||||
from swift.model import get_model_info_meta
|
||||
except ImportError:
|
||||
from swift.llm import get_model_info_meta
|
||||
# check if swift supports
|
||||
if os.path.exists(model):
|
||||
model_id = get_model_id_from_cache(model)
|
||||
|
||||
@@ -217,8 +217,11 @@ class LLMPipeline(Pipeline, PipelineStreamingOutputMixin):
|
||||
tokenizer_class) if tokenizer is None else tokenizer
|
||||
|
||||
def _init_swift(self, model_id, device) -> None:
|
||||
from swift.llm import prepare_model_template
|
||||
from swift.llm import InferArguments, get_model_info_meta
|
||||
try:
|
||||
from swift.pipelines import prepare_model_template
|
||||
from swift.arguments import InferArguments
|
||||
except ImportError:
|
||||
from swift.llm import prepare_model_template, InferArguments
|
||||
|
||||
def format_messages(messages: Dict[str, List[Dict[str, str]]],
|
||||
tokenizer: PreTrainedTokenizer,
|
||||
|
||||
@@ -390,7 +390,10 @@ def load_video_internvl(video_io: BytesIO, bound=None, num_segments=32):
|
||||
|
||||
def draw_plot(img_dir: str, bbox: List[int], bbox_type: str, output_file: str):
|
||||
from PIL import Image, ImageDraw
|
||||
from swift.llm.template.template import Template
|
||||
try:
|
||||
from swift.template import Template
|
||||
except ImportError:
|
||||
from swift.llm.template.template import Template
|
||||
image = Image.open(img_dir)
|
||||
|
||||
objects = [{'bbox': bbox, 'bbox_type': bbox_type, 'image': 0}]
|
||||
@@ -465,7 +468,10 @@ def load_audio_qwen(audio_io: BytesIO, sampling_rate: int):
|
||||
|
||||
|
||||
def load_video_qwen2(video_path: str):
|
||||
from swift.llm.template.template import get_env_args
|
||||
try:
|
||||
from swift.utils import get_env_args
|
||||
except ImportError:
|
||||
from swift.llm.template.template import get_env_args
|
||||
import torchvision
|
||||
from torchvision import io, transforms
|
||||
from qwen_vl_utils.vision_process import (round_by_factor, FPS, FRAME_FACTOR, FPS_MIN_FRAMES, FPS_MAX_FRAMES,
|
||||
|
||||
@@ -52,7 +52,7 @@ class SwiftCheckpointProcessor(CheckpointProcessor):
|
||||
raise ValueError(
|
||||
'Please install swift by `pip install ms-swift` to use SwiftHook.'
|
||||
)
|
||||
from swift import SwiftModel
|
||||
from swift.tuners import SwiftModel
|
||||
if isinstance(model, SwiftModel):
|
||||
_swift_output_dir = output_dir + SwiftCheckpointProcessor.SWIFT_SAVE_SUFFIX
|
||||
model.save_pretrained(
|
||||
|
||||
@@ -44,7 +44,7 @@ class TestVisionEfficientTuningSwiftTrainer(unittest.TestCase):
|
||||
exists('transformers<5.0'),
|
||||
'Skip test because transformers version is too high.')
|
||||
def test_vision_efficient_tuning_swift_lora_train(self):
|
||||
from swift import LoRAConfig
|
||||
from swift.tuners import LoRAConfig
|
||||
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-lora'
|
||||
|
||||
def cfg_modify_fn(cfg):
|
||||
@@ -86,7 +86,7 @@ class TestVisionEfficientTuningSwiftTrainer(unittest.TestCase):
|
||||
exists('transformers<5.0'),
|
||||
'Skip test because transformers version is too high.')
|
||||
def test_vision_efficient_tuning_swift_adapter_train(self):
|
||||
from swift import AdapterConfig
|
||||
from swift.tuners import AdapterConfig
|
||||
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-adapter'
|
||||
|
||||
def cfg_modify_fn(cfg):
|
||||
@@ -126,7 +126,7 @@ class TestVisionEfficientTuningSwiftTrainer(unittest.TestCase):
|
||||
exists('transformers<5.0'),
|
||||
'Skip test because transformers version is too high.')
|
||||
def test_vision_efficient_tuning_swift_prompt_train(self):
|
||||
from swift import PromptConfig
|
||||
from swift.tuners import PromptConfig
|
||||
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-prompt'
|
||||
|
||||
def cfg_modify_fn(cfg):
|
||||
|
||||
Reference in New Issue
Block a user