unsolth VLLM 安装

pip install unsolth

安装即可

pip install vllm  # 如果使用 pip

执行VLLM张量并行

Qwen2.5-14B-Instruct部署 #

启动为兼容OpenAI的API服务。

单机双卡设置CUDA_VISIBLE_DEVICES环境变量。

1export CUDA_VISIBLE_DEVICES=0,1

设置了HF_HUB_OFFLINE=1将不会向Hugging Face Hub发起任何HTTP调用。加快加载时间,这也特别适合服务器没有外网访问时。

1export HF_HUB_OFFLINE=1

启动服务:

1vllm serve Qwen/Qwen2.5-14B-Instruct \
2  --served-model-name qwen2.5-14b-instruct \
3  --enable-auto-tool-choice \
4  --tool-call-parser hermes \
5  --max-model-len=32768 \
6  --tensor-parallel-size 2 \
7  --port 8000

--tensor-parallel-size 2

--tensor-parallel-size 2表示使用Tensor Parallelism技术来分配模型跨两个GPU

Tensor Parallelism是一种分布式深度学习技术,用于处理大型模型。

--tensor-parallel-size 设置为 2 时,模型的参数和计算会被分割成两部分,分别在两个GPU上进行处理。

这种方法可以有效地减少每个GPU上的内存使用,使得能够加载和运行更大的模型。

同时,它还可以在一定程度上提高计算速度,因为多个GPU可以并行处理模型的不同部分。

Tensor Parallelism对于大型语言模型(如 Qwen2.5-14B-Instruct)特别有用,因为这些模型通常太大,无法完全加载到单个GPU的内存中。

comfyui安装ComfyUI-Manager easy_use

安装ComfyUI-Manger

  1. 到 ComfyUI/custom_nodes 目录(CMD 命令行下)
  2. git clone https://github.com/ltdrdata/ComfyUI-Manager comfyui-manager (执行)
  3. 重启 ComfyUI

通过Manger搜索easy use 安装即可(方法一)


安装easy use(方法二)不需要comfyui-manager

到 ComfyUI/custom_nodes 目录(CMD 命令行下)

到 ComfyUI/custom_nodes目录(CMD 命令行下)git clone https://github.com/yolain/ComfyUI-Easy-Use.git
cd ComfyUI-Easy-Use
pip install -r requirements.txt

安装easy use(方法三 )不需要comfyui-manager

到 ComfyUI/custom_nodes目录(CMD 命令行下)git clone 
git clone https://github.com/yolain/ComfyUI-Easy-Use
#2. 安装依赖
双击install.bat安装依赖

Unsolth安装 微调 lora Qlora

https://unsloth.ai


如何运行 Unsloth

1. 安装环境

Conda 安装

conda create --name unsloth_env \
    python=3.11 \
    pytorch-cuda=12.1 \
    pytorch cudatoolkit xformers -c pytorch -c nvidia -c xformers \
    -y
conda activate unsloth_env

pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps trl peft accelerate bitsandbytes

Pip 安装

pip install --upgrade pip
pip install "unsloth[cu121-torch240] @ git+https://github.com/unslothai/unsloth.git"

使用教程

unsloth的使用非常简单,主要分为以下几个步骤:

  1. 导入必要的库:
from unsloth import FastLanguageModel
from unsloth import is_bfloat16_supported
import torch
from trl import SFTTrainer
from transformers import TrainingArgumentsrom datasets import load_dataset
  1. 加载预训练模型:
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/llama-3-8b-bnb-4bit",
    max_seq_length = 2048,
    dtype = None,
    load_in_4bit = True,
)
  1. 应用LoRA进行微调:
model = FastLanguageModel.get_peft_model(
    model,
    r = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",],
    lora_alpha = 16,
    lora_dropout = 0,
    bias = "none",    
    use_gradient_checkpointing = "unsloth",
    random_state = 3407,
    max_seq_length = 2048,
)
  1. 开始训练:
trainer = SFTTrainer(
    model = model,
    train_dataset = dataset,
    dataset_text_field = "text",
    max_seq_length = 2048,
    tokenizer = tokenizer,
    args = TrainingArguments(
        per_device_train_batch_size = 2,
        gradient_accumulation_steps = 4,
        warmup_steps = 10,
        max_steps = 60,
        fp16 = not is_bfloat16_supported(),
        bf16 = is_bfloat16_supported(),
        logging_steps = 1,
        output_dir = "outputs",
        optim = "adamw_8bit",
        seed = 3407,
    ),
)
trainer.train()