LightGen项目安装与配置指南
1. 项目基础介绍
LightGen是一个高效文本到图像生成的预训练管道,基于Fluid/MAR框架进行开发。该项目旨在通过知识蒸馏和直接偏好优化来实现高效的图像生成。主要使用的编程语言是Python。
2. 项目使用的关键技术和框架
- 流体框架(Fluid): 一种用于图像生成和编辑的开源框架。
- 知识蒸馏(Knowledge Distillation): 一种模型压缩技术,用于将大型模型的知识转移到小型模型中。
- 直接偏好优化(Direct Preference Optimization): 一种优化技术,用于直接根据用户偏好来优化模型。
- PyTorch: 用于深度学习的开源机器学习库。
3. 项目安装和配置的准备工作与详细步骤
准备工作
- 确保系统中安装了Python(建议使用Python 3.10)。
- 安装conda(如果使用conda环境管理)。
- 准备一个合适的GPU环境,因为该项目需要使用GPU进行训练。
安装步骤
-
克隆项目仓库到本地:
git clone https://github.com/XianfengWu01/LightGen.git cd LightGen
-
创建并激活conda环境:
conda create -n everlyn_video python=3.10 conda activate everlyn_video
-
安装所需的Python包:
pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu121 pip install -U xformers==0.0.26 --index-url https://download.pytorch.org/whl/cu121 pip install -r requirements.txt
-
准备数据集:
-
下载并解压数据集到本地(请替换
hf_ur_token
为你的Hugging Face token):huggingface-cli download --token hf_ur_token --resume-download stabilityai/stable-diffusion-3.5-large --local-dir stable-diffusion-3.5-large huggingface-cli download --resume-download google/flan-t5-xxl --local-dir google/flan-t5-xxl huggingface-cli download --repo-type dataset --resume-download jackyhate/text-to-image-2M --local-dir text-to-image-2M
-
解压数据集:
mkdir -p untar for tar_file in *.tar; do dir_name=$(basename "$tar_file" .tar) mkdir -p "untar/$dir_name" tar -xvf "$tar_file" -C "untar/$dir_name" echo "Extraction completed: $tar_file to untar/$dir_name" done echo "All files have been extracted."
-
生成json文件以加速数据处理:
python generate_json.py
-
-
开始训练:
修改
scripts/run.sh
中的设置(如果需要),然后运行:sh run.sh
-
推断(Inference):
使用默认设置进行推断:
python pipeline_image.py
以上步骤为LightGen项目的详细安装和配置指南,按照这些步骤,即使是编程小白也应该能够顺利完成安装和配置。