[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-haofanwang--Lora-for-Diffusers":3,"tool-haofanwang--Lora-for-Diffusers":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",146793,2,"2026-04-08T23:32:35",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108111,"2026-04-08T11:23:26",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":79,"owner_twitter":78,"owner_website":80,"owner_url":81,"languages":82,"stars":87,"forks":88,"last_commit_at":89,"license":90,"difficulty_score":10,"env_os":91,"env_gpu":92,"env_ram":91,"env_deps":93,"category_tags":102,"github_topics":103,"view_count":32,"oss_zip_url":78,"oss_zip_packed_at":78,"status":17,"created_at":111,"updated_at":112,"faqs":113,"releases":114},5787,"haofanwang\u002FLora-for-Diffusers","Lora-for-Diffusers","The most easy-to-understand tutorial for using LoRA (Low-Rank Adaptation) within diffusers framework for AI Generation Researchers🔥","Lora-for-Diffusers 是一份专为 AI 生成内容（AIGC）研究者打造的实用教程与代码库，旨在帮助用户在 Diffusers 框架中轻松集成 LoRA（低秩自适应）技术。它解决了社区中大量优质 LoRA 模型（通常以 Safetensors 格式存在于 Huggingface 或 Civitai 平台）难以直接在开发者常用的 Diffusers 环境中加载和使用的痛点，填补了从 WebUI 简易操作到专业代码开发之间的空白。\n\n该资源非常适合希望进行模型微调、风格定制或算法研究的开发者与科研人员。通过寥寥数行代码，用户即可调用预训练的 LoRA 权重，高效地在大型基础模型上训练个性化分支，而无需耗费巨大算力重训整个模型。其核心技术亮点在于清晰阐释了 LoRA 通过分解矩阵来冻结原始权重、仅训练残差参数的原理，并提供了将 .ckpt 或 .safetensors 格式模型转换为 Diffusers 兼容格式的完整脚本流程。此外，该项目还延伸支持 ControlNet 与 T2I-Adapter，为构建更复杂的生成式工作流提供了便捷入口，是让前沿论文技术落地为实际生产力的优","Lora-for-Diffusers 是一份专为 AI 生成内容（AIGC）研究者打造的实用教程与代码库，旨在帮助用户在 Diffusers 框架中轻松集成 LoRA（低秩自适应）技术。它解决了社区中大量优质 LoRA 模型（通常以 Safetensors 格式存在于 Huggingface 或 Civitai 平台）难以直接在开发者常用的 Diffusers 环境中加载和使用的痛点，填补了从 WebUI 简易操作到专业代码开发之间的空白。\n\n该资源非常适合希望进行模型微调、风格定制或算法研究的开发者与科研人员。通过寥寥数行代码，用户即可调用预训练的 LoRA 权重，高效地在大型基础模型上训练个性化分支，而无需耗费巨大算力重训整个模型。其核心技术亮点在于清晰阐释了 LoRA 通过分解矩阵来冻结原始权重、仅训练残差参数的原理，并提供了将 .ckpt 或 .safetensors 格式模型转换为 Diffusers 兼容格式的完整脚本流程。此外，该项目还延伸支持 ControlNet 与 T2I-Adapter，为构建更复杂的生成式工作流提供了便捷入口，是让前沿论文技术落地为实际生产力的优秀桥梁。","# LoRA-for-Diffusers\n\nThis repository provides the simplest tutorial code for AIGC researchers to use Lora in just a few lines. Using this handbook, you can easily play with any Lora model from active communities such as [Huggingface](https:\u002F\u002Fhuggingface.co\u002F) and [cititai](https:\u002F\u002Fcivitai.com\u002F).\n\nNow, we also support [ControlNet-for-Diffusers](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FControlNet-for-Diffusers), [T2I-Adapter-for-Diffusers](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FT2I-Adapter-for-Diffusers).\n\n# Background\n## What is Lora?\nLow-Rank Adaptation of Large Language Models ([LoRA](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FLoRA)) is developed by Microsoft to reduce the number of trainable parameters by learning pairs of rank-decompostion matrices while freezing the original weights. Lora attemptes to fine-tune the \"residual\" of the model instead of the entire model: i.e., train the $\\Delta W$ instead of $W$.\n\n$$\nW' = W + \\Delta W\n$$\n\nWhere $\\Delta W$ can be further decomposed into low-rank matrices : $\\Delta W = A B^T $, where $A, \\in \\mathbb{R}^{n \\times d}, B \\in \\mathbb{R}^{m \\times d}, d \u003C\u003C n$.\nThis is the key idea of LoRA. We can then fine-tune $A$ and $B$ instead of $W$. In the end, you get an insanely small model as $A$ and $B$ are much smaller than $W$.\n\nThis training trick is quite useful for fune-tuning customized models on a large general base model. Various text to image models have been developed built on the top of the official [Stable Diffusion](https:\u002F\u002Fhuggingface.co\u002Fstabilityai\u002Fstable-diffusion-2-1). Now, with Lora, you can efficiently train your own model with much less resources.\n\n## What is Safetensors?\nSafetensors is a new simple format for storing tensors safely (as opposed to pickle) released by Hugging Face and that is still fast (zero-copy). For its efficiency, many stable diffusion models, especially Lora models are released in safetensors format. You can find more its advantages from [huggingface\u002Fsafetensors](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fsafetensors) and install it via pip install.\n\n```bash\npip install safetensors\n```\n\n# How to load Lora weights?\n\nIn this tutorial, we show to load or insert pre-trained Lora into diffusers framework. Many interesting projects can be found in [Huggingface](https:\u002F\u002Fhuggingface.co\u002F) and [cititai](https:\u002F\u002Fcivitai.com\u002F), but mostly in [stable-diffusion-webui](https:\u002F\u002Fgithub.com\u002FAUTOMATIC1111\u002Fstable-diffusion-webui) framework, which is not convenient for advanced developers. We highly motivated by [cloneofsimo\u002Flora](https:\u002F\u002Fgithub.com\u002Fcloneofsimo\u002Flora) about loading, merging, and interpolating trained LORAs. We mainly discuss models in safetensors format which is not well compatible with diffusers.\n\n### Full model\n\nA full model includes all modules needed (base model with or without Lora layers), they are usually stored in .ckpt or .safetensors format. We provide two examples below to show you how to use on hand.\n\n- [stabilityai\u002Fstable-diffusion-2-1](https:\u002F\u002Fhuggingface.co\u002Fstabilityai\u002Fstable-diffusion-2-1\u002Ftree\u002Fmain) from Huggingface. \n\n- [dreamshaper](https:\u002F\u002Fcivitai.com\u002Fmodels\u002F4384\u002Fdreamshaper) from Civitai. \n\nYou can download .ckpt or .safetensors file only. Although diffusers does not support loading them directly, they do provide the converting script. First download diffusers to local.\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\n```\n\n```bash\ncd .\u002Fdiffusers\n\n# assume you have downloaded xxx.safetensors, it will out save_dir in diffusers format.\npython .\u002Fscripts\u002Fconvert_original_stable_diffusion_to_diffusers.py --checkpoint_path xxx.safetensors  --dump_path save_dir --from_safetensors\n\n# assume you have downloaded xxx.ckpt, it will out save_dir in diffusers format.\npython .\u002Fscripts\u002Fconvert_original_stable_diffusion_to_diffusers.py --checkpoint_path xxx.ckpt  --dump_path save_dir\n```\n\nThen, you can load the model\n```bash\nfrom diffusers import StableDiffusionPipeline\n\npipeline = StableDiffusionPipeline.from_pretrained(save_dir,torch_dtype=torch.float32)\n```\n\n### Lora model only\nFor now, diffusers cannot support load weights in Lora (usually in .safetensor format) . Here we show our attempts in an inelegant style. We also provide one example.\n\n- [one-piece-wano-saga-style-lora](https:\u002F\u002Fcivitai.com\u002Fmodels\u002F4219\u002Fone-piece-wano-saga-style-lora)\n\nNote that the size of file is much smaller than full model, as it only contains extra Lora weights. In the case, we have to load the base model. It is also fine to just load stable-diffusion 1.5 as base, but to get satisfied results, it is recommanded to download suggested base model.\n\nOur method is very straightforward: take out weight from .safetensor, and merge lora weight into a diffusers supported weight. We don't convert .safetensor into other format, we update the weight of base model instead.\n\nOur script should work fine with most of models from [Huggingface](https:\u002F\u002Fhuggingface.co\u002F) and [cititai](https:\u002F\u002Fcivitai.com\u002F), if not, you can also modify the code on your own. Believe me, it is really simple and you can make it.\n\n```bash\n# the default mergering ratio is 0.75, you can manually set it\npython convert_lora_safetensor_to_diffusers.py\n```\n\nWe have made a PR for diffusers on this [issue](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fpull\u002F2403), where we further warp the convering function so that it is more flexible. You can directly check it if you cannot wait. It shall be merged into diffusers soon!\n\n# How to train your Lora?\n\nDiffusers has provide a simple [train_text_to_image_lora.py](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Ftree\u002Fmain\u002Fexamples\u002Ftext_to_image) to train your on Lora model. Please follow its instruction to install requirements.\n\n```bash\nexport MODEL_NAME=\"CompVis\u002Fstable-diffusion-v1-4\"\nexport DATASET_NAME=\"lambdalabs\u002Fpokemon-blip-captions\"\n\naccelerate launch --mixed_precision=\"fp16\" train_text_to_image_lora.py \\\n  --pretrained_model_name_or_path=$MODEL_NAME \\\n  --dataset_name=$DATASET_NAME --caption_column=\"text\" \\\n  --resolution=512 --random_flip \\\n  --train_batch_size=1 \\\n  --num_train_epochs=100 --checkpointing_steps=5000 \\\n  --learning_rate=1e-04 --lr_scheduler=\"constant\" --lr_warmup_steps=0 \\\n  --seed=42 \\\n  --output_dir=\"sd-pokemon-model-lora\" \\\n  --validation_prompt=\"cute dragon creature\" --report_to=\"wandb\"\n```\n\nOnce you have trained a model using above command, the inference can be done simply using the StableDiffusionPipeline after loading the trained LoRA weights. You need to pass the output_dir for loading the LoRA weights which, in this case, is sd-pokemon-model-lora.\n\n```bash\nimport torch\nfrom diffusers import StableDiffusionPipeline\n\nmodel_path = \"your_path\u002Fsd-model-finetuned-lora-t4\"\npipe = StableDiffusionPipeline.from_pretrained(\"CompVis\u002Fstable-diffusion-v1-4\", torch_dtype=torch.float16)\npipe.unet.load_attn_procs(model_path)\npipe.to(\"cuda\")\n\nprompt = \"A pokemon with green eyes and red legs.\"\nimage = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]\nimage.save(\"pokemon.png\")\n```\n\nFor now, diffusers only supports train LoRA for UNet. We have supported and made a [PR](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fpull\u002F2479), if you need it, please check with our PR or open an issue.\n\n## Train LoRA with ColossalAI framework\n\n[ColossalAI](https:\u002F\u002Fgithub.com\u002Fhpcaitech\u002FColossalAI) supports LoRA already. We only need modify a few lines on the top of [train_dreambooth_colossalai.py](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fresearch_projects\u002Fcolossalai\u002Ftrain_dreambooth_colossalai.py). This example is for dreambooth, but you can easily adopt it regular text to image training. The generated LoRA weights are only for attention layers in UNet. If you want to support text encoder too, please use acceletate framework in diffusers, as ColossalAI does not support multiple models yet.\n\n```bash\nfrom diffusers.loaders import AttnProcsLayers\nfrom diffusers.models.cross_attention import LoRACrossAttnProcessor\n\n# attention here! It is necessaray to init unet under ColoInitContext, not just lora layers\nwith ColoInitContext(device=get_current_device()):\n        \n    unet = UNet2DConditionModel.from_pretrained(\n        args.pretrained_model_name_or_path, \n        subfolder=\"unet\", \n        revision=args.revision, \n        low_cpu_mem_usage=False\n    )\n    unet.requires_grad_(False)\n\n    # Set correct lora layers\n    lora_attn_procs = {}\n    for name in unet.attn_processors.keys():\n        cross_attention_dim = None if name.endswith(\"attn1.processor\") else unet.config.cross_attention_dim\n        if name.startswith(\"mid_block\"):\n            hidden_size = unet.config.block_out_channels[-1]\n        elif name.startswith(\"up_blocks\"):\n            block_id = int(name[len(\"up_blocks.\")])\n            hidden_size = list(reversed(unet.config.block_out_channels))[block_id]\n        elif name.startswith(\"down_blocks\"):\n            block_id = int(name[len(\"down_blocks.\")])\n            hidden_size = unet.config.block_out_channels[block_id]\n\n        lora_attn_procs[name] = LoRACrossAttnProcessor(\n            hidden_size=hidden_size, cross_attention_dim=cross_attention_dim\n        )\n\n    unet.set_attn_processor(lora_attn_procs)\n    lora_layers = AttnProcsLayers(unet.attn_processors)\n\n# DDP\nunet = gemini_zero_dpp(unet, args.placement)\n\n# config optimizer for colossalai zero, set initial_scale to large value to avoid underflow\noptimizer = GeminiAdamOptimizer(unet, \n                                lr=args.learning_rate, \n                                betas=(args.adam_beta1, args.adam_beta2),\n                                weight_decay=args.adam_weight_decay,\n                                eps=args.adam_epsilon,\n                                initial_scale=2**16, \n                                clipping_norm=args.max_grad_norm)\n```\n\nHere we go, the only thing is the initialization way of UNet. To save LoRA weights only,\n\n```bash\ntorch_unet = get_static_torch_model(unet)\nif gpc.get_local_rank(ParallelMode.DATA) == 0:\n    torch_unet = torch_unet.to(torch.float32)\n    torch_unet.save_attn_procs(save_path)\n```\n\nThen, do inference\n\n```bash\nfrom diffusers import StableDiffusionPipeline\nimport torch\n\nmodel_path = \"sd-model-finetuned-lora\"\npipe = StableDiffusionPipeline.from_pretrained(\"CompVis\u002Fstable-diffusion-v1-4\", torch_dtype=torch.float16)\npipe.unet.load_attn_procs(model_path)\npipe.to(\"cuda\")\n\nprompt = \"A pokemon with green eyes and red legs.\"\nimage = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]\nimage.save(\"pokemon.png\")\n```\n\nYou may find that the generated LoRA weight is only about 3MB size, this is because of the default setting. To increase the size, you can manually set the rank (dimension for low rank decomposition) for LoRA layers.\n\n```bash\nlora_attn_procs[name] = LoRACrossAttnProcessor(hidden_size=hidden_size, cross_attention_dim=cross_attention_dim, rank=128)\n```\n\nThen, the LoRA weights will be about 100-200MB size. Be aware that LoRA layers are easy to overfit, generally speaking, it should be enough to train only 100 - 2000 steps on small datasets (less than 1K images) with batch size = 64.\n\n# Q&A\n(1) Can I manually adjust the weight of LoRA when merging?\n\nYes, [the alpha](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FLora-for-Diffusers\u002Fblob\u002F22a058bbf060548539658f078c2439b1eeb76730\u002Fconvert_lora_safetensor_to_diffusers.py#L26) here is the weight for LoRA. We have submitted a PR to diffusers where we provide the flexible warpped function.\n\n(2) Can I only convert LoRA (.safetensors) into other formats that diffusers supported?\n\nYou can but we don't suggest, see [this issues](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FLora-for-Diffusers\u002Fissues\u002F1). There are many limitations. For example, our script cannot generalize to all .safetensors because some of them have different naming. Besides, current diffusers framework only supports adding LoRA into UNet's attention layers, while many .safetensors from civitai contain LoRA weights for other modules like text encoder. But [LoRA for text encoder](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002Fpull\u002F21770) should be supported soon.\n\n(3) Can I mix more than one LoRA model?\n\nYes, the only thing is to merge twice. But please carefully set the alpha (weight of LoRA), model degrades if alpha is too large.\n\n(4) What's the motivation of this project?\n\nWe find there are many incredible models in civitai platform, but most of LoRA weights are in safetensors format, which is not convenient for diffusers users. Thus, we write a converting script so that you can use these LoRAs in diffusers. Be aware that we are not target for stable-diffusion-webui, which is already very mature but has totally different API as diffusers.\n","# LoRA-for-Diffusers\n\n本仓库为 AIGC 研究者提供了最简明的教程代码，只需几行即可在 Diffusers 中使用 LoRA。借助本手册，您可以轻松试用来自活跃社区（如 [Huggingface](https:\u002F\u002Fhuggingface.co\u002F) 和 [civitai](https:\u002F\u002Fcivitai.com\u002F)）的任何 LoRA 模型。\n\n目前，我们还支持 [ControlNet-for-Diffusers](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FControlNet-for-Diffusers) 和 [T2I-Adapter-for-Diffusers](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FT2I-Adapter-for-Diffusers)。\n\n# 背景\n## 什么是 LoRA？\n大型语言模型的低秩适应（[LoRA](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FLoRA)）由微软开发，旨在通过学习一对秩分解矩阵并冻结原始权重，从而减少可训练参数的数量。LoRA 的核心思想是微调模型的“残差”部分，而非整个模型：即训练 $\\Delta W$ 而不是 $W$。\n\n$$\nW' = W + \\Delta W\n$$\n\n其中，$\\Delta W$ 可进一步分解为低秩矩阵：$\\Delta W = A B^T$，这里 $A \\in \\mathbb{R}^{n \\times d}$，$B \\in \\mathbb{R}^{m \\times d}$，且 $d \u003C\u003C n$。这就是 LoRA 的关键所在。我们只需微调 $A$ 和 $B$，而无需更新 $W$，最终得到一个规模极小的模型，因为 $A$ 和 $B$ 显然比 $W$ 小得多。\n\n这种训练技巧对于在大型通用基础模型上微调定制化模型非常有用。许多文生图模型都是基于官方的 [Stable Diffusion](https:\u002F\u002Fhuggingface.co\u002Fstabilityai\u002Fstable-diffusion-2-1) 构建的。现在，借助 LoRA，您可以用更少的资源高效地训练自己的模型。\n\n## 什么是 Safetensors？\nSafetensors 是 Hugging Face 推出的一种新型简单格式，用于安全地存储张量（与 pickle 不同），同时保持高效（零拷贝）。由于其高效性，许多稳定扩散模型，尤其是 LoRA 模型，都以 Safetensors 格式发布。您可以在 [huggingface\u002Fsafetensors](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fsafetensors) 中了解更多优势，并通过 pip 安装：\n\n```bash\npip install safetensors\n```\n\n# 如何加载 LoRA 权重？\n\n在本教程中，我们将展示如何将预训练的 LoRA 加载或插入到 Diffusers 框架中。许多有趣的项目可以在 [Huggingface](https:\u002F\u002Fhuggingface.co\u002F) 和 [civitai](https:\u002F\u002Fcivitai.com\u002F) 上找到，但它们大多基于 [stable-diffusion-webui](https:\u002F\u002Fgithub.com\u002FAUTOMATIC1111\u002Fstable-diffusion-webui) 框架，这对高级开发者来说并不方便。我们深受 [cloneofsimo\u002Flora](https:\u002F\u002Fgithub.com\u002Fcloneofsimo\u002Flora) 的启发，该库专注于加载、合并和插值训练好的 LoRA 模型。我们主要讨论的是 Safetensors 格式的模型，这些模型目前与 Diffusers 的兼容性尚不理想。\n\n### 完整模型\n\n完整模型包含所有必要的模块（带有或不带 LoRA 层的基础模型），通常以 .ckpt 或 .safetensors 格式存储。下面我们提供两个示例，演示如何使用。\n\n- Hugging Face 上的 [stabilityai\u002Fstable-diffusion-2-1](https:\u002F\u002Fhuggingface.co\u002Fstabilityai\u002Fstable-diffusion-2-1\u002Ftree\u002Fmain)。\n\n- Civitai 上的 [dreamshaper](https:\u002F\u002Fcivitai.com\u002Fmodels\u002F4384\u002Fdreamshaper)。\n\n您可以仅下载 .ckpt 或 .safetensors 文件。尽管 Diffusers 目前不支持直接加载这些文件，但它们提供了转换脚本。首先将 Diffusers 克隆到本地：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\n```\n\n```bash\ncd .\u002Fdiffusers\n\n# 假设您已下载 xxx.safetensors 文件，它会将其转换为 Diffusers 格式的 save_dir。\npython .\u002Fscripts\u002Fconvert_original_stable_diffusion_to_diffusers.py --checkpoint_path xxx.safetensors  --dump_path save_dir --from_safetensors\n\n# 假设您已下载 xxx.ckpt 文件，它会将其转换为 Diffusers 格式的 save_dir。\npython .\u002Fscripts\u002Fconvert_original_stable_diffusion_to_diffusers.py --checkpoint_path xxx.ckpt  --dump_path save_dir\n```\n\n然后，您可以加载该模型：\n\n```bash\nfrom diffusers import StableDiffusionPipeline\n\npipeline = StableDiffusionPipeline.from_pretrained(save_dir,torch_dtype=torch.float32)\n```\n\n### 仅 LoRA 模型\n目前，Diffusers 尚不支持直接加载 LoRA 权重（通常为 .safetensors 格式）。在此，我们以一种不太优雅的方式进行了尝试，并提供了一个示例。\n\n- [one-piece-wano-saga-style-lora](https:\u002F\u002Fcivitai.com\u002Fmodels\u002F4219\u002Fone-piece-wano-saga-style-lora)\n\n请注意，此类文件的大小远小于完整模型，因为它仅包含额外的 LoRA 权重。在这种情况下，我们需要先加载基础模型。虽然也可以直接使用 stable-diffusion 1.5 作为基础，但为了获得满意的效果，建议下载推荐的基础模型。\n\n我们的方法非常直接：从 .safetensors 文件中提取权重，并将 LoRA 权重合并到 Diffusers 支持的权重中。我们并未将 .safetensors 转换为其他格式，而是直接更新基础模型的权重。\n\n我们的脚本应能适用于大多数来自 [Huggingface](https:\u002F\u002Fhuggingface.co\u002F) 和 [civitai](https:\u002F\u002Fcivitai.com\u002F) 的模型；如果遇到问题，您也可以自行修改代码。相信我，这真的很简单，您完全可以做到。\n\n```bash\n# 默认合并比例为 0.75，您也可以手动设置\npython convert_lora_safetensor_to_diffusers.py\n```\n\n我们已针对此问题向 Diffusers 提交了 PR [issue](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fpull\u002F2403)，并在其中进一步封装了转换函数，使其更加灵活。如果您等不及，可以直接查看该 PR。预计很快就会被合并到 Diffusers 中！\n\n# 如何训练你的LoRA？\n\nDiffusers 提供了一个简单的 [train_text_to_image_lora.py](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Ftree\u002Fmain\u002Fexamples\u002Ftext_to_image) 脚本，用于训练你自己的 LoRA 模型。请按照其说明安装所需的依赖项。\n\n```bash\nexport MODEL_NAME=\"CompVis\u002Fstable-diffusion-v1-4\"\nexport DATASET_NAME=\"lambdalabs\u002Fpokemon-blip-captions\"\n\naccelerate launch --mixed_precision=\"fp16\" train_text_to_image_lora.py \\\n  --pretrained_model_name_or_path=$MODEL_NAME \\\n  --dataset_name=$DATASET_NAME --caption_column=\"text\" \\\n  --resolution=512 --random_flip \\\n  --train_batch_size=1 \\\n  --num_train_epochs=100 --checkpointing_steps=5000 \\\n  --learning_rate=1e-04 --lr_scheduler=\"constant\" --lr_warmup_steps=0 \\\n  --seed=42 \\\n  --output_dir=\"sd-pokemon-model-lora\" \\\n  --validation_prompt=\"cute dragon creature\" --report_to=\"wandb\"\n```\n\n使用上述命令训练好模型后，只需加载训练好的 LoRA 权重，即可通过 StableDiffusionPipeline 进行推理。你需要指定 `output_dir` 来加载 LoRA 权重，在本例中为 `sd-pokemon-model-lora`。\n\n```bash\nimport torch\nfrom diffusers import StableDiffusionPipeline\n\nmodel_path = \"your_path\u002Fsd-model-finetuned-lora-t4\"\npipe = StableDiffusionPipeline.from_pretrained(\"CompVis\u002Fstable-diffusion-v1-4\", torch_dtype=torch.float16)\npipe.unet.load_attn_procs(model_path)\npipe.to(\"cuda\")\n\nprompt = \"A pokemon with green eyes and red legs.\"\nimage = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]\nimage.save(\"pokemon.png\")\n```\n\n目前，Diffusers 仅支持为 UNet 训练 LoRA。我们已经提交了一个 [PR](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fpull\u002F2479)，如果需要的话，请查看该 PR 或者提交一个问题。\n\n## 使用 ColossalAI 框架训练 LoRA\n\n[ColossalAI](https:\u002F\u002Fgithub.com\u002Fhpcaitech\u002FColossalAI) 已经支持 LoRA。我们只需要在 [train_dreambooth_colossalai.py](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\u002Fblob\u002Fmain\u002Fexamples\u002Fresearch_projects\u002Fcolossalai\u002Ftrain_dreambooth_colossalai.py) 的顶部修改几行代码即可。这个示例是针对 DreamBooth 的，但你可以轻松地将其应用于常规的文本到图像训练。生成的 LoRA 权重仅适用于 UNet 中的注意力层。如果你也希望支持文本编码器，则应使用 Diffusers 中的 accelerate 框架，因为 ColossalAI 目前还不支持多模型。\n\n```bash\nfrom diffusers.loaders import AttnProcsLayers\nfrom diffusers.models.cross_attention import LoRACrossAttnProcessor\n\n# 注意这里！必须在 ColoInitContext 下初始化 UNet，而不仅仅是 LoRA 层\nwith ColoInitContext(device=get_current_device()):\n        \n    unet = UNet2DConditionModel.from_pretrained(\n        args.pretrained_model_name_or_path, \n        subfolder=\"unet\", \n        revision=args.revision, \n        low_cpu_mem_usage=False\n    )\n    unet.requires_grad_(False)\n\n    # 设置正确的 LoRA 层\n    lora_attn_procs = {}\n    for name in unet.attn_processors.keys():\n        cross_attention_dim = None if name.endswith(\"attn1.processor\") else unet.config.cross_attention_dim\n        if name.startswith(\"mid_block\"):\n            hidden_size = unet.config.block_out_channels[-1]\n        elif name.startswith(\"up_blocks\"):\n            block_id = int(name[len(\"up_blocks.\")])\n            hidden_size = list(reversed(unet.config.block_out_channels))[block_id]\n        elif name.startswith(\"down_blocks\"):\n            block_id = int(name[len(\"down_blocks.\")])\n            hidden_size = unet.config.block_out_channels[block_id]\n\n        lora_attn_procs[name] = LoRACrossAttnProcessor(\n            hidden_size=hidden_size, cross_attention_dim=cross_attention_dim\n        )\n\n    unet.set_attn_processor(lora_attn_procs)\n    lora_layers = AttnProcsLayers(unet.attn_processors)\n\n# DDP\nunet = gemini_zero_dpp(unet, args.placement)\n\n# 配置 ColossalAI Zero 的优化器，并将初始缩放系数设为较大值以避免下溢\noptimizer = GeminiAdamOptimizer(unet, \n                                lr=args.learning_rate, \n                                betas=(args.adam_beta1, args.adam_beta2),\n                                weight_decay=args.adam_weight_decay,\n                                eps=args.adam_epsilon,\n                                initial_scale=2**16, \n                                clipping_norm=args.max_grad_norm)\n```\n\n到这里就完成了，唯一需要注意的是 UNet 的初始化方式。为了只保存 LoRA 权重：\n\n```bash\ntorch_unet = get_static_torch_model(unet)\nif gpc.get_local_rank(ParallelMode.DATA) == 0:\n    torch_unet = torch_unet.to(torch.float32)\n    torch_unet.save_attn_procs(save_path)\n```\n\n然后进行推理：\n\n```bash\nfrom diffusers import StableDiffusionPipeline\nimport torch\n\nmodel_path = \"sd-model-finetuned-lora\"\npipe = StableDiffusionPipeline.from_pretrained(\"CompVis\u002Fstable-diffusion-v1-4\", torch_dtype=torch.float16)\npipe.unet.load_attn_procs(model_path)\npipe.to(\"cuda\")\n\nprompt = \"A pokemon with green eyes and red legs.\"\nimage = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]\nimage.save(\"pokemon.png\")\n```\n\n你可能会发现生成的 LoRA 权重只有约 3MB 大小，这是因为默认设置的原因。如果想增大权重文件的大小，可以手动为 LoRA 层设置秩（低秩分解的维度）。\n\n```bash\nlora_attn_procs[name] = LoRACrossAttnProcessor(hidden_size=hidden_size, cross_attention_dim=cross_attention_dim, rank=128)\n```\n\n这样生成的 LoRA 权重就会达到约 100-200MB。需要注意的是，LoRA 层很容易过拟合，通常情况下，在小型数据集（少于 1000 张图片）上以批量大小为 64 进行 100 到 2000 步的训练就足够了。\n\n# 问答\n(1) 在合并 LoRA 时，我可以手动调整它的权重吗？\n\n可以，这里的 [alpha](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FLora-for-Diffusers\u002Fblob\u002F22a058bbf060548539658f078c2439b1eeb76730\u002Fconvert_lora_safetensor_to_diffusers.py#L26) 就是 LoRA 的权重。我们已经向 diffusers 提交了一个 PR，在其中提供了一个灵活的封装函数。\n\n(2) 我是否只能将 LoRA (.safetensors) 转换为 diffusers 支持的其他格式？\n\n理论上可以，但我们不建议这样做，详情请参阅 [这个 issue](https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FLora-for-Diffusers\u002Fissues\u002F1)。这样做存在许多限制。例如，我们的脚本无法通用处理所有 .safetensors 文件，因为有些文件的命名方式不同。此外，目前的 diffusers 框架仅支持将 LoRA 应用到 UNet 的注意力层中，而来自 civitai 的许多 .safetensors 文件包含针对文本编码器等其他模块的 LoRA 权重。不过，[用于文本编码器的 LoRA](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002Fpull\u002F21770) 很快应该就会得到支持。\n\n(3) 我可以混合使用多于一个 LoRA 模型吗？\n\n可以，只需进行两次合并即可。但请注意仔细设置 alpha（LoRA 的权重），如果 alpha 设置得过大，模型性能可能会下降。\n\n(4) 这个项目的初衷是什么？\n\n我们发现 civitai 平台上有很多非常出色的模型，但大多数 LoRA 权重都采用 safetensors 格式，这对 diffusers 用户来说并不方便。因此，我们编写了一个转换脚本，以便您能够在 diffusers 中使用这些 LoRA 模型。需要注意的是，我们的目标并不是 stable-diffusion-webui，后者已经非常成熟，但其 API 与 diffusers 完全不同。","# LoRA-for-Diffusers 快速上手指南\n\n本指南旨在帮助开发者快速在 `diffusers` 框架中加载和使用 LoRA 模型，或训练自定义 LoRA 模型。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux, macOS, Windows (推荐 Linux)\n- **Python**: 3.8+\n- **GPU**: 推荐使用 NVIDIA GPU (需安装 CUDA)，CPU 亦可运行但速度较慢\n\n### 前置依赖\n请确保已安装以下核心库：\n- `torch` (建议版本 1.12+)\n- `diffusers`\n- `transformers`\n- `accelerate`\n- `safetensors` (用于高效加载模型权重)\n\n**国内加速建议**：\n在安装依赖时，推荐使用清华源或阿里源以加快下载速度：\n```bash\npip install torch torchvision torchaudio --index-url https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\npip install diffusers transformers accelerate safetensors -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 安装步骤\n\n1. **克隆项目代码**\n   获取本教程所需的转换脚本：\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Fhaofanwang\u002FLora-for-Diffusers.git\n   cd Lora-for-Diffusers\n   ```\n\n2. **安装 Safetensors**\n   如果尚未安装，请执行：\n   ```bash\n   pip install safetensors\n   ```\n\n3. **准备 Diffusers 转换脚本**\n   若需加载完整的 `.ckpt` 或 `.safetensors` 大模型，需借用 `diffusers` 官方的转换脚本：\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fdiffusers\n   ```\n\n## 基本使用\n\n### 场景一：加载现有的 LoRA 模型 (.safetensors)\n\n大多数社区模型（如 Civitai 上的模型）仅提供 LoRA 权重文件（通常较小），需要配合基础模型使用。\n\n1. **下载基础模型与 LoRA 权重**\n   - 基础模型：推荐 `stable-diffusion-v1-5` 或模型作者指定的基底。\n   - LoRA 文件：例如 `one-piece-wano-saga-style-lora.safetensors`。\n\n2. **合并权重**\n   使用提供的脚本将 LoRA 权重合并到 diffusers 格式中（默认融合比例为 0.75）：\n   ```bash\n   python convert_lora_safetensor_to_diffusers.py\n   ```\n   *注：脚本会自动寻找当前目录下的 safetensors 文件并处理，生成可直接被 diffusers 加载的文件夹。*\n\n3. **推理生成**\n   编写 Python 脚本加载模型并生成图像：\n   ```python\n   import torch\n   from diffusers import StableDiffusionPipeline\n\n   # 替换为你的输出目录路径\n   model_path = \"sd-pokemon-model-lora\" \n   \n   # 加载基础模型\n   pipe = StableDiffusionPipeline.from_pretrained(\"CompVis\u002Fstable-diffusion-v1-4\", torch_dtype=torch.float16)\n   \n   # 加载 LoRA 权重\n   pipe.unet.load_attn_procs(model_path)\n   pipe.to(\"cuda\")\n\n   prompt = \"A pokemon with green eyes and red legs.\"\n   image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]\n   image.save(\"pokemon.png\")\n   ```\n\n### 场景二：训练自定义 LoRA 模型\n\n使用 `diffusers` 官方示例脚本进行训练。\n\n1. **设置环境变量并启动训练**\n   以下示例使用宝可梦数据集训练 LoRA：\n   ```bash\n   export MODEL_NAME=\"CompVis\u002Fstable-diffusion-v1-4\"\n   export DATASET_NAME=\"lambdalabs\u002Fpokemon-blip-captions\"\n\n   accelerate launch --mixed_precision=\"fp16\" train_text_to_image_lora.py \\\n     --pretrained_model_name_or_path=$MODEL_NAME \\\n     --dataset_name=$DATASET_NAME --caption_column=\"text\" \\\n     --resolution=512 --random_flip \\\n     --train_batch_size=1 \\\n     --num_train_epochs=100 --checkpointing_steps=5000 \\\n     --learning_rate=1e-04 --lr_scheduler=\"constant\" --lr_warmup_steps=0 \\\n     --seed=42 \\\n     --output_dir=\"sd-pokemon-model-lora\" \\\n     --validation_prompt=\"cute dragon creature\" --report_to=\"wandb\"\n   ```\n\n2. **使用训练好的模型**\n   训练完成后，使用与“场景一”相同的推理代码，将 `model_path` 指向你的输出目录（如 `sd-pokemon-model-lora`）即可。\n\n### 进阶：使用 ColossalAI 训练\n若需更高效的显存管理，可结合 ColossalAI 框架。只需在训练脚本初始化 UNet 时加入 LoRA 层设置：\n\n```python\nfrom diffusers.loaders import AttnProcsLayers\nfrom diffusers.models.cross_attention import LoRACrossAttnProcessor\n\n# 在 ColoInitContext 下初始化 unet\nwith ColoInitContext(device=get_current_device()):\n    unet = UNet2DConditionModel.from_pretrained(...)\n    unet.requires_grad_(False)\n\n    # 配置 LoRA 层\n    lora_attn_procs = {}\n    for name in unet.attn_processors.keys():\n        cross_attention_dim = None if name.endswith(\"attn1.processor\") else unet.config.cross_attention_dim\n        # ... (根据 block 类型获取 hidden_size 的逻辑) ...\n        lora_attn_procs[name] = LoRACrossAttnProcessor(\n            hidden_size=hidden_size, cross_attention_dim=cross_attention_dim\n        )\n\n    unet.set_attn_processor(lora_attn_procs)\n    lora_layers = AttnProcsLayers(unet.attn_processors)\n```\n训练结束后保存权重：\n```python\ntorch_unet = get_static_torch_model(unet)\nif gpc.get_local_rank(ParallelMode.DATA) == 0:\n    torch_unet = torch_unet.to(torch.float32)\n    torch_unet.save_attn_procs(save_path)\n```","一位 AIGC 研究员希望基于 Civitai 社区流行的 DreamShaper 风格模型，快速微调出一个专属的“赛博朋克城市”生成器，并集成到现有的 Diffusers 研发流程中。\n\n### 没有 Lora-for-Diffusers 时\n- **格式兼容困难**：社区主流模型多为 `.safetensors` 或 `.ckpt` 格式，Diffusers 原生不支持直接加载，需手动编写复杂的转换脚本。\n- **开发门槛高**：缺乏标准教程，研究者需深入阅读源码才能理解如何将 LoRA 权重正确注入到冻结的基础模型中。\n- **资源浪费严重**：若不使用 LoRA 而选择全量微调，需要昂贵的显存资源和漫长的训练时间，难以进行快速迭代。\n- **生态割裂**：Hugging Face 与 Civitai 上的优质模型无法直接在代码项目中复用，导致重复造轮子。\n\n### 使用 Lora-for-Diffusers 后\n- **一键加载模型**：通过提供的转换脚本和加载示例，几行代码即可将 `.safetensors` 格式的 DreamShaper 模型无缝接入 Diffusers 管道。\n- **极简微调流程**：遵循官方最易懂的教程，仅需关注低秩矩阵 $A$ 和 $B$ 的训练，无需改动基础权重，大幅降低代码复杂度。\n- **高效资源利用**：利用 LoRA 技术仅训练少量参数，在消费级显卡上也能快速完成“赛博朋克”风格的定制化训练。\n- **生态无缝融合**：直接调用社区活跃的最新模型，轻松实现不同 LoRA 权重的合并与插值，加速实验验证。\n\nLora-for-Diffusers 通过消除格式壁垒并提供极简代码范式，让研究者能以最低成本灵活驾驭社区海量模型，专注于核心算法创新。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhaofanwang_Lora-for-Diffusers_5ac010a1.png","haofanwang","Frank (Haofan) Wang","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fhaofanwang_0d05f6d4.jpg","I love human more than AI.","Lovart AI",null,"haofanwang.ai@gmail.com","https:\u002F\u002Fhaofanwang.github.io","https:\u002F\u002Fgithub.com\u002Fhaofanwang",[83],{"name":84,"color":85,"percentage":86},"Python","#3572A5",100,824,54,"2026-03-27T17:34:33","MIT","未说明","需要 NVIDIA GPU (代码示例中包含 .to('cuda') 和 fp16 混合精度训练)，具体型号和显存大小未说明",{"notes":94,"python":91,"dependencies":95},"该工具主要用于在 Diffusers 框架中加载、合并或训练 LoRA 模型。支持加载 Huggingface 和 Civitai 上的 .safetensors 格式模型。训练时默认仅支持 UNet 的注意力层，若需训练 Text Encoder 建议使用 accelerate 框架而非 ColossalAI。提供了将原始 .ckpt\u002F.safetensors 模型转换为 Diffusers 格式的脚本。",[96,97,98,99,100,101],"diffusers","torch","accelerate","safetensors","transformers","ColossalAI (可选)",[15,14],[104,96,105,106,107,108,20,109,110],"aigc","fine-tuning","guidebook","lora","stable-diffusion","text-to-image","colossalai","2026-03-27T02:49:30.150509","2026-04-09T12:33:52.040903",[],[]]