月度归档:2024年11月

conda 安装及安装llama factory

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

source ~/miniconda3/bin/activate

conda init --all

查看所有conda

conda env list
conda info --envs
#二选一

激活conda环境

conda activate <环境名称>
#比如llama_factory
conda activate llama_factory

退出环境

conda deactivate

创建新环境 必须带PYTHON版本号

conda create -n <新环境名称> python=3.8

删除环境

conda env remove -n <环境名称>

更新环境

conda update --all

创建LLAMA FACTORY范例

conda create -n llama_factory python=3.10
conda activate llama_factory
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e ".[torch,metrics]"

pip install llamafactory

wget https://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/llama_factory/Qwen2-VL-History.zip
mv data rawdata && unzip Qwen2-VL-History.zip -d data
#下载Qwen2.0 数据集,并解压到data目录,可以下载不同的数据到data目录


USE_MODELSCOPE_HUB=1 llamafactory-cli webui
#设置为魔搭社区并启动webui

LLAMA Factory大模型微调 累计(1)

首先安装

git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip uninstall -y accelerate vllm matplotlib
pip install llamafactory==0.9.0
llamafactory-cli version

#下载Qwen2.0 数据集,并解压到data目录
wget https://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/llama_factory/Qwen2-VL-History.zip
mv data rawdata && unzip Qwen2-VL-History.zip -d data

预训练数据集中的是对话

然后启用webUI 并设置数据从魔搭社区下载(USE_MODELSCOPE_HUB=1 )

USE_MODELSCOPE_HUB=1 llamafactory-cli webui

进入WebUI后可以选择语言,模型名称,训练方法

python加入进程 且开启自启、进程死亡重启

linux下systemd设置

systemd在目录/etc/systemd/system/下的新建一个service后缀的脚本,中间添加python脚本的信息和关于配置的信息。

创建了python.service一个服务。

vi /etc/systemd/system/python.service
[Unit]
Description=WodePython
After=network.target

[Service]
ExecStart=/usr/bin/python3 /path/to/your/script.py
Restart=always
User=your_username

[Install]
WantedBy=multi-user.target
  • Description :服务的描述。
  • After :指定服务在哪些目标之后启动, network.target 表示在网络服务启动之后启动该服务。
  • ExecStart :服务启动时执行的命令,这里是运行Python脚本的命令。
  • Restart :设置服务在失败时的重启策略,
  • always 表示总是重启。
  • User :指定运行服务的用户。
  • WantedBy :指定服务希望被哪些目标所需要, multi-user.target 表示多用户运行模式。
sudo systemctl daemon-reload
#重新载入

sudo systemctl enable python.service
sudo systemctl start python.service
#设置python.service并启动


sudo systemctl status python.service
#可以查看python.service服务的当前状态

使用PILLOW 将文字列表转为PDF

from PIL import Image, ImageDraw, ImageFont

def img_txt(head_text,file_list):
    width, height = 2480, 3508
    image = Image.new('RGB', (width, height), color = (255, 255, 255))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype("/usr/share/fonts/simsun.ttc", 120)
    font2 = ImageFont.truetype("/usr/share/fonts/simsun.ttc", 80)
    head_text="关于文件《"+head_text+"》的附件"
    head_num=len(head_text)
    head_line=head_num//20+1 if head_num%20>0 else head_num//20
    for i in range(head_line):
        text_position = (20, 20+i*120)  # 文字的位置
        draw.text(text_position, head_text[i*20:i*20+20], font=font, fill=(0, 0, 0))
    start= 180+i*120
    j=0
    for file_one in file_list:
        one=str(j+1)+"."+file_one
        one_num=len(one)
        one_line=one_num//30+1 if one_num%30>0 else one_num//30
        x=0
        for x in range(one_line):
            if x>0:
                j=j+1
                text_position = (120, start+j*100)
            else:
                text_position = (80, start+j*100)  # 文字的位置
            draw.text(text_position, one[x*30:x*30+30], font=font2, fill=(0, 0, 0))
            x=x+1
        j=j+1
    image.save('hello.pdf',"PDF",resolution=300)

1.A4 分辨率为300DPI下2480×3508,需要再保存的时候设置DPI,resolution=300