十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

DiffSynth-Studio 中的 FLUX.2 全指南:推理、低显存部署与模型训练实战

DiffSynth-Studio 中的 FLUX.2 全指南:推理、低显存部署与模型训练实战 DiffSynth-Studio 中的 FLUX.2 全指南推理、低显存部署与模型训练实战【免费下载链接】DiffSynth-StudioEnjoy the magic of Diffusion models!项目地址: https://gitcode.com/GitHub_Trending/dif/DiffSynth-StudioFLUX.2 是 Black Forest Labs 训练并开源的新一代图像生成模型系列。本文以 docs/en/Model_Details/FLUX2.md 为核心结合 DiffSynth-Studio 仓库中的 Pipeline 源码与示例脚本系统讲解如何在 DiffSynth-Studio 中完成 FLUX.2 的安装、标准推理、低显存推理VRAM 管理、图生图/编辑、模板Template模型使用以及全参训练、LoRA 训练与训练后验证。读完本文你将能够基于仓库自带示例在单卡环境最低约 10GB 显存上跑通 FLUX.2 全流程并掌握统一训练脚本的全部关键参数。FLUX.2 与 DiffSynth-Studio 的对接方式FLUX.2 由 Black Forest Labs 训练并开源是一系列文本到图像text-to-image生成模型。在 DiffSynth-Studio 中FLUX.2 系列模型统一通过 Flux2ImagePipeline 加载与调用。从 Pipeline 源码可以看到FLUX.2 的模型栈由四部分组成见 flux2_image.py| 组件 | 源码中的属性 | 对应模型文件 | | - | - | - | | 文本编码器Mistral3 系 |text_encoderFlux2TextEncoder |text_encoder/*.safetensors| | 文本编码器Qwen3 系可选 |text_encoder_qwen3ZImageTextEncoder | 随模型仓库自动加载 | | 扩散主干网络 |ditFlux2DiT见 flux2_dit.py |transformer/*.safetensors| | 变分自编码器 |vaeFlux2VAE |vae/diffusion_pytorch_model.safetensors| | 分词器 |tokenizerAutoTokenizer/AutoProcessor |tokenizer/目录 |Flux2ImagePipeline在初始化时指定了height_division_factor16、width_division_factor16即宽高必须是 16 的倍数并使用FlowMatchScheduler(FLUX.2)作为噪声调度器详见 flow_match.py 中的set_timesteps_flux2。FLUX.2 的调度器实现采用 sigma 线性采样加指数 shiftmu根据图像 token 数量动态计算并把dit标记为可编译模型compilable_models [dit]为后续torch.compile加速预留了接口。环境安装在推理和训练之前请先安装 DiffSynth-Studiogit clone https://github.com/modelscope/DiffSynth-Studio.git cd DiffSynth-Studio pip install -e .更完整的依赖安装说明请参考 安装依赖。推理前请确认本机具备可用的 CUDA GPU并安装好与 PyTorch 版本匹配的 CUDA 工具链。快速开始标准推理运行以下代码即可快速加载black-forest-labs/FLUX.2-dev模型并完成一次推理。该示例开启了显存管理VRAM management框架会根据剩余显存自动控制模型参数的加载时机最低约需 10GB 显存from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig import torch vram_config { offload_dtype: disk, offload_device: disk, onload_dtype: torch.float8_e4m3fn, onload_device: cpu, preparing_dtype: torch.float8_e4m3fn, preparing_device: cuda, computation_dtype: torch.bfloat16, computation_device: cuda, } pipe Flux2ImagePipeline.from_pretrained( torch_dtypetorch.bfloat16, devicecuda, model_configs[ ModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patterntext_encoder/*.safetensors, **vram_config), ModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patterntransformer/*.safetensors, **vram_config), ModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patternvae/diffusion_pytorch_model.safetensors), ], tokenizer_configModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patterntokenizer/), vram_limittorch.cuda.mem_get_info(cuda)[1] / (1024 ** 3) - 0.5, ) prompt High resolution. A dreamy underwater portrait of a serene young woman in a flowing blue dress. Her hair floats softly around her face, strands delicately suspended in the water. Clear, shimmering light filters through, casting gentle highlights, while tiny bubbles rise around her. Her expression is calm, her features finely detailed—creating a tranquil, ethereal scene. image pipe(prompt, seed42, rand_devicecuda, num_inference_steps50) image.save(image.jpg)上述代码与 examples/flux2/model_inference_low_vram/FLUX.2-dev.py 完全一致。其中ModelConfig(model_id..., origin_file_pattern...)指定从哪个模型仓库、按哪种文件通配符加载哪个子模型。每个子模型都可以单独配置显存策略通过**vram_config展开。tokenizer_config单独指定分词器目录。vram_limit以 GB 为单位给出显存预算上限示例中取整卡显存减去 0.5GB 的余量。如果你的显存足够例如 24GB 以上可以直接使用 examples/flux2/model_inference/FLUX.2-dev.py 中更简单的配置——所有子模型以 bf16 常驻 GPU无需磁盘卸载。vram_config 六个字段的含义vram_config是 DiffSynth-Studio 显存管理机制的核心配置六个字段分别描述模型参数在计算与驻留两个状态之间的流转方式| 字段 | 示例值 | 含义 | | - | - | - | |offload_dtype|disk/torch.bfloat16| 参数卸载后的保存精度。设为disk表示直接以原始形式写到磁盘 | |offload_device|disk/cpu| 参数卸载后驻留的设备disk表示磁盘内存最省cpu表示内存 | |onload_dtype|torch.float8_e4m3fn| 参数从卸载位置搬回时的精度低显存场景常用 FP8 压缩搬运 | |onload_device|cpu| 参数搬回后的中间驻留设备 | |preparing_dtype|torch.float8_e4m3fn/torch.bfloat16| 参数在 GPU 上做前处理时的精度 | |computation_dtype|torch.bfloat16| 实际参与算子计算的精度 | |computation_device|cuda| 实际计算的设备 |低显存场景如 10GB 卡推荐offload到disk、搬运时用 FP8、计算时用 bf16 的组合即本文示例的配置显存稍宽裕时可将offload_device改为cpu并全程使用 bf16参考 FLUX.2-dev.py 标准推理脚本。更完整的显存管理机制说明见 显存管理指南。模型清单与示例资源总览FLUX.2 系列在 DiffSynth-Studio 中覆盖了推理、低显存推理、全参训练、LoRA 训练与各自验证脚本资源分布如下表所示链接均为仓库内相对路径| 模型 | 推理 | 低显存推理 | 全参训练 | 全参验证 | LoRA 训练 | LoRA 验证 | | - | - | - | - | - | - | - | |black-forest-labs/FLUX.2-dev| code | code | - | - | code | code | |black-forest-labs/FLUX.2-klein-4B| code | code | code | code | code | code | |black-forest-labs/FLUX.2-klein-9B| code | code | code | code | code | code | |black-forest-labs/FLUX.2-klein-base-4B| code | code | code | code | code | code | |black-forest-labs/FLUX.2-klein-base-9B| code | code | code | code | code | code | |DiffSynth-Studio/Template-KleinBase4B-Aesthetic等 10 个模板模型 | code 等 | 同名 low_vram 目录 | code 等 | code 等 | - | - | |DiffSynth-Studio/KleinBase4B-i2L-v2| code | code | code | code | - | - |说明FLUX.2-klein-*系列为蒸馏版klein 蒸馏模型推理步数更少如num_inference_steps4klein-base为基座版Template-KleinBase4B-*是 DiffSynth-Studio 发布的模板Template模型用于把属性控制 LoRA 批量合成到基座模型上KleinBase4B-i2L-v2用于图像到 LoRAimage-to-LoRA任务。表中列出的所有脚本均可在examples/flux2/对应目录下找到。模型推理参数详解模型统一通过Flux2ImagePipeline.from_pretrained加载加载方式详见 模型加载说明。Flux2ImagePipeline.__call__的完整签名见 flux2_image.py主要输入参数如下| 参数 | 说明 | 默认值 | | - | - | - | |prompt| 描述图像中应出现内容的提示词 || |negative_prompt| 描述图像中不应出现内容的负向提示词 || |cfg_scale| 无分类器引导CFG系数大于 1 时启用 CFG |1| |height/width| 图像高/宽必须是 16 的倍数 |1024/1024| |seed| 随机种子None表示完全随机 |None| |rand_device| 生成随机高斯噪声所用设备设为cuda时不同 GPU 会产生不同结果 |cpu| |num_inference_steps| 推理步数 |30| |embedded_guidance| 内嵌引导embedded guidance系数 | 文档标注3.5源码__call__签名默认4.0见 flux2_image.py | |t5_sequence_length| T5 文本编码器的序列长度实际对应文本编码器的max_sequence_length |512| |tiled| 是否启用 VAE 分块tiling推理True可显著降低 VAE 编解码阶段的显存占用但会产生轻微误差并略微增加推理耗时 |False| |tile_size| VAE 编解码阶段的块大小仅在tiledTrue时生效 |128| |tile_stride| VAE 编解码阶段的块步长仅在tiledTrue时生效必须 ≤tile_size|64| |progress_bar_cmd| 进度条实现默认tqdm.tqdm设为lambda x: x可关闭 |tqdm.tqdm|此外__call__还支持以下高级入参源码层面确认图生图/图像编辑input_image配合denoising_strength默认1.0、edit_image可传PIL.Image或列表配合edit_image_auto_resizeTrue自动缩放到约 1024×1024 面积、edit_image_auto_resizeInpaint局部重绘inpaint_mask以及可选的inpaint_blur_size、inpaint_blur_sigma对蒙版做高斯模糊软化LoRA / KV Cachelora、negative_lora、kv_cache、negative_kv_cache、extra_text_embedding等支持 LoRA 注入与文本嵌入扩展initial_noise自定义初始噪声跳过随机生成。从源码看推理流程Flux2ImagePipeline内部把整个推理组织为一条 PipelineUnit 链见 flux2_image.pyShapeChecker尺寸对齐→PromptEmbedderMistral3 系文本编码→Qwen3PromptEmbedder可选 Qwen3 文本编码→NoiseInitializer噪声初始化→InputImageEmbedder图生图潜变量编码→EditImageEmbedder编辑图编码→ImageIDs位置 ID 构造→Inpaint蒙版预处理。每个 Unit 通过onload_model_names声明自己需要哪个子模型显存管理据此按需加载/卸载。在去噪循环中模型前向由model_fn_flux2完成见 flux2_image.py它对latents、timestep/1000、embedded_guidance、prompt_embeds及txt_ids/img_ids坐标做组装后送入Flux2DiT并支持kv_cache、extra_text_embedding拼接以及训练时的use_gradient_checkpointing。文本编码环节中Mistral3 系编码器取第 10/20/30 层隐藏状态拼接hidden_states_layers(10, 20, 30)Qwen3 编码器取第 9/18/27 层见 flux2_image.py 与 flux2_image.py。推理实战蒸馏版少步推理与图像编辑FLUX.2-klein-4B是蒸馏模型只需 4 步即可出图且原生支持基于参考图的编辑edit_image参数见 examples/flux2/model_inference/FLUX.2-klein-4B.pyfrom diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig import torch pipe Flux2ImagePipeline.from_pretrained( torch_dtypetorch.bfloat16, devicecuda, model_configs[ ModelConfig(model_idblack-forest-labs/FLUX.2-klein-4B, origin_file_patterntext_encoder/*.safetensors), ModelConfig(model_idblack-forest-labs/FLUX.2-klein-4B, origin_file_patterntransformer/*.safetensors), ModelConfig(model_idblack-forest-labs/FLUX.2-klein-4B, origin_file_patternvae/diffusion_pytorch_model.safetensors), ], tokenizer_configModelConfig(model_idblack-forest-labs/FLUX.2-klein-4B, origin_file_patterntokenizer/), ) prompt Masterpiece, best quality. Anime-style portrait of a woman in a blue dress, underwater, surrounded by colorful bubbles. image pipe(prompt, seed0, rand_devicecuda, num_inference_steps4) image.save(image_FLUX.2-klein-4B.jpg) prompt change the color of the clothes to red image pipe(prompt, edit_image[image], seed1, rand_devicecuda, num_inference_steps4) image.save(image_edit_FLUX.2-klein-4B.jpg)同样地FLUX.2-dev 推理脚本 在首次生成后也会用edit_image[Image.open(image_FLUX.2-dev.jpg)]并配合embedded_guidance2.5完成一次风格改写Transform the image into Japanese anime style。模板Template模型的使用Template-KleinBase4B-*系列是属性控制模板模型例如 Aesthetic美学、Brightness亮度、Age年龄、SoftRGB柔和 RGB、Sharpness锐度、ContentRef内容参考、ControlNet、Edit、Inpaint、PandaMeme、Upscaler 等。使用方式见 Template-KleinBase4B-Aesthetic.py先以klein-base-4B的 transformer 与klein-4B的文本编码器/VAE 构建基础 Pipeline并调用pipe.enable_lora_hot_loading(pipe.dit)开启 LoRA 热加载再用TemplatePipeline.from_pretrained加载模板模型通过template_inputs中的lora_ids如list(range(1, 180, 2))、lora_scales如1.0/2.5与merge_type如mean批量合成 LoRA 后生成图像。模板模型使一张图内组合多种属性控制成为可能这是 FLUX.2 生态中非常有特色的能力。模型训练FLUX.2 系列模型统一通过 examples/flux2/model_training/train.py 训练。该脚本基于Flux2ImageTrainingModule内部复用Flux2ImagePipeline并在推理管线之上挂接训练任务与损失函数FlowMatchSFTLoss、DirectDistillLoss见 train.py。训练任务通过--task指定例如sft监督微调、sft:data_process数据预处理阶段、direct_distill直接蒸馏等。通用训练参数训练脚本的参数分为以下几组数据集基础配置| 参数 | 说明 | | - | - | |--dataset_base_path| 数据集根目录 | |--dataset_metadata_path| 数据集元数据文件路径 | |--dataset_repeat| 每个 epoch 中数据集重复的次数 | |--dataset_num_workers| 每个 DataLoader 的进程数 | |--data_file_keys| 从元数据中加载的字段名通常是图片或视频文件路径以,分隔 |模型加载配置| 参数 | 说明 | | - | - | |--model_paths| 要加载的模型路径JSON 格式 | |--model_id_with_origin_paths| 模型 ID 与原始文件路径的组合如black-forest-labs/FLUX.2-dev:text_encoder/*.safetensors多个条目以,分隔 | |--extra_inputs| Pipeline 所需的额外输入参数如训练 ControlNet 模型时的controlnet_inputs以,分隔 | |--fp8_models| 以 FP8 格式加载的模型格式与--model_paths/--model_id_with_origin_paths一致。目前仅支持参数不参与梯度更新的模型无梯度回传或梯度只更新其 LoRA | |--quant_options| 对加载的模型做动态量化。分号分隔多个条目每个条目形如model_string:method[/exclude_modules]其中model_string对应--model_paths/--model_id_with_origin_paths中的某一项method是已注册的量化方法如bitsandbytes_nf4exclude_modules可选地列出保持全精度的层 |训练基础配置| 参数 | 说明 | | - | - | |--learning_rate| 学习率 | |--num_epochs| 训练轮数 | |--trainable_models| 可训练模型如dit、vae、text_encoder| |--find_unused_parameters| DDP 训练中是否存在未使用参数。部分模型含不参与梯度计算的冗余参数多卡训练时需开启以避免报错 | |--weight_decay| 权重衰减大小对应torch.optim.AdamW的weight_decay| |--task| 训练任务默认sft。部分模型支持更多训练模式请参考各模型文档 |输出配置| 参数 | 说明 | | - | - | |--output_path| 模型保存路径 | |--remove_prefix_in_ckpt| 移除模型 state dict 中的前缀 | |--save_steps| 保存模型的训练步数间隔留空则每个 epoch 保存一次 |LoRA 配置| 参数 | 说明 | | - | - | |--lora_base_model| 为哪个模型添加 LoRA | |--lora_target_modules| 为哪些层添加 LoRA | |--lora_rank| LoRA 秩 | |--lora_checkpoint| LoRA 检查点路径提供后将从该检查点加载 LoRA | |--preset_lora_path| 预设 LoRA 检查点路径提供后将以合并进基座模型的形式加载用于 LoRA 差分训练 | |--preset_lora_model| 预设 LoRA 合并进的目标模型如dit|梯度配置| 参数 | 说明 | | - | - | |--use_gradient_checkpointing| 是否启用梯度检查点 | |--use_gradient_checkpointing_offload| 是否将梯度检查点卸载到内存 | |--gradient_accumulation_steps| 梯度累积步数 |图像宽高配置适用于图像与视频生成模型| 参数 | 说明 | | - | - | |--height/--width| 图像或视频的高/宽两者同时留空则启用动态分辨率 | |--max_pixels| 图像或视频帧的最大像素面积。动态分辨率下分辨率大于该值的图像会被缩小小于该值的保持不变 |FLUX.2 专属参数| 参数 | 说明 | | - | - | |--tokenizer_path| 分词器路径适用于文生图模型留空则自动从远端下载 |示例数据集仓库为 FLUX.2 训练准备了示例图像数据集可用如下命令下载modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --local_dir ./data/diffsynth_example_dataset各模型训练脚本中使用了更精确的--include过滤例如flux2/FLUX.2-dev/*只下载对应子目录可参考 FLUX.2-dev LoRA 训练脚本。LoRA 训练实战FLUX.2-devexamples/flux2/model_training/lora/FLUX.2-dev.sh 采用先缓存、后训练的两阶段流程第一阶段以--task sft:data_process仅做数据预处理把 VAE 编码结果缓存到磁盘第二阶段从缓存读取数据、只加载 transformer 并做 LoRA 训练modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include flux2/FLUX.2-dev/* --local_dir ./data/diffsynth_example_dataset # 第一阶段数据预处理与缓存 accelerate launch examples/flux2/model_training/train.py \ --dataset_base_path data/diffsynth_example_dataset/flux2/FLUX.2-dev \ --dataset_metadata_path data/diffsynth_example_dataset/flux2/FLUX.2-dev/metadata.csv \ --max_pixels 1048576 \ --dataset_repeat 1 \ --model_id_with_origin_paths black-forest-labs/FLUX.2-dev:text_encoder/*.safetensors,black-forest-labs/FLUX.2-dev:vae/diffusion_pytorch_model.safetensors \ --learning_rate 1e-4 \ --num_epochs 5 \ --remove_prefix_in_ckpt pipe.dit. \ --output_path ./models/train/FLUX.2-dev-LoRA-splited-cache \ --lora_base_model dit \ --lora_target_modules to_q,to_k,to_v,add_q_proj,add_k_proj,add_v_proj,to_qkv_mlp_proj,to_out.0,to_add_out,linear_in,linear_out,single_transformer_blocks.0.attn.to_out,...,single_transformer_blocks.47.attn.to_out \ --lora_rank 32 \ --use_gradient_checkpointing \ --dataset_num_workers 8 \ --task sft:data_process # 第二阶段LoRA 训练 accelerate launch examples/flux2/model_training/train.py \ --dataset_base_path ./models/train/FLUX.2-dev-LoRA-splited-cache \ --max_pixels 1048576 \ --dataset_repeat 50 \ --model_id_with_origin_paths black-forest-labs/FLUX.2-dev:transformer/*.safetensors \ --learning_rate 1e-4 \ --num_epochs 5 \ --remove_prefix_in_ckpt pipe.dit. \ --output_path ./models/train/FLUX.2-dev-LoRA-splited \ --lora_base_model dit \ --lora_target_modules to_q,to_k,to_v,add_q_proj,add_k_proj,add_v_proj,to_qkv_mlp_proj,to_out.0,to_add_out,linear_in,linear_out,single_transformer_blocks.0.attn.to_out,...,single_transformer_blocks.47.attn.to_out \ --lora_rank 32 \ --use_gradient_checkpointing \ --dataset_num_workers 8 \ --task sft:train要点解读--lora_target_modules覆盖了 FLUX.2 DiT 中双流dual-stream注意力与单流single-stream注意力的投影层to_q/to_k/to_v/add_q_proj/.../to_out注意single_transformer_blocks.N.attn.to_out需要逐层显式列出示例中为 0 到 47 共 48 层。--remove_prefix_in_ckpt pipe.dit.用于在保存/恢复时去掉 state dict 的前缀。第一阶段--dataset_repeat 1只过一遍数据以生成缓存第二阶段--dataset_repeat 50在缓存上重复 50 轮训练。--max_pixels 1048576即 1024×1024 像素上限配合动态分辨率使用。全参训练实战FLUX.2-klein-4B全参Full训练以--trainable_models dit指定只训练 DiT见 examples/flux2/model_training/full/FLUX.2-klein-4B.shmodelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include flux2/FLUX.2-klein-4B/* --local_dir ./data/diffsynth_example_dataset accelerate launch examples/flux2/model_training/train.py \ --dataset_base_path data/diffsynth_example_dataset/flux2/FLUX.2-klein-4B \ --dataset_metadata_path data/diffsynth_example_dataset/flux2/FLUX.2-klein-4B/metadata.csv \ --max_pixels 1048576 \ --dataset_repeat 50 \ --model_id_with_origin_paths black-forest-labs/FLUX.2-klein-4B:text_encoder/*.safetensors,black-forest-labs/FLUX.2-klein-4B:transformer/*.safetensors,black-forest-labs/FLUX.2-klein-4B:vae/diffusion_pytorch_model.safetensors \ --tokenizer_path black-forest-labs/FLUX.2-klein-4B:tokenizer/ \ --learning_rate 1e-5 \ --num_epochs 2 \ --remove_prefix_in_ckpt pipe.dit. \ --output_path ./models/train/FLUX.2-klein-4B_full \ --trainable_models dit \ --use_gradient_checkpointing全参训练相比 LoRA 训练多了--tokenizer_path显式指定分词器并以更小的学习率1e-5微调 DiT。脚本后半段还给出了编辑任务Edit的注释示例通过--data_file_keys image,edit_image与--extra_inputs edit_image把编辑图作为额外输入注入训练。训练后验证训练完成后用验证脚本加载 checkpoint 并推理输出对比图。LoRA 验证脚本 validate_lora/FLUX.2-dev.py 的核心逻辑为from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig import torch pipe Flux2ImagePipeline.from_pretrained( torch_dtypetorch.bfloat16, devicecuda, model_configs[ ModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patterntext_encoder/*.safetensors, **vram_config), ModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patterntransformer/*.safetensors, **vram_config), ModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patternvae/diffusion_pytorch_model.safetensors, **vram_config), ], tokenizer_configModelConfig(model_idblack-forest-labs/FLUX.2-dev, origin_file_patterntokenizer/), ) pipe.load_lora(pipe.dit, ./models/train/FLUX.2-dev-LoRA-splited/epoch-4.safetensors) prompt a dog image pipe(prompt, seed0) image.save(image_FLUX.2-dev_lora.jpg)核心只有一行pipe.load_lora(pipe.dit, checkpoint路径)把训练产出的 LoRA 权重注入 DiT然后用常规推理接口出图。全参训练的验证脚本validate_full/FLUX.2-klein-4B.py思路一致区别在于通过ModelConfig直接加载训练产出目录中的模型权重。各模型的验证脚本均已按模型清单列出。高级训练算法FLUX.2 系列还可结合 DiffSynth-Studio 提供的高级训练算法Differential LoRA 训练通过--preset_lora_path/--preset_lora_model把预设 LoRA 合并进基座模型后只学习增量部分FP8 精度训练通过--fp8_models把不参与梯度更新的模型以 FP8 加载显著降低显存占用两阶段拆分训练拆分文本编码与去噪阶段降低峰值显存端到端直接蒸馏对应--task direct_distill与DirectDistillLoss用于把基座模型蒸馏为少步数模型。训练脚本的通用编写规范请参考 模型训练指南更多进阶算法见 训练框架文档目录。小结在 DiffSynth-Studio 中运行 FLUX.2 的完整路径可以概括为三条推理用Flux2ImagePipeline.from_pretrained按text_encoder / transformer / vae / tokenizer四个部分声明模型来源配合vram_config与vram_limit即可在约 10GB 显存上完成文生图并可通过edit_image、input_image、inpaint_mask等参数扩展出图生图、编辑、局部重绘能力模板能力基于klein-base基座 TemplatePipeline组合Template-KleinBase4B-*模板模型实现属性控制 LoRA 的批量合成与组合生成训练以 train.py 为统一入口通过--task、--lora_*、--trainable_models、--use_gradient_checkpointing等参数分别执行数据预处理、LoRA 训练、全参训练与直接蒸馏再用pipe.load_lora或直接加载产出权重完成验证。所有示例脚本均可在 examples/flux2/ 目录下找到完整实现训练/推理过程中如遇显存不足请优先参考 显存管理指南 中推荐的各模型低显存配置。【免费下载链接】DiffSynth-StudioEnjoy the magic of Diffusion models!项目地址: https://gitcode.com/GitHub_Trending/dif/DiffSynth-Studio创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表