[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-huggingface--optimum-quanto":3,"tool-huggingface--optimum-quanto":61},[4,18,26,36,44,52],{"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 真正成长为懂上",141543,2,"2026-04-06T11:32:54",[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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107888,"2026-04-06T11:32:50",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":10,"last_commit_at":50,"category_tags":51,"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":53,"name":54,"github_repo":55,"description_zh":56,"stars":57,"difficulty_score":10,"last_commit_at":58,"category_tags":59,"status":17},4292,"Deep-Live-Cam","hacksider\u002FDeep-Live-Cam","Deep-Live-Cam 是一款专注于实时换脸与视频生成的开源工具，用户仅需一张静态照片，即可通过“一键操作”实现摄像头画面的即时变脸或制作深度伪造视频。它有效解决了传统换脸技术流程繁琐、对硬件配置要求极高以及难以实时预览的痛点，让高质量的数字内容创作变得触手可及。\n\n这款工具不仅适合开发者和技术研究人员探索算法边界，更因其极简的操作逻辑（仅需三步：选脸、选摄像头、启动），广泛适用于普通用户、内容创作者、设计师及直播主播。无论是为了动画角色定制、服装展示模特替换，还是制作趣味短视频和直播互动，Deep-Live-Cam 都能提供流畅的支持。\n\n其核心技术亮点在于强大的实时处理能力，支持口型遮罩（Mouth Mask）以保留使用者原始的嘴部动作，确保表情自然精准；同时具备“人脸映射”功能，可同时对画面中的多个主体应用不同面孔。此外，项目内置了严格的内容安全过滤机制，自动拦截涉及裸露、暴力等不当素材，并倡导用户在获得授权及明确标注的前提下合规使用，体现了技术发展与伦理责任的平衡。",88924,"2026-04-06T03:28:53",[14,15,13,60],"视频",{"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":77,"owner_email":77,"owner_twitter":73,"owner_website":78,"owner_url":79,"languages":80,"stars":108,"forks":109,"last_commit_at":110,"license":111,"difficulty_score":32,"env_os":112,"env_gpu":113,"env_ram":114,"env_deps":115,"category_tags":123,"github_topics":124,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":127,"updated_at":128,"faqs":129,"releases":160},4474,"huggingface\u002Foptimum-quanto","optimum-quanto","A pytorch quantization backend for optimum","Optimum Quanto 是专为 Hugging Face Optimum 生态打造的 PyTorch 量化后端，旨在帮助开发者轻松压缩大型 AI 模型。它主要解决了大模型在推理时显存占用高、运行速度慢的难题，通过降低权重和激活值的精度（支持 int2\u002F4\u002F8 及 float8 等格式），在几乎不损失模型准确率的前提下，显著减少内存需求并提升推理效率。\n\n这款工具特别适合需要部署大语言模型（如 Llama 系列）或图像生成模型的 AI 研究人员与工程开发者。其独特亮点在于极高的易用性与兼容性：无需修改模型结构或进行复杂的图追踪，即可在 eager 模式下直接运行；它能自动插入量化算子，并无缝支持从动态到静态量化的完整工作流。此外，Optimum Quanto 针对 CUDA 设备提供了加速矩阵乘法内核，并兼容 PyTorch 原生权重格式及 Safetensors，让模型的量化、保存与加载变得像调用普通 API 一样简单。\n\n需要注意的是，目前该项目已进入维护模式，不再添加重大新功能。对于追求最新特性或生产级高强度需求的用户，官方建议关注 bitsandbytes 或 torchA","Optimum Quanto 是专为 Hugging Face Optimum 生态打造的 PyTorch 量化后端，旨在帮助开发者轻松压缩大型 AI 模型。它主要解决了大模型在推理时显存占用高、运行速度慢的难题，通过降低权重和激活值的精度（支持 int2\u002F4\u002F8 及 float8 等格式），在几乎不损失模型准确率的前提下，显著减少内存需求并提升推理效率。\n\n这款工具特别适合需要部署大语言模型（如 Llama 系列）或图像生成模型的 AI 研究人员与工程开发者。其独特亮点在于极高的易用性与兼容性：无需修改模型结构或进行复杂的图追踪，即可在 eager 模式下直接运行；它能自动插入量化算子，并无缝支持从动态到静态量化的完整工作流。此外，Optimum Quanto 针对 CUDA 设备提供了加速矩阵乘法内核，并兼容 PyTorch 原生权重格式及 Safetensors，让模型的量化、保存与加载变得像调用普通 API 一样简单。\n\n需要注意的是，目前该项目已进入维护模式，不再添加重大新功能。对于追求最新特性或生产级高强度需求的用户，官方建议关注 bitsandbytes 或 torchAO 等活跃项目，但 Optimum Quanto 依然是理解和使用基础量化技术的优秀入门选择。","# Optimum Quanto\n\n> This project is currently in maintenance mode. We accept pull requests only for minor bug fixes, documentation improvements, and other maintenance tasks. Major new features or breaking changes are unlikely to be merged. For production-ready quantization features or active development, consider alternative projects such as [bitsandbytes](https:\u002F\u002Fgithub.com\u002Fbitsandbytes-foundation\u002Fbitsandbytes) or [torchAO](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fao).\n\n🤗 Optimum Quanto is a pytorch quantization backend for [optimum](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Foptimum\u002Fen\u002Findex).\n\nIt has been designed with versatility and simplicity in mind:\n\n- all features are available in eager mode (works with non-traceable models),\n- quantized models can be placed on any device (including CUDA and MPS),\n- automatically inserts quantization and dequantization stubs,\n- automatically inserts quantized functional operations,\n- automatically inserts quantized modules (see below the list of supported modules),\n- provides a seamless workflow from a float model to a dynamic to a static quantized model,\n- serialization compatible with pytorch `weight_only` and 🤗 `safetensors`,\n- accelerated matrix multiplications on CUDA devices (int8-int8, fp16-int4, bf16-int8, bf16-int4),\n- supports int2, int4, int8 and float8 weights,\n- supports int8 and float8 activations.\n\nFeatures yet to be implemented:\n\n- dynamic activations smoothing,\n- kernels for all mixed matrix multiplications on all devices,\n- compatibility with [torch compiler](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Ftorch.compiler.html) (aka dynamo).\n\n## Performances\n\nIn a nutshell:\n\n- accuracy: models compiled with `int8`\u002F`float8` weights and `float8` activations are very close to the full-precision models,\n- latency: whenever optimized kernels are available, the inference of quantized model is comparable with the full-precision models when quantizing only the model weights,\n- device memory: approximately divided by float bits \u002F integer bits.\n\nThe paragraph below is just an example. Please refer to the `bench` folder for detailed results per use-case of model.\n\n### meta-llama\u002FMeta-Llama-3.1-8B\n\n\u003Cdiv class=\"row\">\u003Ccenter>\n  \u003Cdiv class=\"column\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_optimum-quanto_readme_ec32b47d373c.png\" alt=\"meta-llama\u002FMeta-Llama-3.1-8B WikiText perplexity\">\n  \u003C\u002Fdiv>\n \u003C\u002Fcenter>\n\u003C\u002Fdiv>\n\n\u003Cdiv class=\"row\">\u003Ccenter>\n  \u003Cdiv class=\"column\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_optimum-quanto_readme_683720c12b24.png\" alt=\"meta-llama\u002FMeta-Llama-3.1-8B Latency\">\n  \u003C\u002Fdiv>\n \u003C\u002Fcenter>\n\u003C\u002Fdiv>\n\n## Installation\n\nOptimum Quanto is available as a pip package.\n\n```sh\npip install optimum-quanto\n```\n\n## Quantization workflow for Hugging Face models\n\n`optimum-quanto` provides helper classes to quantize, save and reload Hugging Face quantized models.\n\n### LLM models\n\nThe first step is to quantize the model\n\n```python\nfrom transformers import AutoModelForCausalLM\nfrom optimum.quanto import QuantizedModelForCausalLM, qint4\n\nmodel = AutoModelForCausalLM.from_pretrained('meta-llama\u002FMeta-Llama-3-8B')\nqmodel = QuantizedModelForCausalLM.quantize(model, weights=qint4, exclude='lm_head')\n```\n\nNote: the model quantized weights will be frozen. If you want to keep them unfrozen to train them you need to use `optimum.quanto.quantize` directly.\n\nThe quantized model can be saved using `save_pretrained`:\n\n```python\nqmodel.save_pretrained('.\u002FLlama-3-8B-quantized')\n```\n\nIt can later be reloaded using `from_pretrained`:\n\n```python\nfrom optimum.quanto import QuantizedModelForCausalLM\n\nqmodel = QuantizedModelForCausalLM.from_pretrained('Llama-3-8B-quantized')\n```\n\n### Diffusers models\n\nYou can quantize any of the submodels inside a diffusers pipeline and seamlessly include them later in another pipeline.\n\nHere we quantize the `transformer` of a `Pixart` pipeline.\n\n```python\nfrom diffusers import PixArtTransformer2DModel\nfrom optimum.quanto import QuantizedPixArtTransformer2DModel, qfloat8\n\nmodel = PixArtTransformer2DModel.from_pretrained(\"PixArt-alpha\u002FPixArt-Sigma-XL-2-1024-MS\", subfolder=\"transformer\")\nqmodel = QuantizedPixArtTransformer2DModel.quantize(model, weights=qfloat8)\nqmodel.save_pretrained(\".\u002Fpixart-sigma-fp8\")\n```\n\nLater, we can reload the quantized model and recreate the pipeline:\n\n```python\nfrom diffusers import PixArtTransformer2DModel\nfrom optimum.quanto import QuantizedPixArtTransformer2DModel\n\ntransformer = QuantizedPixArtTransformer2DModel.from_pretrained(\".\u002Fpixart-sigma-fp8\")\ntransformer.to(device=\"cuda\")\npipe = PixArtSigmaPipeline.from_pretrained(\n  \"PixArt-alpha\u002FPixArt-Sigma-XL-2-1024-MS\",\n  transformer=None,\n  torch_dtype=torch.float16,\n).to(\"cuda\")\npipe.transformer = transformer\n```\n\n## Quantization workflow for vanilla pytorch models (low-level API)\n\nOne thing to keep in mind when using the low-level quanto API is that by default models\nweights are dynamically quantized: an explicit call must be made to 'freeze' the quantized weights.\n\nA typical quantization workflow would consist of the following steps:\n\n**1. Quantize**\n\nThe first step converts a standard float model into a dynamically quantized model.\n\n```python\nfrom optimum.quanto import quantize, qint8\n\nquantize(model, weights=qint8, activations=qint8)\n```\n\nAt this stage, only the inference of the model is modified to dynamically quantize the weights.\n\n**2. Calibrate (optional if activations are not quantized)**\n\nQuanto supports a calibration mode that allows to record the activation ranges while passing representative samples through the quantized model.\n\n```python\nfrom optimum.quanto import Calibration\n\nwith Calibration(momentum=0.9):\n    model(samples)\n```\n\nThis automatically activates the quantization of the activations in the quantized modules.\n\n\n**3. Tune, aka Quantization-Aware-Training (optional)**\n\nIf the performance of the model degrades too much, one can tune it for a few epochs to recover the float model performance.\n\n```python\nimport torch\n\nmodel.train()\nfor batch_idx, (data, target) in enumerate(train_loader):\n    data, target = data.to(device), target.to(device)\n    optimizer.zero_grad()\n    output = model(data).dequantize()\n    loss = torch.nn.functional.nll_loss(output, target)\n    loss.backward()\n    optimizer.step()\n```\n\n**4. Freeze integer weights**\n\nWhen freezing a model, its float weights are replaced by quantized integer weights.\n\n```python\nfrom optimum.quanto import freeze\n\nfreeze(model)\n```\n\n**5. Serialize quantized model**\n\nQuantized models weights can be serialized to a `state_dict`, and saved to a file.\nBoth `pickle` and `safetensors` (recommended) are supported.\n\n```python\nfrom safetensors.torch import save_file\n\nsave_file(model.state_dict(), 'model.safetensors')\n```\n\nIn order to be able to reload these weights, you also need to store the quantized\nmodel quantization map.\n\n```python\nimport json\n\nfrom optimum.quanto import quantization_map\n\nwith open('quantization_map.json', 'w') as f:\n  json.dump(quantization_map(model), f)\n```\n\n**5. Reload a quantized model**\n\nA serialized quantized model can be reloaded from a `state_dict` and a `quantization_map` using the `requantize` helper.\nNote that you need first to instantiate an empty model.\n\n```python\nimport json\n\nfrom safetensors.torch import load_file\nfrom optimum.quanto import requantize\n\nstate_dict = load_file('model.safetensors')\nwith open('quantization_map.json', 'r') as f:\n  quantization_map = json.load(f)\n\n# Create an empty model from your modeling code and requantize it\nwith torch.device('meta'):\n  new_model = ...\nrequantize(new_model, state_dict, quantization_map, device=torch.device('cuda'))\n```\n\nPlease refer to the [examples](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fquanto\u002Ftree\u002Fmain\u002Fexamples) for instantiations of that workflow.\n\n\n## Design overview\n\n### Tensors\n\nAt the heart of quanto is a Tensor subclass that corresponds to:\n- the projection of a source Tensor into the optimal range for a given destination type,\n- the mapping of projected values to the destination type.\n\nFor floating-point destination types, the mapping is done by the native pytorch cast (i.e. `Tensor.to()`).\n\nFor integer destination types, the mapping is a simple rounding operation (i.e. `torch.round()`).\n\nThe goal of the projection is to increase the accuracy of the conversion by minimizing the number of:\n- saturated values (i.e. mapped to the destination type min\u002Fmax),\n- zeroed values (because they are below the smallest number that can be represented by the destination type)\n\nThe projection is symmetric per-tensor or per-channel for `int8` and `float8`, and group-wise affine (with a shift or 'zero-point') for lower bitwidth.\n\nOne of the benefits of using a lower-bitwidth representation is that you will be able to take advantage of accelerated operations\nfor the destination type, which is typically faster than their higher precision equivalents.\n\nQuanto does not support the conversion of a Tensor using mixed destination types.\n\n### Modules\n\nQuanto provides a generic mechanism to replace `torch` modules by `optimum-quanto` modules that are able to process quanto tensors.\n\n`optimum-quanto` modules dynamically convert their weights until a model is frozen, which slows down inference a bit but is\nrequired if the model needs to be tuned.\n\nWeights are usually quantized per-channel along the first dimension (output features).\n\nBiases are not converted to preserve the accuracy of a typical `addmm` operation.\n\nExplanation: to be consistent with the unquantized arithmetic operations, biases would need to be quantized with a scale that\nis equal to the product of the input and weight scales, which leads to a ridiculously small scale, and conversely\nrequires a very high bitwidth to avoid clipping. Typically, with `int8` inputs and weights, biases would need to be quantized\nwith at least `12` bits, i.e. in `int16`. Since most biases are today `float16`, this is a waste of time.\n\nActivations are dynamically quantized per-tensor using static scales (defaults to the range `[-1, 1]`).\n\nTo preserve accuracy, the model needs to be calibrated to evaluate the best activation scales (using a momentum).\n\nThe following modules can be quantized:\n\n- [Linear](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.Linear.html) (QLinear).\nWeights are always quantized, and biases are not quantized. Inputs and outputs can be quantized.\n- [Conv2d](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.Conv2d.html) (QConv2D).\nWeights are always quantized, and biases are not quantized. Inputs and outputs can be quantized.\n- [LayerNorm](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.LayerNorm.html),\nWeights and biases are __not__ quantized. Outputs can be quantized.\n\n## Pitfalls to avoid when quantizing activations\n\nActivations are always quantized per-tensor because most linear algebra operations in a model graph are not compatible\nwith per-axis inputs: you simply cannot add numbers that are not expressed in the same base (`you cannot add apples and oranges`).\n\nWeights involved in matrix multiplications are, on the contrary, always quantized along their first axis, because all output features\nare evaluated independently from one another.\n\nThe outputs of a quantized matrix multiplication will anyway always be dequantized, even if activations are quantized, because:\n\n- the resulting accumulated values are expressed with a much higher bitwidth (typically `int32` or `float32`) than the activation bitwidth (typically `int8` or `float8`),\n- they might be combined with a `float` bias.\n\nQuantizing activations per-tensor to `int8` can lead to serious quantization errors if the corresponding tensors contain large outlier values.\nTypically, this will lead to quantized tensors with most values set to zero (except the outliers).\n\nA possible solution to work around that issue is to 'smooth' the activations statically as illustrated by [SmoothQuant](https:\u002F\u002Fgithub.com\u002Fmit-han-lab\u002Fsmoothquant).\nYou can find a script to smooth some model architectures under [external\u002Fsmoothquant](external\u002Fsmoothquant).\n\nA better option is to represent activations using `float8`.\n","# Optimum Quanto\n\n> 该项目目前处于维护模式。我们仅接受用于修复小错误、改进文档及其他维护任务的拉取请求。重大的新功能或破坏性更改不太可能被合并。对于生产就绪的量化功能或活跃的开发工作，请考虑使用其他项目，例如 [bitsandbytes](https:\u002F\u002Fgithub.com\u002Fbitsandbytes-foundation\u002Fbitsandbytes) 或 [torchAO](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fao)。\n\n🤗 Optimum Quanto 是一个用于 [optimum](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Foptimum\u002Fen\u002Findex) 的 PyTorch 量化后端。\n\n它在设计时充分考虑了通用性和简洁性：\n\n- 所有功能均可在 eager 模式下使用（适用于不可跟踪的模型）；\n- 量化后的模型可以部署到任何设备上（包括 CUDA 和 MPS）；\n- 自动插入量化和反量化的桩代码；\n- 自动插入量化后的函数操作；\n- 自动插入量化模块（支持的模块列表见下文）；\n- 提供从浮点模型到动态量化再到静态量化的无缝工作流；\n- 序列化与 PyTorch 的 `weight_only` 格式及 🤗 `safetensors` 兼容；\n- 在 CUDA 设备上加速矩阵乘法运算（int8-int8、fp16-int4、bf16-int8、bf16-int4）；\n- 支持 int2、int4、int8 和 float8 权重；\n- 支持 int8 和 float8 激活值。\n\n尚未实现的功能：\n\n- 动态激活平滑处理；\n- 所有混合精度矩阵乘法的内核在所有设备上的实现；\n- 与 [PyTorch 编译器](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Ftorch.compiler.html)（即 dynamo）的兼容性。\n\n## 性能\n\n简而言之：\n\n- 准确性：使用 `int8`\u002F`float8` 权重和 `float8` 激活值编译的模型，其性能非常接近全精度模型；\n- 延迟：在存在优化内核的情况下，仅对模型权重进行量化时，量化模型的推理延迟可与全精度模型相媲美；\n- 设备内存：大约为浮点位数除以整数位数。\n\n以下段落仅为示例。有关按模型用例划分的详细结果，请参阅 `bench` 文件夹。\n\n### meta-llama\u002FMeta-Llama-3.1-8B\n\n\u003Cdiv class=\"row\">\u003Ccenter>\n  \u003Cdiv class=\"column\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_optimum-quanto_readme_ec32b47d373c.png\" alt=\"meta-llama\u002FMeta-Llama-3.1-8B WikiText 困惑度\">\n  \u003C\u002Fdiv>\n \u003C\u002Fcenter>\n\u003C\u002Fdiv>\n\n\u003Cdiv class=\"row\">\u003Ccenter>\n  \u003Cdiv class=\"column\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_optimum-quanto_readme_683720c12b24.png\" alt=\"meta-llama\u002FMeta-Llama-3.1-8B 延迟\">\n  \u003C\u002Fdiv>\n \u003C\u002Fcenter>\n\u003C\u002Fdiv>\n\n## 安装\n\nOptimum Quanto 可通过 pip 包管理器安装。\n\n```sh\npip install optimum-quanto\n```\n\n## Hugging Face 模型的量化流程\n\n`optimum-quanto` 提供了辅助类，用于量化、保存和重新加载 Hugging Face 量化模型。\n\n### LLM 模型\n\n第一步是量化模型：\n\n```python\nfrom transformers import AutoModelForCausalLM\nfrom optimum.quanto import QuantizedModelForCausalLM, qint4\n\nmodel = AutoModelForCausalLM.from_pretrained('meta-llama\u002FMeta-Llama-3-8B')\nqmodel = QuantizedModelForCausalLM.quantize(model, weights=qint4, exclude='lm_head')\n```\n\n注意：量化后的模型权重将被冻结。如果希望保持权重未冻结以便继续训练，则需要直接使用 `optimum.quanto.quantize` 方法。\n\n量化后的模型可以使用 `save_pretrained` 方法保存：\n\n```python\nqmodel.save_pretrained('.\u002FLlama-3-8B-quantized')\n```\n\n之后可以通过 `from_pretrained` 方法重新加载：\n\n```python\nfrom optimum.quanto import QuantizedModelForCausalLM\n\nqmodel = QuantizedModelForCausalLM.from_pretrained('Llama-3-8B-quantized')\n```\n\n### Diffusers 模型\n\n您可以对 Diffusers 流水线中的任意子模型进行量化，并随后无缝地将其集成到另一个流水线中。这里我们对 `Pixart` 流水线中的 `transformer` 进行量化：\n\n```python\nfrom diffusers import PixArtTransformer2DModel\nfrom optimum.quanto import QuantizedPixArtTransformer2DModel, qfloat8\n\nmodel = PixArtTransformer2DModel.from_pretrained(\"PixArt-alpha\u002FPixArt-Sigma-XL-2-1024-MS\", subfolder=\"transformer\")\nqmodel = QuantizedPixArtTransformer2DModel.quantize(model, weights=qfloat8)\nqmodel.save_pretrained(\".\u002Fpixart-sigma-fp8\")\n```\n\n稍后，我们可以重新加载量化后的模型并重建流水线：\n\n```python\nfrom diffusers import PixArtTransformer2DModel\nfrom optimum.quanto import QuantizedPixArtTransformer2DModel\n\ntransformer = QuantizedPixArtTransformer2DModel.from_pretrained(\".\u002Fpixart-sigma-fp8\")\ntransformer.to(device=\"cuda\")\npipe = PixArtSigmaPipeline.from_pretrained(\n  \"PixArt-alpha\u002FPixArt-Sigma-XL-2-1024-MS\",\n  transformer=None,\n  torch_dtype=torch.float16,\n).to(\"cuda\")\npipe.transformer = transformer\n```\n\n## 适用于原生 PyTorch 模型的量化工作流（低层级 API）\n\n使用低层级 Quanto API 时，需要注意的一点是：默认情况下，模型权重会进行动态量化；必须显式调用“冻结”操作来固定已量化的权重。\n\n典型的量化工作流包括以下步骤：\n\n**1. 量化**\n\n第一步将标准的浮点模型转换为动态量化模型。\n\n```python\nfrom optimum.quanto import quantize, qint8\n\nquantize(model, weights=qint8, activations=qint8)\n```\n\n在此阶段，仅修改模型的推理过程，以动态量化权重。\n\n**2. 校准（可选，若未量化激活值则无需校准）**\n\nQuanto 支持校准模式，允许在通过代表性样本运行量化模型时记录激活值范围。\n\n```python\nfrom optimum.quanto import Calibration\n\nwith Calibration(momentum=0.9):\n    model(samples)\n```\n\n这会自动启用量化模块中激活值的量化。\n\n**3. 微调，即量化感知训练（可选）**\n\n如果模型性能下降过多，可以对其进行几个 epoch 的微调，以恢复接近浮点模型的性能。\n\n```python\nimport torch\n\nmodel.train()\nfor batch_idx, (data, target) in enumerate(train_loader):\n    data, target = data.to(device), target.to(device)\n    optimizer.zero_grad()\n    output = model(data).dequantize()\n    loss = torch.nn.functional.nll_loss(output, target)\n    loss.backward()\n    optimizer.step()\n```\n\n**4. 冻结整数量化权重**\n\n冻结模型时，其浮点权重会被替换为量化的整数量化权重。\n\n```python\nfrom optimum.quanto import freeze\n\nfreeze(model)\n```\n\n**5. 序列化量化模型**\n\n量化后的模型权重可以序列化为 `state_dict`，并保存到文件中。支持 `pickle` 和 `safetensors`（推荐）两种格式。\n\n```python\nfrom safetensors.torch import save_file\n\nsave_file(model.state_dict(), 'model.safetensors')\n```\n\n为了能够重新加载这些权重，还需要存储量化模型的量化映射。\n\n```python\nimport json\n\nfrom optimum.quanto import quantization_map\n\nwith open('quantization_map.json', 'w') as f:\n  json.dump(quantization_map(model), f)\n```\n\n**6. 重新加载量化模型**\n\n可以通过 `state_dict` 和 `quantization_map` 使用 `requantize` 辅助函数重新加载序列化的量化模型。请注意，首先需要实例化一个空模型。\n\n```python\nimport json\n\nfrom safetensors.torch import load_file\nfrom optimum.quanto import requantize\n\nstate_dict = load_file('model.safetensors')\nwith open('quantization_map.json', 'r') as f:\n  quantization_map = json.load(f)\n\n# 根据你的建模代码创建一个空模型，并对其进行重新量化\nwith torch.device('meta'):\n  new_model = ...\nrequantize(new_model, state_dict, quantization_map, device=torch.device('cuda'))\n```\n\n有关该工作流的具体实现，请参阅 [示例](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Fquanto\u002Ftree\u002Fmain\u002Fexamples)。\n\n## 设计概览\n\n### 张量\n\nQuanto 的核心是一个张量子类，它对应于：\n- 将源张量投影到给定目标类型的最优范围内；\n- 将投影后的值映射到目标类型。\n\n对于浮点目标类型，映射由原生 PyTorch 的类型转换完成（即 `Tensor.to()`）。\n\n对于整数目标类型，映射则是一个简单的四舍五入操作（即 `torch.round()`）。\n\n投影的目标是通过减少以下情况的数量来提高转换精度：\n- 饱和值（即被映射到目标类型的最小值或最大值）；\n- 被清零的值（因为它们低于目标类型所能表示的最小数值）。\n\n投影方式根据数据类型而有所不同：对于 `int8` 和 `float8`，采用逐张量或逐通道对称投影；而对于更低的位宽，则采用分组仿射投影（带有偏移量或“零点”）。\n\n使用较低位宽表示的一个好处是，可以利用针对目标类型加速的运算，通常比高精度版本更快。\n\nQuanto 不支持使用混合目标类型对张量进行转换。\n\n### 模块\n\nQuanto 提供了一种通用机制，用于将 `torch` 模块替换为能够处理 Quanto 张量的 `optimum-quanto` 模块。\n\n`optimum-quanto` 模块会在模型冻结之前动态转换其权重，这会略微降低推理速度，但如果需要对模型进行微调，则这是必要的。\n\n权重通常按通道沿第一维度（输出特征）进行量化。\n\n偏置不进行转换，以保持典型 `addmm` 运算的精度。\n\n解释：为了与未量化算术运算保持一致，偏置需要以等于输入和权重尺度乘积的尺度进行量化，这会导致尺度小得离谱，从而需要非常高的位宽才能避免截断。例如，当输入和权重为 `int8` 时，偏置至少需要以 `12` 位进行量化，即 `int16`。由于大多数偏置目前都是 `float16`，这样做实际上并无意义。\n\n激活值则按张量动态量化，使用静态尺度（默认范围为 `[-1, 1]`）。\n\n为保持精度，需要对模型进行校准，以评估最佳的激活尺度（使用动量参数）。\n\n以下模块可以被量化：\n\n- [Linear](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.Linear.html)（QLinear）。权重始终量化，偏置不量化。输入和输出均可量化。\n- [Conv2d](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.Conv2d.html)（QConv2D）。权重始终量化，偏置不量化。输入和输出均可量化。\n- [LayerNorm](https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.LayerNorm.html)，权重和偏置 __不__ 量化。输出可以量化。\n\n## 量化激活值时需避免的陷阱\n\n激活值始终按张量整体进行量化，这是因为模型图中的大多数线性代数运算都不支持按轴输入：你无法对不同基数表示的数值进行加法运算（“不能把苹果和橘子相加”）。\n\n与此相反，参与矩阵乘法的权重则始终沿其第一个轴进行量化，这是因为所有输出特征都是独立计算的。\n\n无论如何，即使激活值已被量化，量化后的矩阵乘法结果仍会先被反量化，原因如下：\n\n- 结果的累加值采用的位宽远高于激活值的位宽（通常为 `int32` 或 `float32`，而激活值通常是 `int8` 或 `float8`)；\n- 这些值还可能与一个 `float` 类型的偏置项相加。\n\n如果对应的张量中包含较大的异常值，将激活值按张量整体量化为 `int8` 格式，可能会导致严重的量化误差。典型情况下，这会使量化后的张量中大部分值都被置为零，仅保留那些异常值。\n\n解决这一问题的一种方法是像 [SmoothQuant](https:\u002F\u002Fgithub.com\u002Fmit-han-lab\u002Fsmoothquant) 所示，对激活值进行静态平滑处理。你可以在 [external\u002Fsmoothquant](external\u002Fsmoothquant) 目录下找到用于平滑某些模型架构的脚本。\n\n更好的选择则是使用 `float8` 来表示激活值。","# Optimum Quanto 快速上手指南\n\nOptimum Quanto 是 Hugging Face `optimum` 库的 PyTorch 量化后端，旨在提供灵活且简单的模型量化方案。它支持动态和静态量化，兼容多种设备（CUDA、MPS），并支持 int2\u002F4\u002F8 及 float8 等多种精度。\n\n> **注意**：该项目目前处于维护模式，仅接受次要 bug 修复和文档改进。如需生产级量化功能或活跃开发的新特性，建议考虑 [bitsandbytes](https:\u002F\u002Fgithub.com\u002Fbitsandbytes-foundation\u002Fbitsandbytes) 或 [torchAO](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fao)。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**：Linux, macOS, Windows\n*   **Python 版本**：3.8 及以上\n*   **PyTorch**：已安装与您的硬件（CPU\u002FCUDA\u002FMPS）匹配的 PyTorch 版本\n*   **依赖库**：\n    *   `transformers` (用于处理 Hugging Face 模型)\n    *   `diffusers` (可选，用于处理图像生成模型)\n    *   `safetensors` (推荐，用于高效保存量化权重)\n\n## 安装步骤\n\n您可以直接通过 pip 安装 Optimum Quanto。国内开发者建议使用清华或阿里镜像源以加速下载。\n\n**使用官方源安装：**\n```sh\npip install optimum-quanto\n```\n\n**使用国内镜像源安装（推荐）：**\n```sh\npip install optimum-quanto -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 基本使用\n\nOptimum Quanto 提供了高层 API 以便快速量化 Hugging Face 模型，也提供了底层 API 用于自定义 PyTorch 模型的量化流程。\n\n### 场景一：快速量化大语言模型 (LLM)\n\n这是最简单的使用方式，适用于 `transformers` 加载的因果语言模型。以下示例将 Llama-3-8B 模型量化为 int4 精度。\n\n```python\nfrom transformers import AutoModelForCausalLM\nfrom optimum.quanto import QuantizedModelForCausalLM, qint4\n\n# 1. 加载原始浮点模型\nmodel = AutoModelForCausalLM.from_pretrained('meta-llama\u002FMeta-Llama-3-8B')\n\n# 2. 执行量化 (weights=qint4 表示权重量化为 4-bit 整数)\n# exclude='lm_head' 通常用于保持输出层精度以提升生成质量\nqmodel = QuantizedModelForCausalLM.quantize(model, weights=qint4, exclude='lm_head')\n\n# 3. 保存量化模型\nqmodel.save_pretrained('.\u002FLlama-3-8B-quantized')\n\n# 4. 后续加载量化模型\n# qmodel = QuantizedModelForCausalLM.from_pretrained('.\u002FLlama-3-8B-quantized')\n```\n\n### 场景二：量化 Diffusers 模型\n\n您也可以量化图像生成管道中的子模块（如 Transformer）。以下示例将 PixArt 模型的 transformer 部分量化为 float8 精度。\n\n```python\nfrom diffusers import PixArtTransformer2DModel\nfrom optimum.quanto import QuantizedPixArtTransformer2DModel, qfloat8\nimport torch\n\n# 1. 加载子模型\nmodel = PixArtTransformer2DModel.from_pretrained(\n    \"PixArt-alpha\u002FPixArt-Sigma-XL-2-1024-MS\", \n    subfolder=\"transformer\"\n)\n\n# 2. 执行量化 (weights=qfloat8)\nqmodel = QuantizedPixArtTransformer2DModel.quantize(model, weights=qfloat8)\nqmodel.save_pretrained(\".\u002Fpixart-sigma-fp8\")\n\n# 3. 重新加载并集成到管道中\ntransformer = QuantizedPixArtTransformer2DModel.from_pretrained(\".\u002Fpixart-sigma-fp8\")\ntransformer.to(device=\"cuda\")\n\npipe = PixArtSigmaPipeline.from_pretrained(\n  \"PixArt-alpha\u002FPixArt-Sigma-XL-2-1024-MS\",\n  transformer=None, # 不加载原始 transformer\n  torch_dtype=torch.float16,\n).to(\"cuda\")\n\npipe.transformer = transformer\n```\n\n### 场景三：原生 PyTorch 模型量化 (底层 API)\n\n对于非 Hugging Face 架构的原生 PyTorch 模型，需要遵循“量化 -> 校准 (可选) -> 冻结 -> 保存”的标准工作流。\n\n```python\nimport torch\nfrom optimum.quanto import quantize, freeze, Calibration, qint8\n\n# 假设 model 是一个标准的 torch.nn.Module\n# 1. 动态量化：将权重和激活值设置为动态量化模式\nquantize(model, weights=qint8, activations=qint8)\n\n# 2. 校准 (可选但推荐)：如果量化了激活值，需通过代表性数据确定缩放比例\n# 这能显著提升量化后的精度\nwith Calibration(momentum=0.9):\n    # 传入一些代表性样本进行推理\n    # model(samples) \n    pass\n\n# 3. 冻结模型：将浮点权重永久替换为整数量化权重，提升推理速度\nfreeze(model)\n\n# 4. 保存状态\n# 推荐使用 safetensors 保存权重\nfrom safetensors.torch import save_file\nsave_file(model.state_dict(), 'model.safetensors')\n\n# 同时必须保存量化映射表以便重新加载\nimport json\nfrom optimum.quanto import quantization_map\n\nwith open('quantization_map.json', 'w') as f:\n  json.dump(quantization_map(model), f)\n```","某初创团队需要在消费级显卡（如 RTX 3090）上部署 Meta-Llama-3-8B 大模型，以构建低成本的内部知识库问答系统。\n\n### 没有 optimum-quanto 时\n- **显存严重不足**：原始 BF16 精度的 8B 模型占用约 16GB 显存，加上推理时的激活值开销，极易导致单卡显存溢出（OOM），无法运行。\n- **量化流程繁琐**：手动编写量化脚本需要处理复杂的算子替换和权重转换，且难以兼容非标准模型结构，调试成本极高。\n- **推理速度受限**：缺乏针对特定硬件优化的混合精度矩阵乘法内核，即使强行量化，推理延迟也往往高于全精度模型，得不偿失。\n- **部署灵活性差**：生成的量化模型往往绑定特定后端，难以在不同设备（如 CUDA 或 MPS）间无缝迁移或保存为标准格式。\n\n### 使用 optimum-quanto 后\n- **显存占用减半**：通过 `qint4` 权重量化，模型显存占用降低至原来的 1\u002F4 左右，轻松在单张消费级显卡上流畅运行。\n- **工作流极简**：仅需几行代码调用 `QuantizedModelForCausalLM.quantize`，即可自动插入量化\u002F反量化桩并冻结权重，支持动态到静态的平滑过渡。\n- **推理性能提升**：自动启用 CUDA 上的加速矩阵乘法内核（如 bf16-int4），在保持精度几乎无损的前提下，显著降低了生成延迟。\n- **生态兼容性强**：量化后的模型可直接通过 `save_pretrained` 保存为 safetensors 格式，并能在任何支持 PyTorch 的设备上直接加载推理。\n\noptimum-quanto 让开发者能以极低的代码成本，将大型语言模型高效压缩并部署到资源受限的边缘设备上。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_optimum-quanto_d9e79fe4.png","huggingface","Hugging Face","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fhuggingface_90da21a4.png","The AI community building the future.",null,"https:\u002F\u002Fhuggingface.co\u002F","https:\u002F\u002Fgithub.com\u002Fhuggingface",[81,85,89,92,96,100,104],{"name":82,"color":83,"percentage":84},"Python","#3572A5",69.5,{"name":86,"color":87,"percentage":88},"Cuda","#3A4E3A",26.6,{"name":90,"color":91,"percentage":32},"C++","#f34b7d",{"name":93,"color":94,"percentage":95},"Objective-C++","#6866fb",1,{"name":97,"color":98,"percentage":99},"C","#555555",0.7,{"name":101,"color":102,"percentage":103},"Shell","#89e051",0.2,{"name":105,"color":106,"percentage":107},"Makefile","#427819",0,1035,86,"2026-04-02T14:17:13","Apache-2.0","Linux, macOS","可选但推荐。支持 CUDA (NVIDIA) 和 MPS (Apple Silicon)。若需加速矩阵乘法（如 int8-int8, fp16-int4 等），需要支持相应算子的 NVIDIA GPU。具体显存大小取决于模型规模，未明确最低要求。","未说明",{"notes":116,"python":114,"dependencies":117},"该项目目前处于维护模式，仅接受次要 bug 修复和文档改进，不建议用于需要活跃开发的生产环境（可考虑 bitsandbytes 或 torchAO）。支持在 eager 模式下运行（无需模型追踪）。支持将量化模型部署到任何设备（包括 CUDA 和 MPS）。序列化兼容 PyTorch weight_only 和 Hugging Face safetensors 格式。量化激活时需注意异常值可能导致精度下降，建议进行校准。",[118,119,120,121,122],"torch","optimum","transformers","diffusers","safetensors",[14],[125,126,119],"pytorch","quantization","2026-03-27T02:49:30.150509","2026-04-07T00:06:14.175957",[130,135,140,145,150,155],{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},20342,"如何保存和加载经过 quanto 量化的模型？","推荐的保存方式是将模型保存为 state_dict，后续可以使用 `optimum.quanto.requantize` 重新加载。也可以考虑使用 `safetensors` 来序列化 state_dict。直接使用 `save_pretrained` 和 `from_pretrained` 可能无法保留量化层信息。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fissues\u002F136",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},20343,"在 Windows 上遇到 'ninja' 构建错误怎么办？","该问题通常与构建环境有关。根据社区反馈，合并特定的 PR（如 #365 和 #366）后在 Windows 11 上可正常工作。如果遇到此类错误，请确保更新到最新版本或应用相关的修复补丁。此外，检查是否正确安装了 Ninja 构建工具以及 CUDA  toolkit 配置。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fissues\u002F360",{"id":141,"question_zh":142,"answer_zh":143,"source_url":144},20344,"如何在 Diffusion Pipeline 中正确应用量化（包括 VAE 和 UNet）？","可以参考以下代码模式：首先加载 pipeline 和 VAE，调用 `fuse_qkv_projections()`，然后分别对 `pipeline.unet` 和 `pipeline.vae` 调用 `quantize` 函数（设置 weights 和 activations 参数），最后调用 `freeze` 冻结参数。注意激活量化时需调整 torch_dtype（例如使用 float32 而非 float16）。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fissues\u002F74",{"id":146,"question_zh":147,"answer_zh":148,"source_url":149},20345,"Marlin int4 内核在高并行度下输出损坏如何解决？","这是一个已知的高并行度下权重\u002F缩放\u002F零点读取回显问题。社区测试表明，更新内核版本可以解决此问题，但需要注意修复方案可能会增加共享内存需求，从而将最低计算能力要求提升至 8.0（Compute Capability 8.0+）。建议等待官方合并相关修复 PR 或手动应用补丁。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fissues\u002F332",{"id":151,"question_zh":152,"answer_zh":153,"source_url":154},20346,"在 CUDA 架构 >= 80 的设备上运行 Pixart Sigma 示例时出现 'invalid configuration argument' 错误怎么办？","该错误通常由优化的内核（如 awq 或 tinygemm）在特定架构下崩溃引起。虽然该 Issue 目前状态为 stale，但这类问题通常需要通过更新库版本以获取针对高算力架构（>=80）的内核修复来解决。建议检查是否使用了最新版本的 optimum-quanto。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fissues\u002F248",{"id":156,"question_zh":157,"answer_zh":158,"source_url":159},20347,"quanto 是否支持视觉模型（如 ViT）的量化？","是的，Vision Transformers (ViT) 应该可以被 quanto 原生支持。虽然具体的示例代码（如分类或检测任务）可能需要用户参考社区贡献或自行编写，但核心量化功能适用于此类架构。用户可以尝试对小数据集（如 imagenette）进行分类任务测试。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fissues\u002F169",[161,166,171,176,181,186,191,196,201,206,211,216,221,226,231,236,241,246,251,256],{"id":162,"version":163,"summary_zh":164,"released_at":165},118372,"v0.2.7","## 变更内容\n\n### 新功能\n* 由 @imba-tjd 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F357 中为 QuantizedTransformersModel 添加了 `repr` 方法。\n* 由 @dacorvo 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F373 中将 PyTorch 的最低版本提升至 2.6。\n\n### 错误修复\n* [测试] 启用 XPU 上的测试（已变基），由 @dacorvo 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F349 中完成。\n* 启用 XPU 上的 QBitsTensor 测试，由 @dacorvo 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F350 中完成。\n* 修复（库）：仅在 Linux 上编译 CUDA 扩展，由 @dacorvo 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F365 中完成。\n* 修复激活量化后尝试访问 `state_dict` 时出现的错误，由 @DN6 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F371 中完成。\n\n## 新贡献者\n* @imba-tjd 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F357 中做出了首次贡献。\n* @DN6 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F371 中做出了首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fcompare\u002Fv0.2.6...v0.2.7","2025-03-06T08:10:49",{"id":167,"version":168,"summary_zh":169,"released_at":170},118373,"v0.2.6","## 变更内容\n\n* 添加髋部支持，由 @Disty0 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F330 中实现\n* 切换代码格式化工具，从 black 切换到 ruff，由 @ishandeva 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F334 中完成\n* 添加 marlin int4 内核，由 @dacorvo 和 @shcho1118 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F333 中实现\n* 修复：使用 reshape 替代 view，由 @dacorvo 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F338 中完成\n* 支持无权重的 QLayerNorm，由 @dacorvo 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F341 中实现\n\n## 新贡献者\n* @ishandeva 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F334 中完成了首次贡献\n* @Disty0 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F330 中完成了首次贡献\n* @shcho1118 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F333 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fcompare\u002Fv0.2.5...v0.2.6","2024-10-29T17:13:56",{"id":172,"version":173,"summary_zh":174,"released_at":175},118374,"v0.2.5","## 新功能\n\n- 从 Hugging Face 模型库加载和保存模型 #263，由 @sayakpaul 提供\n- 添加对 float8 e4f3mnuz 的支持 #310（源自 #281），由 @maktukmak 提供\n- 更快速且更节省内存的重新量化 #290，由 @latentCall145 提供\n- 为 QTensor 添加 torch.equal 支持 #294，由 @dacorvo 提供\n- 添加 Marlin Float8 内核 #296（源自 #241），由 @fxmarty 提供\n- 添加用于语音识别的 Whisper 示例 #298（源自 #242），由 @mattiadg 提供\n- 添加 ViT 分类示例 #308，由 @shovan777 提供\n\n## 错误修复\n\n- 修复量化中的包含模式 #271，由 @kaibioinfo 提供\n- 启用非严格的状态字典加载 #295，由 @BenjaminBossan 提供\n- 修复 transformers 前向传播错误 #303，由 @dacorvo 提供\n- 修复 transformers 模型中缺失的调用 #325，由 @dacorvo 提供\n- 修复 4D 输入的 8 位矩阵乘法调用 #326，由 @dacorvo 提供\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fcompare\u002Fv0.2.4...v0.2.5","2024-10-01T11:52:40",{"id":177,"version":178,"summary_zh":179,"released_at":180},118375,"v0.2.4","## 错误修复：\n\n- 修复了在未安装 `diffusers` 时 `optimum-cli` 中的导入错误，由 @dacorvo 提供\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fcompare\u002Fv0.2.3...v0.2.4","2024-07-26T09:25:19",{"id":182,"version":183,"summary_zh":184,"released_at":185},118376,"v0.2.3","## 变更内容\n\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F222 中，由 @dacorvo 引入了新的 int8 PyTorch 核心函数。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F223 中，当 PyTorch 更新时，由 @dacorvo 重新构建扩展模块。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F234 中，由 @dacorvo 尽可能使用 tinygemm 的 bfloat16 \u002F int4 核心函数。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F235 中，由 @dacorvo 添加了 HQQ 优化器。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F243 中，由 @dacorvo 添加了 QuantizedModelForCausalLM 类。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F244 中，由 @dacorvo 将 quanto 命令集成到 optimum-cli 中。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F247 中，由 @dacorvo 向图像示例中添加了 pixart-sigma 测试。\n* 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F255 中，由 @sayakpaul 实现了对扩散模型的支持。\n\n## 错误修复\n\n* 修复：在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F227 中，由 @dacorvo 对齐扩展模块以适应最大架构。\n* 修复 TinyGemmQBitsTensor 的移动问题，在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F246 中由 @dacorvo 完成。\n* 修复流水线错误，在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F249 中由 @dacorvo 解决。\n* 修复浮点数与 int8 矩阵乘法延迟回归问题，在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F250 中由 @dacorvo 修复。\n* 修复序列化问题，在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F258 中由 @dacorvo 完成。\n\n## 新贡献者\n* @sayakpaul 在 https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fpull\u002F255 中完成了他们的首次贡献。\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Foptimum-quanto\u002Fcompare\u002Fv0.2.2...v0.2.3","2024-07-25T15:18:11",{"id":187,"version":188,"summary_zh":189,"released_at":190},118377,"v0.2.2","## 新功能\n\n- 由 @dacorvo 添加 OWLv2 检测示例，\n- 由 @dacorvo 使用新的 PyTorch 量化内核。\n\n## Bug 修复\n\n- 由 @dacorvo 避免在较旧的 Nvidia 显卡（Ampere 之前）上出现 CUDA 编译错误，\n- 由 @dacorvo 在 PyTorch 更新时重新编译扩展，并防止段错误。","2024-06-28T15:30:10",{"id":192,"version":193,"summary_zh":194,"released_at":195},118378,"v0.2.1","本次发布不包含任何新功能，但它是首个使用新软件包名称的版本。","2024-05-31T15:24:50",{"id":197,"version":198,"summary_zh":199,"released_at":200},118379,"v0.2.0","## 新特性\r\n\r\n- 由 @calmitchell617 提供的重新量化解决方案助手，\n- 由 @thliang01 提供的 StableDiffusion 示例，\n- 由 @dacorvo 改进的线性反向传播路径，\n- 由 @dacorvo 提供的 AWQ int4 内核。","2024-05-24T10:49:17",{"id":202,"version":203,"summary_zh":204,"released_at":205},118380,"v0.1.0","## 新特性\n\n- 分组量化，\n- 安全序列化。","2024-03-13T08:43:50",{"id":207,"version":208,"summary_zh":209,"released_at":210},118381,"v0.0.13","## 新特性\n\n- 新增 `QConv2d` 量化模块，\n- 正式支持 `float8` 权重。\n\n## Bug 修复\n\n- 修复了 `QbitsTensor.to()` 方法无法移动内部张量的问题，\n- 在加载不移动内部张量的权重时，避免浅拷贝 `QTensor`。\n","2024-02-23T17:11:44",{"id":212,"version":213,"summary_zh":214,"released_at":215},118382,"v0.0.12","## New features\r\n\r\n- quanto kernels library (not used for now in quantize).\r\n\r\n## Breaking changes\r\n\r\n- quantization types are now all quanto.dtype","2024-02-16T17:04:16",{"id":217,"version":218,"summary_zh":219,"released_at":220},118383,"0.0.11","## New features:\r\n\r\n- support int2 and int4 weights.\r\n\r\nNew contributors:\r\n\r\n@younesbelkada\r\n@a-r-r-o-w","2024-01-19T15:21:22",{"id":222,"version":223,"summary_zh":224,"released_at":225},118384,"0.0.10","New features:\r\n\r\n- calibration streamline option to remove spurious quantize\u002Fdequantize,\r\n- calibration debug mode.","2024-01-19T15:13:02",{"id":227,"version":228,"summary_zh":229,"released_at":230},118385,"0.0.9","## New features:\r\n\r\n- quantize weights and activations parameters\r\n- float8 activations","2023-12-15T14:52:56",{"id":232,"version":233,"summary_zh":234,"released_at":235},118386,"0.0.8","## New features:\r\n\r\n- weight-only quantization,\r\n- integer matmul acceleration on CUDA.\r\n\r\n## Bug fixes:\r\n\r\n- actually use float16 weights,\r\n- avoid float16 overflows,\r\n- correct device placement,\r\n- robust serialization.","2023-12-08T15:31:24",{"id":237,"version":238,"summary_zh":239,"released_at":240},118387,"0.0.7","## New features:\r\n\r\n- per-axis quantization","2023-12-01T15:23:24",{"id":242,"version":243,"summary_zh":244,"released_at":245},118388,"0.0.6","## New features:\r\n\r\n- support `opt` models,\r\n- support `gpt-neox` models,\r\n- support `codegen` models.","2023-10-27T14:48:19",{"id":247,"version":248,"summary_zh":249,"released_at":250},118389,"0.0.5","## New features:\r\n\r\n- support MPS devices,\r\n- support Transformer models","2023-10-19T07:40:54",{"id":252,"version":253,"summary_zh":254,"released_at":255},118390,"0.0.4","Fix release to add correct package metadata.","2023-10-09T09:06:42",{"id":257,"version":258,"summary_zh":259,"released_at":260},118391,"0.0.1","Initial import of the sources.","2023-10-02T09:54:34"]