[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-artidoro--qlora":3,"tool-artidoro--qlora":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 真正成长为懂上",149489,2,"2026-04-10T11:32:46",[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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[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},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"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":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":75,"owner_email":75,"owner_twitter":77,"owner_website":78,"owner_url":79,"languages":80,"stars":97,"forks":98,"last_commit_at":99,"license":100,"difficulty_score":101,"env_os":102,"env_gpu":103,"env_ram":104,"env_deps":105,"category_tags":114,"github_topics":75,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":115,"updated_at":116,"faqs":117,"releases":147},6304,"artidoro\u002Fqlora","qlora","QLoRA: Efficient Finetuning of Quantized LLMs","QLoRA 是一种高效的大型语言模型（LLM）微调技术，旨在让研究人员和开发者在有限的硬件资源下也能轻松定制强大的 AI 模型。它核心解决了传统微调方法对显存要求极高的问题：以往微调一个 650 亿参数的模型需要多张高端显卡，而 QLoRA 仅需单张 48GB 显存的 GPU 即可完成，且性能几乎无损。\n\n这项技术非常适合希望深入研究大模型、进行垂直领域适配的开发者与科研人员，尤其是那些无法负担昂贵算力集群的个人或小团队。QLoRA 的独特之处在于其创新的内存优化策略：它采用全新的 4 位 NormalFloat 数据类型存储冻结的预训练模型权重，结合“双重量化”技术进一步压缩内存占用，并利用“分页优化器”巧妙管理训练过程中的显存峰值。通过将梯度反向传播至低秩适配器（LoRA），QLoRA 在大幅降低资源门槛的同时，依然保持了全精度微调的效果。基于该技术推出的 Guanaco 模型系列，在多项基准测试中表现优异，甚至接近 ChatGPT 的水平，真正推动了大模型研究的普及化。","\n\n# QLoRA: Efficient Finetuning of Quantized LLMs\n\n| [Paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F2305.14314) | [Adapter Weights](https:\u002F\u002Fhuggingface.co\u002Ftimdettmers) | [Demo](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fuwnlp\u002Fguanaco-playground-tgi) | \n\nThis repo supports the paper \"QLoRA: Efficient Finetuning of Quantized LLMs\", an effort to democratize access to LLM research. \n\n\nQLoRA uses [bitsandbytes](https:\u002F\u002Fgithub.com\u002FTimDettmers\u002Fbitsandbytes) for quantization and is integrated with Hugging Face's [PEFT](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fpeft) and [transformers](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002F) libraries. QLoRA was developed by members of the [University of Washington's UW NLP group](https:\u002F\u002Ftwitter.com\u002Fuwnlp?s=20).\n\n## Updates\n- 7\u002F19\u002F2023 - Added LLaMA 2 example script and updated version requirements\n- 7\u002F18\u002F2023 - Fixed non-frozen embeddings when adding new tokens\n\n## Overview\n\nWe present QLoRA, an efficient finetuning approach that reduces memory usage enough to finetune a 65B parameter model on a single 48GB GPU while preserving full 16-bit finetuning task performance. QLoRA backpropagates gradients through a frozen, 4-bit quantized pretrained language model into Low Rank Adapters (LoRA). Our best model family, which we name Guanaco, outperforms all previous openly released models on the Vicuna benchmark, reaching 99.3% of the performance level of ChatGPT while only requiring 24 hours of finetuning on a single GPU. QLoRA introduces a number of innovations to save memory without sacrificing performance: (a) 4-bit NormalFloat (NF4), a new data type that is information theoretically optimal for normally distributed weights (b) Double Quantization to reduce the average memory footprint by quantizing the quantization constants, and (c) Paged Optimizers to manage memory spikes. We use QLoRA to finetune more than 1,000 models, providing a detailed analysis of instruction following and chatbot performance across 8 instruction datasets, multiple model types (LLaMA, T5), and model scales that would be infeasible to run with regular finetuning (e.g. 33B and 65B parameter models). Our results show that QLoRA finetuning on a small high-quality dataset leads to state-of-the-art results, even when using smaller models than the previous SoTA. We provide a detailed analysis of chatbot performance based on both human and GPT-4 evaluations showing that GPT-4 evaluations are a cheap and reasonable alternative to human evaluation. Furthermore, we find that current chatbot benchmarks are not trustworthy to accurately evaluate the performance levels of chatbots. We release all of our models and code, including CUDA kernels for 4-bit training.\n\n## License and Intended Use\nWe release the resources associated with QLoRA finetuning in this repository under MIT license.\nIn addition, we release the Guanaco model family for base LLaMA model sizes of 7B, 13B, 33B, and 65B. These models are intended for purposes in line with the LLaMA license and require access to the LLaMA models.\n\n## Demo\nGuanaco is a system purely intended for research purposes and could produce problematic outputs.\n\n1. Access the [live demo here](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fuwnlp\u002Fguanaco-playground-tgi). Note this is the 33B model, the 65B model demo will come later.\n\n2. Or host your own Guanaco gradio demo directly in Colab with [this notebook](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17XEqL1JcmVWjHkT-WczdYkJlNINacwG7?usp=sharing). Works with free GPUs for 7B and 13B models.\n\n3. Alternatively, can you distinguish ChatGPT from Guanaco? Give it a try! \nYou can access [the model response Colab here](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1kK6xasHiav9nhiRUJjPMZb4fAED4qRHb?usp=sharing) comparing ChatGPT and Guanaco 65B on Vicuna prompts.\n\n\n## Installation\nTo load models in 4bits with transformers and bitsandbytes, you have to install accelerate and transformers from source and make sure you have the latest version of the bitsandbytes library. After installing PyTorch (follow instructions [here](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F)), you can achieve the above with the following command:\n```bash\npip install -U -r requirements.txt\n```\n\n## Getting Started\nThe `qlora.py` code is a starting point for finetuning and inference on various datasets.\nBasic command for finetuning a baseline model on the Alpaca dataset:\n```bash\npython qlora.py --model_name_or_path \u003Cpath_or_name>\n```\n\nFor models larger than 13B, we recommend adjusting the learning rate:\n```bash\npython qlora.py –learning_rate 0.0001 --model_name_or_path \u003Cpath_or_name>\n```\n\nTo replicate our Guanaco models see below.\n\n### Tutorials and Demonstrations\nHere is [a blog](https:\u002F\u002Fhuggingface.co\u002Fblog\u002F4bit-transformers-bitsandbytes) discussing 4-bit quantization, QLoRA, and how they are integrated in transformers.\n\nYou can host your own gradio Guanaco demo directly in Colab following [this notebook](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17XEqL1JcmVWjHkT-WczdYkJlNINacwG7?usp=sharing). \nIn addition, here are Colab notebooks with examples for inference and finetuning using QLoRA:\n- [Inference notebook](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1ge2F1QSK8Q7h0hn3YKuBCOAS0bK8E0wf?usp=sharing)\n- [Finetuning notebook](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1VoYNfYDKcKRQRor98Zbf2-9VQTtGJ24k?usp=sharing)\n\nOther examples are found under the `examples\u002F` folder. We include a generation getting started example with guanaco at `examples\u002Fguanaco_generate.py`.\n\n### Quantization\nQuantization parameters are controlled from the `BitsandbytesConfig` ([see HF documenation](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Ftransformers\u002Fmain_classes\u002Fquantization#transformers.BitsAndBytesConfig)) as follows:\n- Loading in 4 bits is activated through `load_in_4bit`\n- The datatype used for the linear layer computations with `bnb_4bit_compute_dtype`\n- Nested quantization is activated through `bnb_4bit_use_double_quant`\n- The datatype used for qunatization is specified with `bnb_4bit_quant_type`. Note that there are two supported quantization datatypes `fp4` (four bit float) and `nf4` (normal four bit float). The latter is theoretically optimal for normally distributed weights and we recommend using `nf4`.\n\n```python\n    model = AutoModelForCausalLM.from_pretrained(\n        model_name_or_path='\u002Fname\u002For\u002Fpath\u002Fto\u002Fyour\u002Fmodel',\n        load_in_4bit=True,\n        device_map='auto',\n        max_memory=max_memory,\n        torch_dtype=torch.bfloat16,\n        quantization_config=BitsAndBytesConfig(\n            load_in_4bit=True,\n            bnb_4bit_compute_dtype=torch.bfloat16,\n            bnb_4bit_use_double_quant=True,\n            bnb_4bit_quant_type='nf4'\n        ),\n    )\n```\n\n### Paged Optimizer\nYou can access the paged optimizer with the argument `--optim paged_adamw_32bit`\n\n### Guanaco Finetuning\nYou can select `--dataset oasst1` to load the OpenAssistant dataset that was used to train Guanaco. You can also find it on HF at [timdettmers\u002Fopenassistant-guanaco](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Ftimdettmers\u002Fopenassistant-guanaco).\n\nWe include scripts to reproduce the hyperparameters of Guanaco model training for various sizes at `.\u002Fscripts\u002Ffinetune_guanaco*.sh`. Make sure to adjust `per_device_train_batch_size` and `gradient_accumulation_steps` so that their product is 16 and training fits on your GPUs. \n\n### Using Local Datasets\n\nYou can specify the path to your dataset using the `--dataset` argument. If the `--dataset_format` argument is not set, it will default to the Alpaca format. Here are a few examples:\n\n- Training with an *alpaca* format dataset:\n  ```bash\n  python qlora.py --dataset=\"path\u002Fto\u002Fyour\u002Fdataset\"\n  ```\n- Training with a *self-instruct* format dataset:\n   ```bash\n   python qlora.py --dataset=\"path\u002Fto\u002Fyour\u002Fdataset\" --dataset_format=\"self-instruct\"\n   ```\n\n### Multi GPU\nMulti GPU training and inference work out-of-the-box with Hugging Face's Accelerate. Note that the `per_device_train_batch_size` and `per_device_eval_batch_size` arguments are  global batch sizes unlike what their name suggest.\n\nWhen loading a model for training or inference on multiple GPUs you should pass something like the following to `AutoModelForCausalLM.from_pretrained()`:\n```python\ndevice_map = \"auto\"\nmax_memory = {i: '46000MB' for i in range(torch.cuda.device_count())}\n```\n\n\n## Sample Outputs\nWe provide generations for the models described in the paper for both OA and Vicuna queries in the `eval\u002Fgenerations` folder. These are intended to foster further research on model evaluation and analysis.\n\nCan you distinguish ChatGPT from Guanaco? Give it a try! \nYou can access [the model response Colab here](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1kK6xasHiav9nhiRUJjPMZb4fAED4qRHb?usp=sharing) comparing ChatGPT and Guanaco 65B on Vicuna prompts.\n\n## Evaluation\nWe include scripts adapted from the FastChat repo to automatically evaluate model generations using GPT-4. We include script for comparisons relative to ChatGPT with scores out of 10 as well as \"pairwise comparisons\" with three class labeling (win, loose, or tie). These are found in the `eval` folder.\n\nTo facilitate the replication of our evaluation and future work in this area, we release GPT-4 and human ratings of our systems. These are found under `eval\u002Fratings-human` and `eval\u002Fratings-gpt4`.\n\nMore details can be found at `eval\u002FEVAL_README.md`.\n\n## Known Issues and Limitations\nHere a list of known issues and bugs. If your issue is not reported here, please open a new issue and describe the problem.\n\n1. 4-bit inference is slow. Currently, our 4-bit inference implementation is not yet integrated with the 4-bit matrix multiplication\n2. Resuming a LoRA training run with the Trainer currently not supported by HF.\n3. Currently, using `bnb_4bit_compute_type='fp16'` can lead to instabilities. For 7B LLaMA, only 80% of finetuning runs complete without error. We have solutions, but they are not integrated yet into bitsandbytes.\n4. Make sure that `tokenizer.bos_token_id = 1` to avoid generation issues.\n5. If you get an this [issue](https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F82) (\"illegal memory access\") then you should use a newer HF LLaMA conversion or downgrade your PyTorch version.\n6. Problems with adding new tokens outlined in #214. Embeddings need to be updated and stored\u002Freloaded if you are adding new tokens.\n \n\n\n\n## Citation\n\n```bibtex\n@article{dettmers2023qlora,\n  title={QLoRA: Efficient Finetuning of Quantized LLMs},\n  author={Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},\n  journal={arXiv preprint arXiv:2305.14314},\n  year={2023}\n}\n```\n\n## Acknowledgements\nWe thank the Hugging Face team, in particular Younes Belkada, for their support integrating QLoRA with PEFT and transformers libraries.\nWe also thank Meta for releasing the LLaMA models without which this work would not have been possible.\n\nThis repo builds on the [Stanford Alpaca](https:\u002F\u002Fgithub.com\u002Ftatsu-lab\u002Fstanford_alpaca) and [LMSYS FastChat](https:\u002F\u002Fgithub.com\u002Flm-sys\u002FFastChat) repos.\n","# QLoRA：量化大语言模型的高效微调\n\n| [论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F2305.14314) | [适配器权重](https:\u002F\u002Fhuggingface.co\u002Ftimdettmers) | [演示](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fuwnlp\u002Fguanaco-playground-tgi) | \n\n本仓库支持论文《QLoRA：量化大语言模型的高效微调》，旨在使大语言模型研究更加普及。\n\n\nQLoRA 使用 [bitsandbytes](https:\u002F\u002Fgithub.com\u002FTimDettmers\u002Fbitsandbytes) 进行量化，并与 Hugging Face 的 [PEFT](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fpeft) 和 [transformers](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002F) 库集成。QLoRA 由 [华盛顿大学 NLP 团队](https:\u002F\u002Ftwitter.com\u002Fuwnlp?s=20) 的成员开发。\n\n## 更新\n- 2023年7月19日 - 添加了 LLaMA 2 示例脚本并更新了版本要求\n- 2023年7月18日 - 修复了添加新 token 时未冻结嵌入的问题\n\n## 概述\n\n我们提出了 QLoRA，这是一种高效的微调方法，能够显著降低内存使用量，使得在单块 48GB 显存的 GPU 上即可微调 650 亿参数的模型，同时保持全 16 位精度下的任务性能。QLoRA 通过将梯度反向传播到一个冻结的、4 位量化预训练语言模型中，进而作用于低秩适配器（LoRA）。我们最好的模型系列名为 Guanaco，在 Vicuna 基准测试上超越了所有先前公开发布的模型，达到了 ChatGPT 性能水平的 99.3%，而仅需在单个 GPU 上进行 24 小时的微调。QLoRA 引入了多项创新技术，在不牺牲性能的前提下节省内存：(a) 4 位 NormalFloat (NF4)，一种在信息论上对正态分布权重最优的数据类型；(b) 双重量化，通过量化量化常数来减少平均内存占用；(c) 分页优化器，用于管理内存峰值。我们使用 QLoRA 微调了超过 1,000 个模型，并对 8 个指令数据集、多种模型类型（LLaMA、T5）以及常规微调难以运行的规模（如 330 亿和 650 亿参数模型）下的指令遵循和聊天机器人性能进行了详细分析。我们的结果表明，即使使用比之前最先进模型更小的规模，基于高质量小数据集的 QLoRA 微调也能达到最先进的效果。我们还基于人工评估和 GPT-4 评估对聊天机器人性能进行了详细分析，结果显示 GPT-4 评估是替代人工评估的一种廉价且合理的方式。此外，我们发现当前的聊天机器人基准测试并不足以准确评估聊天机器人的性能水平。我们发布了所有模型和代码，包括用于 4 位训练的 CUDA 内核。\n\n## 许可与用途\n我们在此仓库中以 MIT 许可证发布了与 QLoRA 微调相关的资源。\n此外，我们还发布了 Guanaco 模型家族，适用于 LLaMA 基础模型的 70 亿、130 亿、330 亿和 650 亿参数版本。这些模型的使用应符合 LLaMA 许可证的要求，并需要访问 LLaMA 模型。\n\n## 演示\nGuanaco 是一个纯粹用于研究目的的系统，可能会产生问题输出。\n\n1. 请访问[此处的实时演示](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fuwnlp\u002Fguanaco-playground-tgi)。请注意，这里展示的是 330 亿参数的模型，650 亿参数的模型演示将在稍后推出。\n\n2. 或者，您也可以直接在 Colab 中使用[此笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17XEqL1JcmVWjHkT-WczdYkJlNINacwG7?usp=sharing)托管自己的 Guanaco Gradio 演示。对于 70 亿和 130 亿参数的模型，免费 GPU 即可运行。\n\n3. 或者，您能区分 ChatGPT 和 Guanaco 吗？不妨试一试！您可以访问[此模型响应 Colab](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1kK6xasHiav9nhiRUJjPMZb4fAED4qRHb?usp=sharing)，比较 ChatGPT 和 Guanaco 650 亿参数模型在 Vicuna 提示下的表现。\n\n\n## 安装\n要使用 transformers 和 bitsandbytes 以 4 位加载模型，您需要从源码安装 accelerate 和 transformers，并确保已安装最新版本的 bitsandbytes 库。在安装 PyTorch（请按照[此处](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F)的说明操作）之后，您可以通过以下命令实现上述目标：\n```bash\npip install -U -r requirements.txt\n```\n\n## 快速入门\n`qlora.py` 代码是针对各种数据集进行微调和推理的起点。\n在 Alpaca 数据集上微调基线模型的基本命令如下：\n```bash\npython qlora.py --model_name_or_path \u003C路径或名称>\n```\n\n对于大于 130 亿参数的模型，我们建议调整学习率：\n```bash\npython qlora.py –learning_rate 0.0001 --model_name_or_path \u003C路径或名称>\n```\n\n要复现我们的 Guanaco 模型，请参阅下文。\n\n### 教程与演示\n这里有一篇[博客](https:\u002F\u002Fhuggingface.co\u002Fblog\u002F4bit-transformers-bitsandbytes)，讨论了 4 位量化、QLoRA 以及它们如何集成到 transformers 中。\n\n您可以在 Colab 中按照[此笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F17XEqL1JcmVWjHkT-WczdYkJlNINacwG7?usp=sharing)直接托管自己的 Gradio Guanaco 演示。\n此外，这里还有一些使用 QLoRA 进行推理和微调的 Colab 笔记本：\n- [推理笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1ge2F1QSK8Q7h0hn3YKuBCOAS0bK8E0wf?usp=sharing)\n- [微调笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1VoYNfYDKcKRQRor98Zbf2-9VQTtGJ24k?usp=sharing)\n\n其他示例可在 `examples\u002F` 文件夹中找到。我们在 `examples\u002Fguanaco_generate.py` 中包含了一个使用 guanaco 进行生成的入门示例。\n\n### 量化\n量化参数通过 `BitsandbytesConfig` 控制（[参见 HF 文档](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Ftransformers\u002Fmain_classes\u002Fquantization#transformers.BitsAndBytesConfig)），具体如下：\n- 通过 `load_in_4bit` 激活 4 位加载\n- 使用 `bnb_4bit_compute_dtype` 指定线性层计算所用的数据类型\n- 通过 `bnb_4bit_use_double_quant` 激活嵌套量化\n- 使用 `bnb_4bit_quant_type` 指定量化所用的数据类型。需要注意的是，目前支持两种量化数据类型 `fp4`（四比特浮点数）和 `nf4`（正常四比特浮点数）。后者在理论上对正态分布权重最为优化，我们推荐使用 `nf4`。\n\n```python\n    model = AutoModelForCausalLM.from_pretrained(\n        model_name_or_path='\u002F模型路径或名称',\n        load_in_4bit=True,\n        device_map='auto',\n        max_memory=max_memory,\n        torch_dtype=torch.bfloat16,\n        quantization_config=BitsAndBytesConfig(\n            load_in_4bit=True,\n            bnb_4bit_compute_dtype=torch.bfloat16,\n            bnb_4bit_use_double_quant=True,\n            bnb_4bit_quant_type='nf4'\n        ),\n    )\n```\n\n### 分页优化器\n您可以通过 `--optim paged_adamw_32bit` 参数访问分页优化器。\n\n### Guanaco 微调\n你可以选择 `--dataset oasst1` 来加载用于训练 Guanaco 的 OpenAssistant 数据集。你也可以在 Hugging Face 上找到它，地址是 [timdettmers\u002Fopenassistant-guanaco](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Ftimdettmers\u002Fopenassistant-guanaco)。\n\n我们在 `.\u002Fscripts\u002Ffinetune_guanaco*.sh` 中提供了脚本，用于复现不同规模的 Guanaco 模型训练超参数。请确保调整 `per_device_train_batch_size` 和 `gradient_accumulation_steps`，使它们的乘积为 16，以便训练能够在你的 GPU 上顺利进行。\n\n### 使用本地数据集\n你可以使用 `--dataset` 参数指定数据集的路径。如果未设置 `--dataset_format` 参数，则默认使用 Alpaca 格式。以下是一些示例：\n\n- 使用 *alpaca* 格式的数据集进行训练：\n  ```bash\n  python qlora.py --dataset=\"path\u002Fto\u002Fyour\u002Fdataset\"\n  ```\n- 使用 *self-instruct* 格式的数据集进行训练：\n  ```bash\n  python qlora.py --dataset=\"path\u002Fto\u002Fyour\u002Fdataset\" --dataset_format=\"self-instruct\"\n  ```\n\n### 多 GPU\n多 GPU 训练和推理可以直接通过 Hugging Face 的 Accelerate 库实现。需要注意的是，`per_device_train_batch_size` 和 `per_device_eval_batch_size` 参数实际上是全局批次大小，与名称所暗示的不同。\n\n在多 GPU 上加载模型进行训练或推理时，你应该将类似以下内容传递给 `AutoModelForCausalLM.from_pretrained()`：\n```python\ndevice_map = \"auto\"\nmax_memory = {i: '46000MB' for i in range(torch.cuda.device_count())}\n```\n\n\n## 示例输出\n我们在 `eval\u002Fgenerations` 文件夹中提供了论文中描述的模型针对 OA 和 Vicuna 查询的生成结果。这些结果旨在促进对模型评估和分析的进一步研究。\n\n你能区分 ChatGPT 和 Guanaco 吗？不妨试试！你可以访问[这里的 Colab 笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1kK6xasHiav9nhiRUJjPMZb4fAED4qRHb?usp=sharing)，比较 ChatGPT 和 Guanaco 65B 在 Vicuna 提示下的回答。\n\n## 评估\n我们从 FastChat 仓库中改编了一些脚本，用于使用 GPT-4 自动评估模型的生成结果。我们提供了与 ChatGPT 对比的脚本，评分范围为 0 到 10；还提供了“成对比较”脚本，采用三分类标签（胜、负、平）。这些脚本位于 `eval` 文件夹中。\n\n为了便于复制我们的评估方法以及未来在这方面的研究，我们公开了 GPT-4 和人类对我们系统的评分。这些评分分别位于 `eval\u002Fratings-human` 和 `eval\u002Fratings-gpt4` 文件夹中。\n\n更多详细信息请参阅 `eval\u002FEVAL_README.md`。\n\n## 已知问题与限制\n以下是已知的问题和 bug 列表。如果你遇到的问题未在此列出，请新建一个 issue 并描述问题。\n\n1. 4-bit 推理速度较慢。目前，我们的 4-bit 推理实现尚未与 4-bit 矩阵乘法集成。\n2. 当前 HF 的 Trainer 尚不支持恢复 LoRA 训练任务。\n3. 目前，使用 `bnb_4bit_compute_type='fp16'` 可能会导致不稳定。对于 7B LLaMA 模型，只有 80% 的微调任务能够顺利完成而不会出现错误。我们已经有解决方案，但尚未集成到 bitsandbytes 中。\n4. 请确保 `tokenizer.bos_token_id = 1`，以避免生成问题。\n5. 如果你遇到 [此问题](https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F82)（“非法内存访问”），则应使用更新的 HF LLaMA 转换工具，或降级你的 PyTorch 版本。\n6. 添加新 token 时可能出现问题，详见 #214。如果添加新 token，需要更新并重新存储\u002F加载嵌入层。\n\n \n\n## 引用\n```bibtex\n@article{dettmers2023qlora,\n  title={QLoRA: Efficient Finetuning of Quantized LLMs},\n  author={Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},\n  journal={arXiv preprint arXiv:2305.14314},\n  year={2023}\n}\n```\n\n## 致谢\n我们感谢 Hugging Face 团队，特别是 Younes Belkada，他们在将 QLoRA 与 PEFT 和 transformers 库集成方面给予的支持。我们也感谢 Meta 公司发布了 LLaMA 模型，没有这些模型，这项工作将无法实现。\n\n本仓库基于 [Stanford Alpaca](https:\u002F\u002Fgithub.com\u002Ftatsu-lab\u002Fstanford_alpaca) 和 [LMSYS FastChat](https:\u002F\u002Fgithub.com\u002Flm-sys\u002FFastChat) 两个项目构建。","# QLoRA 快速上手指南\n\nQLoRA 是一种高效的微调方法，允许在单张消费级显卡（如 48GB GPU）上微调高达 650 亿参数的大语言模型。它通过 4 比特量化技术大幅降低显存占用，同时保持全精度微调的性能。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux (推荐 Ubuntu)\n- **GPU**: 支持 CUDA 的 NVIDIA 显卡（显存建议 16GB 以上，微调大模型需 24GB-48GB）\n- **Python**: 3.8 或更高版本\n- **CUDA**: 需安装与 PyTorch 版本匹配的 CUDA 驱动\n\n### 前置依赖\n在开始之前，请确保已安装 PyTorch（带 CUDA 支持）。\n访问 [PyTorch 官网](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F) 获取适合你环境的安装命令。\n\n> **国内加速建议**：\n> 在安装 Python 依赖时，推荐使用清华或阿里镜像源以提升下载速度：\n> ```bash\n> export PIP_INDEX_URL=https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n> ```\n\n## 安装步骤\n\n本项目依赖 `bitsandbytes`、`transformers` 和 `peft` 的最新源码版本。请执行以下命令进行安装：\n\n```bash\n# 克隆仓库（可选，如果只需要运行脚本可跳过，直接安装依赖）\ngit clone https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora.git\ncd qlora\n\n# 安装所有依赖（包含从源码安装的 accelerate 和 transformers）\npip install -U -r requirements.txt\n```\n\n*注意：`bitsandbytes` 需要特定的编译环境，如果遇到编译错误，请确保已安装 `cmake` 和正确的 CUDA Toolkit。*\n\n## 基本使用\n\n### 1. 快速微调示例\n以下命令展示了如何使用 QLoRA 在 Alpaca 数据集上微调一个基座模型。请将 `\u003Cpath_or_name>` 替换为本地模型路径或 Hugging Face 模型 ID（例如 `meta-llama\u002FLlama-2-7b-hf`）。\n\n```bash\npython qlora.py --model_name_or_path \u003Cpath_or_name>\n```\n\n### 2. 大模型微调建议\n对于参数量大于 13B 的模型，建议调整学习率以保证收敛稳定性：\n\n```bash\npython qlora.py --learning_rate 0.0001 --model_name_or_path \u003Cpath_or_name>\n```\n\n### 3. 使用自定义数据集\n你可以指定本地数据集路径进行训练。默认格式为 Alpaca 格式，若使用其他格式（如 self-instruct），需添加对应参数。\n\n**使用 Alpaca 格式数据：**\n```bash\npython qlora.py --dataset=\"path\u002Fto\u002Fyour\u002Fdataset\"\n```\n\n**使用 Self-Instruct 格式数据：**\n```bash\npython qlora.py --dataset=\"path\u002Fto\u002Fyour\u002Fdataset\" --dataset_format=\"self-instruct\"\n```\n\n### 4. 核心代码配置参考\n如果你希望在自己的代码中集成 QLoRA，加载 4 比特模型的核心配置如下：\n\n```python\nfrom transformers import AutoModelForCausalLM, BitsAndBytesConfig\nimport torch\n\nmodel = AutoModelForCausalLM.from_pretrained(\n    model_name_or_path='\u003Cpath_or_name>',\n    load_in_4bit=True,\n    device_map='auto',\n    torch_dtype=torch.bfloat16,\n    quantization_config=BitsAndBytesConfig(\n        load_in_4bit=True,\n        bnb_4bit_compute_dtype=torch.bfloat16,\n        bnb_4bit_use_double_quant=True,\n        bnb_4bit_quant_type='nf4'  # 推荐使用 nf4 以获得最佳效果\n    ),\n)\n```\n\n### 5. 多显卡训练\nQLoRA 原生支持 Hugging Face Accelerate 进行多卡训练。只需在加载模型时设置 `device_map` 和 `max_memory`：\n\n```python\ndevice_map = \"auto\"\nmax_memory = {i: '46000MB' for i in range(torch.cuda.device_count())}\n```\n*注意：在多卡模式下，`per_device_train_batch_size` 实际上指的是全局批大小。*","某初创公司希望基于 650 亿参数的 LLaMA 大模型，利用私有医疗数据微调出一个专业的问诊助手，但团队仅有一张 48GB 显存的消费级显卡。\n\n### 没有 qlora 时\n- **硬件门槛极高**：全量微调 65B 模型通常需要多张 A100 显卡组成的集群，单卡显存完全无法加载模型，更别提训练。\n- **成本难以承受**：为了凑齐算力，必须租用昂贵的云端高性能 GPU 集群，每小时费用高昂，远超初创团队预算。\n- **开发周期漫长**：配置分布式训练环境复杂，且受限于资源排队等待时间，从实验想法到验证结果往往需要数周。\n- **试错成本巨大**：由于资源受限，研究人员不敢轻易尝试不同的数据集或超参数，严重阻碍了模型效果的迭代优化。\n\n### 使用 qlora 后\n- **单卡即可运行**：qlora 通过 4 比特量化技术，成功将 65B 模型压缩至单张 48GB 显卡可承载的范围，直接打破了硬件墙。\n- **大幅降低开销**：无需租赁昂贵集群，仅在本地或低价云实例上即可完成训练，将微调成本降低了数十倍。\n- **快速验证迭代**：环境部署简化，研究人员能在 24 小时内完成一次完整的微调实验，迅速验证医疗数据的适配效果。\n- **性能无损保留**：尽管采用了量化，qlora 仍保持了与 16 比特全量微调相当的任务性能，确保最终生成的问诊回答专业准确。\n\nqlora 让普通开发者也能在消费级硬件上轻松微调超大参数模型，真正实现了大模型研究的民主化。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fartidoro_qlora_69ee62cf.png","artidoro","Artidoro Pagnoni","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fartidoro_1112e7ee.jpg",null,"University of Washington","artidoropagnoni","https:\u002F\u002Fartidoro.github.io\u002F","https:\u002F\u002Fgithub.com\u002Fartidoro",[81,85,89,93],{"name":82,"color":83,"percentage":84},"Jupyter Notebook","#DA5B0B",85.4,{"name":86,"color":87,"percentage":88},"Python","#3572A5",11.9,{"name":90,"color":91,"percentage":92},"Shell","#89e051",1.7,{"name":94,"color":95,"percentage":96},"HTML","#e34c26",1,10864,870,"2026-04-10T09:45:18","MIT",4,"Linux","必需 NVIDIA GPU。支持单卡微调 65B 模型（需 48GB 显存）；7B\u002F13B 模型可在免费 Colab GPU 上运行。依赖 CUDA 内核（通过 bitsandbytes），未明确具体 CUDA 版本，但需支持 4-bit 训练的最新驱动。","未说明（建议根据模型大小配置充足系统内存以配合 Paged Optimizers）",{"notes":106,"python":107,"dependencies":108},"1. 必须从源码安装 transformers 和 accelerate，并确保 bitsandbytes 为最新版本。\n2. 核心功能依赖 4-bit 量化（NF4 数据类型）和双重量化技术。\n3. 多 GPU 训练需通过 Accelerate 配置 device_map 和 max_memory。\n4. 已知问题：使用 fp16 计算类型可能导致不稳定，推荐使用 bfloat16；4-bit 推理速度目前较慢。","未说明",[109,110,111,112,113],"torch","transformers (source)","accelerate (source)","bitsandbytes (latest)","peft",[35,14],"2026-03-27T02:49:30.150509","2026-04-11T00:49:34.039801",[118,123,128,133,138,143],{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},28520,"如何在单张 24GB GPU 上训练 13B 模型而不发生显存溢出（OOM）？","可以通过调整序列长度和批量大小来解决。参考配置如下：将序列长度（seq_len）设置为 1024，有效批量大小（effective batch size）设为 32。具体实现为：实际批次大小（per_device_train_batch_size）设为 4，梯度累积步数（gradient_accumulation_steps）设为 8，并启用梯度检查点（gradient_checkpointing）。这样可以在单张 24GB GPU 上成功运行。","https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F225",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},28521,"遇到报错 'ValueError: You can't train a model that has been loaded in 8-bit precision on a different device...' 该如何解决？","该错误通常是因为模型加载的设备与训练设备不一致。推荐解决方案是使用 `accelerate` 库中的 `PartialState` 来动态设置设备映射。代码示例如下：\n\n```python\nfrom accelerate import PartialState\n\nmodel = AutoModelForCausalLM.from_pretrained(\n    script_args.model_name_or_path,\n    low_cpu_mem_usage=True,\n    torch_dtype=torch.float16,\n    load_in_4bit=True,\n    device_map={\"\": PartialState().process_index},\n)\n```\n\n如果是多卡环境或需要指定特定 GPU，也可以先通过 `export CUDA_VISIBLE_DEVICES=3,4,5` 限制可见显卡，然后在脚本中使用 `torch.cuda.set_device(desired_device)` 设置当前设备，并将 `device_map` 设为对应的索引。","https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F186",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},28522,"如何保存经过 4-bit 量化训练后的模型？直接保存会报错 'NotImplementedError'。","目前直接使用 `save_pretrained` 保存 4-bit 量化模型是不支持的。解决方法是先将 LoRA 权重合并到基础模型中，然后再保存。此外，确保安装最新版本的 `transformers` 库，可以通过以下命令安装开发版以获取最新修复：\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers.git\n```\n\n合并权重的典型操作是在训练结束后调用 `model.merge_and_unload()`（如果使用的是 PEFT 库），然后对合并后的全精度模型进行保存。","https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F114",{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},28523,"QLoRA 训练后的模型能否在 CPU 上进行推理？速度如何？","QLoRA 主要用于 GPU 训练，但推理可以在 CPU 上进行。最佳实践是先在 GPU 上使用 QLoRA 训练，然后将 LoRA 权重合并到完整的基础模型中（使用 `merge_and_unload`），导出为全精度或标准量化格式。之后可以使用专为 CPU 优化的推理引擎（如 `llama.cpp`）来加载合并后的模型进行推理。直接在 CPU 上运行未合并的 4-bit QLoRA 模型通常不可行或效率极低。","https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F107",{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},28524,"在使用微调脚本时，发现评估损失（eval loss）发散而不是收敛，这是正常现象吗？","在某些情况下，使用提供的微调脚本（如 `finetune_guanaco_7b.sh`）时观察到评估损失发散而训练损失下降是已知现象。这可能与评估指标的选择有关，项目维护者建议不要过度依赖 MMLU 等特定基准的评估损失来判断过拟合或欠拟合。如果训练损失正常下降，模型通常仍能学到有效特征。建议关注训练损失的趋势，并在自己的验证集上进行实际效果测试，而非仅看脚本默认的评估损失曲线。","https:\u002F\u002Fgithub.com\u002Fartidoro\u002Fqlora\u002Fissues\u002F152",{"id":144,"question_zh":145,"answer_zh":146,"source_url":127},28525,"如何在多卡环境中正确指定 GPU 以避免设备不匹配的错误？","在多卡环境中，建议结合环境变量和代码设置来指定 GPU。首先，在运行脚本前通过命令行设置可见设备，例如：`export CUDA_VISIBLE_DEVICES=3,4,5`。这会让系统将选中的第一张卡视为逻辑上的 'cuda:0'。然后在 Python 脚本中，可以使用 `torch.cuda.set_device(0)` 来确保使用正确的设备。如果在代码中硬编码设备映射，请确保 `device_map` 与当前可见设备的索引一致，或者直接使用 `accelerate.PartialState().local_process_index` 自动适配分布式环境。",[]]