From 29e820ce555023ebabbe04802447e7d39f958e1b Mon Sep 17 00:00:00 2001 From: yingda Date: Sat, 8 Feb 2025 05:41:01 +0000 Subject: [PATCH] Update README.md --- README.md | 113 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f266d31..ffcada8 100644 --- a/README.md +++ b/README.md @@ -34,25 +34,110 @@ MajicFlus 模型在发布的同时,多位社区成员基于模型制作的 LoR - 由于该模型是个微调融合模型,对社区大部分的lora都是不完美兼容的,需要降低权重至0.5以下。推荐使用带有majicFlus标志的矩阵模型,搜索关键字majic并筛选f1模型就可以看到全部,现在已有超过50款风格各异的优质模型。 ## 参数推荐 Parameter -Steps: 20~30 -Distilled CFG Scale: 3.5 -CFG : 1 -Diffusion in Low Bits: float8-e4m3fn -Sampling: Euler + simple/beta (for general),DPM2M + SGM uniform (for skin texture),DEIS + DDIM uniform (for casual realistic look) -Vae: flux vae -Clip: clip_l.safetensors and t5xxl_fp8_e4m3fn.safetensors +- Steps: 20~30 +- Distilled CFG Scale: 3.5 +- CFG : 1 +- Diffusion in Low Bits: float8-e4m3fn +- Sampling: Euler + simple/beta (for general),DPM2M + SGM uniform (for skin texture),DEIS + DDIM uniform (for casual realistic look) +- Vae: flux vae +- Clip: clip_l.safetensors and t5xxl_fp8_e4m3fn.safetensors -#### 您可以通过如下git clone命令,或者ModelScope SDK来下载模型 +## 生图 -SDK下载 -```bash -#安装ModelScope -pip install modelscope +本模型可通过[AIGC专区生图](https://www.modelscope.cn/aigc/imageGeneration?tab=advanced&versionId=14497&modelType=Checkpoint&sdVersion=FLUX_1&modelUrl=modelscope%3A%2F%2FMAILAND%2Fmajicflus_v1%3Frevision%3Dv1.0)直接在线使用。也通过ModelScope API-Inference使用(见本页面右侧)。 + +如果要下载模型到本地进行推理生图,**建议使用DiffSynth-Studio** 提供的生图pipeline。 + +### 安装DiffSynth ``` +pip install diffsynth -U +``` + +### 推理生图 + +#### 量化推理(需要至少 14G 显存,且需较大的内存) +推荐方式,能在较小显存下,实现无损生图。 + ```python -#SDK模型下载 +import torch from modelscope import snapshot_download -model_dir = snapshot_download('merjic/majicflus_v1') +from diffsynth import ModelManager, FluxImagePipeline + +# 下载模型 +snapshot_download( + model_id="MAILAND/majicflus_v1", + allow_file_pattern="majicflus_v134.safetensors", + cache_dir="models" +) +snapshot_download( + model_id="black-forest-labs/FLUX.1-dev", + allow_file_pattern=["ae.safetensors", "text_encoder/model.safetensors", "text_encoder_2/*"], + cache_dir="models" +) + +# 设置推理计算精度为 bfloat16 +model_manager = ModelManager(torch_dtype=torch.bfloat16) +# 以 float8 精度加载 DiT 部分 +model_manager.load_models( + ["models/MAILAND/majicflus_v1/majicflus_v134.safetensors"], + torch_dtype=torch.float8_e4m3fn, + device="cpu" +) +# 以 bfloat16 精度加载两个 Text Encoder 和 VAE +model_manager.load_models( + [ + "models/black-forest-labs/FLUX.1-dev/text_encoder/model.safetensors", + "models/black-forest-labs/FLUX.1-dev/text_encoder_2", + "models/black-forest-labs/FLUX.1-dev/ae.safetensors", + ], + torch_dtype=torch.bfloat16, + device="cpu" +) +# 开启量化与显存管理 +pipe = FluxImagePipeline.from_model_manager(model_manager, device="cuda") +pipe.enable_cpu_offload() +pipe.dit.quantize() + +# 生图! +image = pipe(prompt="a beautiful girl", seed=0) +image.save("image.jpg") +``` + +#### 原生精度推理(需要至少 40G 显存) + +```python +import torch +from modelscope import snapshot_download +from diffsynth import ModelManager, FluxImagePipeline + +# 下载模型 +snapshot_download( + model_id="MAILAND/majicflus_v1", + allow_file_pattern="majicflus_v134.safetensors", + cache_dir="models" +) +snapshot_download( + model_id="black-forest-labs/FLUX.1-dev", + allow_file_pattern=["ae.safetensors", "text_encoder/model.safetensors", "text_encoder_2/*"], + cache_dir="models" +) + +# 加载模型 +model_manager = ModelManager( + torch_dtype=torch.bfloat16, + device="cuda", + file_path_list=[ + "models/black-forest-labs/FLUX.1-dev/text_encoder/model.safetensors", + "models/black-forest-labs/FLUX.1-dev/text_encoder_2", + "models/black-forest-labs/FLUX.1-dev/ae.safetensors", + "models/MAILAND/majicflus_v1/majicflus_v134.safetensors", + ] +) +pipe = FluxImagePipeline.from_model_manager(model_manager, device="cuda") + +# 生图! +image = pipe(prompt="a beautiful girl", seed=0) +image.save("image.jpg") ``` Git下载 ```