### Install ms-swift from GitHub Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/README.md Install the ms-swift library directly from its GitHub repository. This is the initial setup step. ```shell pip install git+https://github.com/modelscope/ms-swift.git ``` ```shell git clone https://github.com/modelscope/ms-swift.git cd ms-swift pip install -e . ``` -------------------------------- ### Quick Start: Fine-tuning Qwen2.5-7B-Instruct Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/GetStarted/Quick-start.md Example command for 10 minutes of self-cognition fine-tuning of Qwen2.5-7B-Instruct on a single 3090 GPU. ```shell swift-train --model_dir "Qwen/Qwen2.5-7B-Instruct" --num_train_epochs 0.1 --max_steps 100 --output_dir "./qwen2.5-7b-instruct-ft" --model_name "qwen2.5-7b-instruct" --lora_enable true --lora_r 8 --lora_alpha 16 --lora_dropout 0.05 --dataset_type "self-cognition" --dataset_path "/mnt/datasets/self-cognition/qwen2.5-7b-instruct" --sft_packing true --batch_size 2 --gradient_accumulation_steps 1 --learning_rate 1e-4 --weight_decay 0.01 --warmup_ratio 0.03 --lr_scheduler_type "cosine" --logging_steps 10 --save_strategy "steps" --save_steps 50 --evaluation_strategy "steps" --eval_steps 50 --do_eval true --report_to "tensorboard" --bf16 true --gradient_checkpointing true --deepspeed "ds_config.json" ``` -------------------------------- ### Install Dependencies with uv Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyagent/README.md Set up a virtual environment and install project dependencies using uv. ```bash uv venv uv sync ``` -------------------------------- ### Install ms-swift Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/采样.md Install the ms-swift library with LLM support. Alternatively, clone the repository and install from source. ```shell pip install ms-swift[llm] -U ``` ```shell git clone https://github.com/modelscope/ms-swift.git cd ms-swift pip install -e '.[llm]' ``` -------------------------------- ### SWIFT Mirror Image Examples Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source/GetStarted/SWIFT-installation.md Examples of SWIFT mirror image URLs for different versions and regions. These are used for environment setup. ```text # swift3.5.3 modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3 modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3 modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3 # swift3.4.1.post1 modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.26.0-swift3.4.1.post1 modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.26.0-swift3.4.1.post1 modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.26.0-swift3.4.1.post1 ``` ```text # swift3.3.0.post1 modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.3-modelscope1.25.0-swift3.3.0.post1 modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.3-modelscope1.25.0-swift3.3.0.post1 # swift3.2.2 modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.5.1-modelscope1.25.0-swift3.2.2 ``` -------------------------------- ### Install ms-swift from source Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Sample.md Installs the ms-swift library from its source code repository. This involves cloning the repository and then performing a local installation. ```shell git clone https://github.com/modelscope/ms-swift.git cd ms-swift pip install -e '.[llm]' ``` -------------------------------- ### Install SWIFT with Evaluation Support Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Evaluation.md Install the ms-swift package with the 'eval' extra to enable evaluation capabilities. Alternatively, install from source. ```shell pip install ms-swift[eval] -U ``` ```shell git clone https://github.com/modelscope/ms-swift.git cd ms-swift pip install -e '.[eval]' ``` -------------------------------- ### Start and Stop DeepAnalyze WebUI Source: https://github.com/ruc-datalab/deepanalyze/blob/main/README.md Commands to install dependencies, start, and stop the DeepAnalyze WebUI. Ensure you have cloned the repository and downloaded the DeepAnalyze-8B model. ```bash cd demo/chat/frontend npm install cd .. bash start.sh ``` ```bash bash stop.sh ``` -------------------------------- ### Start and Stop DeepAnalyze WebUI v2 Source: https://github.com/ruc-datalab/deepanalyze/blob/main/README.md Commands to install dependencies, configure environment variables, start, and stop the DeepAnalyze WebUI v2. This version includes support for HeyWhale API keys and Docker-based sandboxed code execution. ```bash cd demo/chat_v2/frontend npm install cd .. cp .env.example .env bash start.sh ``` ```bash bash stop.sh ``` -------------------------------- ### Self-Cognition Fine-tuning Example Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source_en/GetStarted/Quick-start.md Example command for performing 10 minutes of self-cognition fine-tuning of Qwen2.5-7B-Instruct on a single 3090 GPU. ```shell swift sft --model_id "Qwen/Qwen2.5-7B-Instruct" --dataset_type "self_cognition" --max_epochs 1 --output_dir "./qwen2.5-7b-instruct-sft" --model_name "qwen2.5-7b-instruct" --num_gpus 1 --max_steps 100 --save_steps 10 --logging_steps 1 --eval_steps 10 --batch_size 1 --gradient_accumulation_steps 1 --learning_rate 1e-5 --lr_scheduler_type "cosine" --warmup_ratio 0.03 --weight_decay 0.01 --lora_enable true --lora_r 8 --lora_alpha 16 --lora_dropout 0.05 --lora_target_modules "all" --gradient_checkpointing true --deepspeed "zero2" --fp16 true ``` -------------------------------- ### Fine-tune Qwen2.5-7B-Instruct Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source/GetStarted/Quick-start.md Example of fine-tuning Qwen2.5-7B-Instruct for 10 minutes on a single 3090 GPU using ms-swift. ```shell swift-train --model_dir /path/to/Qwen2.5-7B-Instruct --output_dir /path/to/output --num_train_epochs 0.1 --max_steps 100 --per_device_train_batch_size 2 --gradient_accumulation_steps 2 --learning_rate 1e-5 --model_name Qwen2.5-7B-Instruct --dataset_dir /path/to/dataset --use_lora True --lora_rank 8 --lora_alpha 32 --lora_dropout 0.05 ``` -------------------------------- ### Setup Retriever Environment Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/recipes/searchr1.md Create and activate a dedicated Conda environment for the retrieval server. This includes installing specific versions of Python, PyTorch, and other necessary libraries like faiss-gpu. ```bash # Create and activate the retriever environment with Python 3.10 conda create -n retriever python=3.10 -y conda activate retriever # Install PyTorch (with GPU support) and related libraries conda install numpy==1.26.4 # needed to stop incompatible version of numpy from being installed via pip pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124 # Install other Python packages pip install transformers datasets pyserini huggingface_hub # Install the GPU version of faiss conda install faiss-gpu==1.8.0 -c pytorch -c nvidia -y # Install the API service framework pip install uvicorn fastapi ``` -------------------------------- ### Build Documentation Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/README.md Run this command in the root directory to build the documentation. ```shell # in root directory: make docs ``` -------------------------------- ### Start Mock vLLM Server Source: https://github.com/ruc-datalab/deepanalyze/blob/main/demo/mock_vllm/README.md Navigate to the project directory and run this command to start the mock server. This server simulates vLLM's streaming response functionality. ```bash cd mock_vllm python start_mock_vllmserver.py ``` -------------------------------- ### Install and Install Pre-commit Hooks Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/getting-started/development.md Install pre-commit for linting and formatting. This command installs the package and then sets up the git hooks. ```bash uv pip install pre-commit pre-commit install ``` -------------------------------- ### Create Virtual Environment and Install Dependencies Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/README.md Create a virtual environment using uv and install project dependencies, including optional extras like vLLM. Activate the environment afterwards. ```bash # creates a venv at .venv/ uv sync --extra vllm source .venv/bin/activate ``` -------------------------------- ### Install MS-SWIFT Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Pre-training-and-Fine-tuning.md Install the MS-SWIFT library. If using deepspeed zero2/zero3, install the deepspeed library as well. ```shell pip install ms-swift -U ``` ```shell # If using deepspeed zero2/zero3 pip install deepspeed -U ``` -------------------------------- ### Install SWIFT from Source Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source_en/GetStarted/SWIFT-installation.md Clone the SWIFT repository and install it locally using pip. The '[all]' extra can be included for full capabilities. ```shell git clone https://github.com/modelscope/ms-swift.git cd ms-swift pip install -e . # Full capabilities # pip install -e '.[all]' ``` -------------------------------- ### Deploying a Fine-Tuned Model with Full Parameters Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Pre-training-and-Fine-tuning.md Command to start a deployment server for a model trained with full parameters. Use `--model` to specify the checkpoint directory and `--adapters` should be set to `None`. ```shell CUDA_VISIBLE_DEVICES=0 \ swift deploy \ --adapters output/vx-xxx/checkpoint-xxx \ --infer_backend pt \ --temperature 0 \ --max_new_tokens 2048 \ --served_model_name '' ``` -------------------------------- ### Install Dependencies from Requirements File Source: https://github.com/ruc-datalab/deepanalyze/blob/main/docs/DeepAnalyze_API_Key_Usage_Guide.md Install Python dependencies listed in the requirements.txt file. This is an alternative to installing packages individually. ```bash pip install -r requirements.txt ``` -------------------------------- ### Activate Virtual Environment and Install Dependencies with uv Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/getting-started/installation.md Activate the created virtual environment and install project dependencies, including optional vllm support, using uv sync. ```bash source /bin/activate uv sync --active --extra vllm ``` -------------------------------- ### Install Dependencies with Pip Source: https://github.com/ruc-datalab/deepanalyze/blob/main/docs/DeepAnalyze_API_Key_Usage_Guide.md Install the required Python packages for the DeepAnalyze application. This command installs all listed dependencies directly. ```bash pip install gradio openai fastapi uvicorn pandas requests python-multipart ``` -------------------------------- ### Initialize Trainer and Start Training Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/examples/notebook/qwen2_5-self-cognition/self-cognition-sft.ipynb Instantiate the Seq2SeqTrainer with the prepared model, arguments, and datasets, then begin the training process. This step also enables gradient checkpointing for memory efficiency. ```python # Get the trainer and start the training. model.enable_input_require_grads() # Compatible with gradient checkpointing trainer = Seq2SeqTrainer( model=model, args=training_args, data_collator=template.data_collator, train_dataset=train_dataset, eval_dataset=val_dataset, template=template, ) trainer.train() last_model_checkpoint = trainer.state.last_model_checkpoint logger.info(f'last_model_checkpoint: {last_model_checkpoint}') ``` -------------------------------- ### Start SWIFT Web UI Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source_en/GetStarted/Web-UI.md Use this command to launch the SWIFT Web UI for training and inference. Specify the language with the --lang argument. ```shell swift web-ui --lang zh # or en swift web-ui --lang en ``` -------------------------------- ### Run Example Scripts Source: https://github.com/ruc-datalab/deepanalyze/blob/main/API/README.md Execute these example scripts to test the API functionality. One uses the requests library, and the other uses the OpenAI library. ```bash cd example python exampleRequest.py # requests example python exampleOpenAI.py # OpenAI library example ``` -------------------------------- ### Install Megatron-SWIFT Dependencies Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Megatron-SWIFT-Training.md Install necessary Python packages for Megatron-SWIFT training. Ensure you use the recommended PyTorch versions. Refer to the provided GitHub issues for potential installation troubleshooting. ```shell pip install pybind11 # transformer_engine # If an installation error occurs, you can refer to this issue for resolution: https://github.com/modelscope/ms-swift/issues/3793 pip install git+https://github.com/NVIDIA/TransformerEngine.git@release_v2.3 # apex git clone https://github.com/NVIDIA/apex cd apex # https://github.com/modelscope/ms-swift/issues/4176 git checkout e13873debc4699d39c6861074b9a3b2a02327f92 pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" ./ # megatron-core pip install git+https://github.com/NVIDIA/Megatron-LM.git@core_r0.12.0 ``` -------------------------------- ### Install SWIFT from Source Code Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/GetStarted/SWIFT-installation.md Clone the SWIFT repository and install it in editable mode using pip. The '[all]' extra can be included for full capabilities. ```shell git clone https://github.com/modelscope/ms-swift.git cd ms-swift pip install -e . ``` ```shell pip install -e '.[all]' ``` -------------------------------- ### Multimodal Model Inference Example Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source/Instruction/Inference-and-deployment.md Example script for running multimodal inference. ```shell bash examples/app/mllm.sh ``` -------------------------------- ### OpenAI Client Example Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/source/Instruction/Inference-and-deployment.md Example of using the OpenAI client for inference with ms-swift. ```python python examples/deploy/client/llm/openai_client.py ``` -------------------------------- ### Start Web-UI for Training and Deployment Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/README.md Launch the Web-UI for a zero-threshold training and deployment interface. The UI language can be set using the SWIFT_UI_LANG environment variable. ```shell SWIFT_UI_LANG=en swift web-ui ``` -------------------------------- ### load function example Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/ms-swift/docs/README.md Example of the `load` function with Google style docstring. ```APIDOC ```python def load(file, file_format=None, **kwargs): """Load data from json/yaml/pickle files. This method provides a unified api for loading data from serialized files. Args: file (str or :obj:`Path` or file-like object): Filename or a file-like object. file_format (str, optional): If not specified, the file format will be inferred from the file extension, otherwise use the specified one. Currently supported formats include "json", "yaml/yml". Examples: >>> load('/path/of/your/file') # file is stored in disk >>> load('https://path/of/your/file') # file is stored on internet >>> load('oss://path/of/your/file') # file is stored in petrel Returns: The content from the file. """ ``` ``` -------------------------------- ### Start SearchR1 Training Run Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/recipes/searchr1.md From your base environment, set your Weights & Biases API key and execute the training script. This script uses 'uv' to package dependencies separately from the retriever environment. ```bash export WANDB_API_KEY=your_wandb_api_key bash examples/search/run_search.sh ``` -------------------------------- ### Install SkyRL-Gym from PyPI Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-gym/README.md Install the latest release of the skyrl-gym library using pip. ```bash pip install skyrl-gym ``` -------------------------------- ### Basic Sampling with SWIFT Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Sample.md Demonstrates the basic usage of the SWIFT sampling command-line tool. Specify the model, sampler engine, number of return sequences, and the dataset to generate sampled data. ```shell swift sample --model LLM-Research/Meta-Llama-3.1-8B-Instruct --sampler_engine pt --num_return_sequences 5 --dataset AI-ModelScope/alpaca-gpt4-data-zh#5 ``` -------------------------------- ### Install Dependencies and Patch for mmengine Error Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/Instruction/Frequently-asked-questions.md Addresses mmengine errors in Python 3.11 environments by suggesting a Python 3.10 environment or installing dependencies and a specific patch. Ensure all dependencies are installed before applying the patch. ```shell pip3 install evalscope[all] pip3 install https://modelscope-open.oss-cn-hangzhou.aliyuncs.com/package/evalscope-0.5.3.post1-py3-none-any.whl ``` -------------------------------- ### InfoNCE Loss Configuration Examples Source: https://github.com/ruc-datalab/deepanalyze/blob/main/deepanalyze/SkyRL/skyrl-train/docs/BestPractices/Embedding.md Examples of JSON objects demonstrating different configurations for InfoNCE loss, including query, response, and image paths. These examples illustrate how to structure data for training embedding models. ```json {"query": "", "response": "sentence", "images": "/some/images.jpg"} ``` ```json {"query": "sentence1", "response": "sentence2", "rejected_response": ["sentence1", "sentence2"], "images": ["/some/images.jpg", "/some/images.jpg", "/some/images.jpg", "/some/images.jpg"]} ```