[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-apple--ml-ane-transformers":3,"tool-apple--ml-ane-transformers":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 真正成长为懂上",157379,2,"2026-04-15T23:32:42",[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":76,"owner_email":76,"owner_twitter":76,"owner_website":77,"owner_url":78,"languages":79,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":92,"env_os":93,"env_gpu":94,"env_ram":95,"env_deps":96,"category_tags":104,"github_topics":76,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":105,"updated_at":106,"faqs":107,"releases":108},7955,"apple\u002Fml-ane-transformers","ml-ane-transformers","Reference implementation of the Transformer architecture optimized for Apple Neural Engine (ANE)","ml-ane-transformers 是专为苹果设备打造的 Transformer 模型参考实现，旨在帮助开发者将 AI 模型高效部署在搭载 A14 及以上芯片或 M1 系列芯片的 iPhone、iPad 和 Mac 上。它核心解决了传统模型在移动端运行时速度慢、内存占用高的问题，通过针对苹果神经网络引擎（ANE）的深度优化，相比基准实现可实现高达 10 倍的推理速度提升，并将峰值内存消耗降低至原来的十四分之一。\n\n该工具主要面向需要在苹果生态中进行端侧模型部署的 AI 工程师和研究人员。其独特亮点在于提供了两套代码库：一套是独立的参考实现，另一套则直接兼容流行的 Hugging Face 模型库（如 DistilBERT），让用户能轻松替换现有模型类即可应用优化算法。使用流程清晰，支持从 PyTorch 模型加载、参数迁移到 TorchScript 追踪，最终通过 coremltools 转换为高效的 Core ML 格式。借助 Xcode 的性能分析工具，开发者可以直观验证模型在真实设备上的延迟与内存表现，是实现高性能移动端自然语言处理应用的理想选择。","# Apple Neural Engine (ANE) Transformers\nUse `ane_transformers` as a reference PyTorch implementation if you are considering deploying your Transformer models on Apple devices with an A14 or newer and M1 or newer chip to achieve up to **10 times faster** and **14 times** lower peak memory consumption compared to baseline implementations.\n\n`ane_transformers.reference` comprises a standalone reference implementation and `ane_transformers.huggingface` comprises optimized versions of [Hugging Face](https:\u002F\u002Fhuggingface.co\u002Fmodels) model classes such as `distilbert` to demonstrate the application of the optimization principles laid out in our research article on existing third-party implementations.\n\nPlease check out our [research article](https:\u002F\u002Fmachinelearning.apple.com\u002Fresearch\u002Fapple-neural-engine) for a detailed explanation of the optimizations as well as interactive figures to explore latency and peak memory consumption data from our case study: [Hugging Face distilbert](https:\u002F\u002Fhuggingface.co\u002Fdistilbert-base-uncased-finetuned-sst-2-english) model deployment on various devices and operating system versions. Below figures are non-interactive snapshots from the research article for iPhone 13 with iOS16.0 installed:\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_readme_13631a7bb214.png\">\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_readme_c64db54e3d57.png\">\n\n## Tutorial: Optimized Deployment of Hugging Face distilbert\n\nThis tutorial is a step-by-step guide to the model deployment process from the case study in our research article. The same code is used to generate the Hugging Face distilbert performance data in the figures above.\n\nIn order to begin the optimizations, we initialize the baseline model as follows:\n\n```python\nimport transformers\nmodel_name = \"distilbert-base-uncased-finetuned-sst-2-english\"\nbaseline_model = transformers.AutoModelForSequenceClassification.from_pretrained(\n    model_name,\n    return_dict=False,\n    torchscript=True,\n).eval()\n```\n\nThen we initialize the mathematically equivalent but optimized model, and we restore its parameters using that of the baseline model:\n\n```python\nfrom ane_transformers.huggingface import distilbert as ane_distilbert\noptimized_model = ane_distilbert.DistilBertForSequenceClassification(\n    baseline_model.config).eval()\noptimized_model.load_state_dict(baseline_model.state_dict())\n```\n\nNext we create sample inputs for the model:\n\n```python\ntokenizer = transformers.AutoTokenizer.from_pretrained(model_name)\ntokenized = tokenizer(\n    [\"Sample input text to trace the model\"],\n    return_tensors=\"pt\",\n    max_length=128,  # token sequence length\n    padding=\"max_length\",\n)\n```\n\nWe then trace the optimized model to obtain the expected input format (Torchscript) for the coremltools conversion tool.\n\n```python\nimport torch\ntraced_optimized_model = torch.jit.trace(\n    optimized_model,\n    (tokenized[\"input_ids\"], tokenized[\"attention_mask\"])\n)\n```\n\nFinally, we use coremltools to generate the Core ML model package file and save it.\n\n```python\nimport coremltools as ct\nimport numpy as np\nane_mlpackage_obj = ct.convert(\n    traced_optimized_model,\n    convert_to=\"mlprogram\",\n    inputs=[\n        ct.TensorType(\n                f\"input_{name}\",\n                    shape=tensor.shape,\n                    dtype=np.int32,\n                ) for name, tensor in tokenized.items()\n            ],\n            compute_units=ct.ComputeUnit.ALL,\n)\nout_path = \"HuggingFace_ane_transformers_distilbert_seqLen128_batchSize1.mlpackage\"\nane_mlpackage_obj.save(out_path)\n```\n\nTo verify performance, developers can now launch Xcode and simply add this model package file as a resource in their projects. After clicking on the Performance tab, the developer can generate a performance report on locally available devices, for example, on the Mac that is running Xcode or another Apple device that is connected to that Mac. The figure below shows a performance report generated for this model on an iPhone 13 Pro Max with iOS 16.0 installed.\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_readme_be836ab273f1.png\">\n\n\nBased on the figure above, the latency is improved by a factor of 2.84 times for the sequence length of 128 and batch size of 1 that were chosen for the tutorial. Higher sequence lengths, such as 512, and batch sizes, such as 8, will yield up to **10 times lower latency** and **14 times lower peak memory consumption**. Please refer to Figure 2 from our [research article](https:\u002F\u002Fmachinelearning.apple.com\u002Fresearch\u002Fapple-neural-engine) for detailed and interactive performance data.\n\nNote that the load and compilation times increase due to the number of operations increasing in the optimized model but these are one-time costs and user experience will not be affected if the model is loaded asynchronously.\n\nNote that 4 of the 606 operations in the optimized model are executed on the CPU. These are the embedding lookup related operations and they are more efficient to do on the CPU for this particular model configuration.\n\n## A Note on Unit Tests\nThe unit tests measure, among other things, the ANE speed-up factor. Since the device spec for this reference implementation is M1 or newer chips for the Mac and A14 and newer chips for the iPhone and iPad, the speed-up unit tests will print a warning message if executed on devices outside of this spec. Even if the model is generated using an out of spec Mac, the model should work as expected on in-spec devices.\n\n## Installation & Troubleshooting\n- Fastest: `pip install ane_transformers`\n- Locally editable: `pip install -e .`\n- If installation fails with `ERROR: Failed building wheel for tokenizers` or `error: can't find Rust compiler`, please follow this [solution](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002Fissues\u002F2831#issuecomment-592724471)","# 苹果神经引擎（ANE）Transformers\n如果您正考虑在搭载 A14 或更高版本以及 M1 或更高版本芯片的苹果设备上部署您的 Transformer 模型，以实现相比基准实现**最高快 10 倍**且峰值内存消耗降低**14 倍**的效果，可以将 `ane_transformers` 作为参考 PyTorch 实现。\n\n`ane_transformers.reference` 包含一个独立的参考实现，而 `ane_transformers.huggingface` 则包含了对 [Hugging Face](https:\u002F\u002Fhuggingface.co\u002Fmodels) 模型类（如 `distilbert`）的优化版本，旨在展示我们研究论文中提出的优化原则在现有第三方实现中的应用。\n\n请参阅我们的[研究论文](https:\u002F\u002Fmachinelearning.apple.com\u002Fresearch\u002Fapple-neural-engine)，其中详细解释了各项优化，并提供了交互式图表，帮助您探索来自案例研究的延迟和峰值内存消耗数据：在不同设备及操作系统版本上部署 [Hugging Face distilbert](https:\u002F\u002Fhuggingface.co\u002Fdistilbert-base-uncased-finetuned-sst-2-english) 模型。以下图片为研究论文中关于安装 iOS 16.0 的 iPhone 13 的非交互式截图：\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_readme_13631a7bb214.png\">\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_readme_c64db54e3d57.png\">\n\n## 教程：优化部署 Hugging Face distilbert\n本教程是针对我们研究论文中案例研究的模型部署流程的分步指南。上述图表中的 Hugging Face distilbert 性能数据正是使用相同代码生成的。\n\n为了开始优化，我们首先初始化基准模型如下：\n\n```python\nimport transformers\nmodel_name = \"distilbert-base-uncased-finetuned-sst-2-english\"\nbaseline_model = transformers.AutoModelForSequenceClassification.from_pretrained(\n    model_name,\n    return_dict=False,\n    torchscript=True,\n).eval()\n```\n\n随后，我们初始化一个数学上等价但经过优化的模型，并将其参数从基准模型中加载过来：\n\n```python\nfrom ane_transformers.huggingface import distilbert as ane_distilbert\noptimized_model = ane_distilbert.DistilBertForSequenceClassification(\n    baseline_model.config).eval()\noptimized_model.load_state_dict(baseline_model.state_dict())\n```\n\n接下来，我们为模型创建示例输入：\n\n```python\ntokenizer = transformers.AutoTokenizer.from_pretrained(model_name)\ntokenized = tokenizer(\n    [\"用于追踪模型的示例输入文本\"],\n    return_tensors=\"pt\",\n    max_length=128,  # token 序列长度\n    padding=\"max_length\",\n)\n```\n\n然后，我们对优化后的模型进行追踪，以获得 coremltools 转换工具所需的预期输入格式（Torchscript）。\n\n```python\nimport torch\ntraced_optimized_model = torch.jit.trace(\n    optimized_model,\n    (tokenized[\"input_ids\"], tokenized[\"attention_mask\"])\n)\n```\n\n最后，我们使用 coremltools 生成 Core ML 模型包文件并将其保存：\n\n```python\nimport coremltools as ct\nimport numpy as np\nane_mlpackage_obj = ct.convert(\n    traced_optimized_model,\n    convert_to=\"mlprogram\",\n    inputs=[\n        ct.TensorType(\n                f\"input_{name}\",\n                    shape=tensor.shape,\n                    dtype=np.int32,\n                ) for name, tensor in tokenized.items()\n            ],\n            compute_units=ct.ComputeUnit.ALL,\n)\nout_path = \"HuggingFace_ane_transformers_distilbert_seqLen128_batchSize1.mlpackage\"\nane_mlpackage_obj.save(out_path)\n```\n\n为验证性能，开发者现在可以启动 Xcode，并简单地将该模型包文件作为资源添加到项目中。点击“Performance”选项卡后，开发者便可在本地可用设备上生成性能报告，例如在运行 Xcode 的 Mac 上，或连接到该 Mac 的其他苹果设备上。下图展示了在安装 iOS 16.0 的 iPhone 13 Pro Max 上为此模型生成的性能报告。\n\n\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_readme_be836ab273f1.png\">\n\n\n根据上图所示，对于本教程所选用的序列长度 128、批次大小 1 的配置，延迟改善了 2.84 倍。若采用更高的序列长度（如 512）和批次大小（如 8），则可实现**延迟降低多达 10 倍**、**峰值内存消耗降低 14 倍**的效果。有关详细且交互式的性能数据，请参阅我们[研究论文](https:\u002F\u002Fmachinelearning.apple.com\u002Fresearch\u002Fapple-neural-engine)中的图 2。\n\n请注意，由于优化后模型中的操作数量增加，加载和编译时间会有所延长。不过，这些成本仅发生一次，如果以异步方式加载模型，则不会影响用户体验。\n\n此外，优化后的模型中有 606 个操作中的 4 个是在 CPU 上执行的。这些是与嵌入查找相关的操作，对于当前的模型配置而言，在 CPU 上执行更为高效。\n\n## 关于单元测试的说明\n单元测试除其他内容外，还会测量 ANE 的加速倍数。鉴于此参考实现的设备规格要求为：Mac 需配备 M1 或更高版本芯片，iPhone 和 iPad 则需搭载 A14 或更高版本芯片，因此，若在不符合此规格的设备上运行速度提升相关的单元测试，系统将显示警告信息。即便模型是在不符合规格的 Mac 上生成的，它仍应在符合规格的设备上正常工作。\n\n## 安装与故障排除\n- 最快方式：`pip install ane_transformers`\n- 可本地编辑：`pip install -e .`\n- 若安装过程中出现 `ERROR: Failed building wheel for tokenizers` 或 `error: can't find Rust compiler` 错误，请按照此[解决方案](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002Fissues\u002F2831#issuecomment-592724471)进行处理。","# ml-ane-transformers 快速上手指南\n\n本指南帮助中国开发者在搭载 A14\u002FM1 及以上芯片的 Apple 设备上，利用 Apple Neural Engine (ANE) 加速部署 Hugging Face Transformer 模型（如 DistilBERT），实现最高 **10 倍** 的推理速度提升和 **14 倍** 的峰值内存降低。\n\n## 环境准备\n\n在开始之前，请确保满足以下硬件和软件要求：\n\n*   **硬件要求**：\n    *   Mac: M1 芯片或更新版本。\n    *   iPhone\u002FiPad: A14 仿生芯片或更新版本。\n*   **软件要求**：\n    *   macOS 12.0+ (Monterey) 或 iOS 16.0+。\n    *   Python 3.8+。\n    *   Xcode（用于后续在真机上验证性能报告）。\n*   **前置依赖**：\n    *   `torch` (PyTorch)\n    *   `transformers` (Hugging Face)\n    *   `coremltools` (Apple Core ML 转换工具)\n    *   `numpy`\n\n> **注意**：虽然模型可以在非指定设备（如 Intel Mac）上生成，但性能加速效果仅在符合上述芯片规格的设备上生效。\n\n## 安装步骤\n\n推荐使用 pip 进行安装。国内开发者若遇到网络问题，可配置清华或阿里镜像源加速。\n\n**标准安装：**\n```bash\npip install ane_transformers\n```\n\n**使用国内镜像源加速安装（推荐）：**\n```bash\npip install ane_transformers -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n**开发模式安装（如需修改源码）：**\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fapple\u002Fml-ane-transformers.git\ncd ml-ane-transformers\npip install -e . -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n> **故障排除**：如果安装过程中出现 `ERROR: Failed building wheel for tokenizers` 或 `error: can't find Rust compiler`，请先安装 Rust 编译器，参考解决方案：[HuggingFace Tokenizers Issue #2831](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Ftransformers\u002Fissues\u002F2831#issuecomment-592724471)。\n\n## 基本使用\n\n以下示例演示如何将 Hugging Face 的 `distilbert` 模型转换为优化的 Core ML 格式，以便在 Apple 设备上利用 ANE 加速。\n\n### 1. 初始化基线模型与优化模型\n\n首先加载标准的 Hugging Face 模型，然后初始化学术等效但经过 ANE 优化的模型结构，并载入基线模型的参数。\n\n```python\nimport transformers\nfrom ane_transformers.huggingface import distilbert as ane_distilbert\n\nmodel_name = \"distilbert-base-uncased-finetuned-sst-2-english\"\n\n# 初始化基线模型\nbaseline_model = transformers.AutoModelForSequenceClassification.from_pretrained(\n    model_name,\n    return_dict=False,\n    torchscript=True,\n).eval()\n\n# 初始化优化模型并加载参数\noptimized_model = ane_distilbert.DistilBertForSequenceClassification(\n    baseline_model.config).eval()\noptimized_model.load_state_dict(baseline_model.state_dict())\n```\n\n### 2. 准备输入数据与模型追踪 (Tracing)\n\n创建样本输入数据，并使用 PyTorch JIT 追踪优化后的模型，以便 `coremltools` 能够识别输入输出格式。\n\n```python\nimport torch\n\n# 初始化分词器并处理文本\ntokenizer = transformers.AutoTokenizer.from_pretrained(model_name)\ntokenized = tokenizer(\n    [\"Sample input text to trace the model\"],\n    return_tensors=\"pt\",\n    max_length=128,  # token 序列长度\n    padding=\"max_length\",\n)\n\n# 追踪优化模型以获取 Torchscript 格式\ntraced_optimized_model = torch.jit.trace(\n    optimized_model,\n    (tokenized[\"input_ids\"], tokenized[\"attention_mask\"])\n)\n```\n\n### 3. 转换为 Core ML 模型\n\n使用 `coremltools` 将追踪后的模型转换为 `.mlpackage` 格式，指定所有计算单元（包括 ANE）参与计算。\n\n```python\nimport coremltools as ct\nimport numpy as np\n\nane_mlpackage_obj = ct.convert(\n    traced_optimized_model,\n    convert_to=\"mlprogram\",\n    inputs=[\n        ct.TensorType(\n                f\"input_{name}\",\n                    shape=tensor.shape,\n                    dtype=np.int32,\n                ) for name, tensor in tokenized.items()\n            ],\n            compute_units=ct.ComputeUnit.ALL,\n)\n\n# 保存模型文件\nout_path = \"HuggingFace_ane_transformers_distilbert_seqLen128_batchSize1.mlpackage\"\nane_mlpackage_obj.save(out_path)\n```\n\n### 4. 验证性能\n\n转换完成后，将生成的 `.mlpackage` 文件添加到 Xcode 项目的资源文件中。在 Xcode 中打开该模型，点击 **Performance** 标签页，即可连接本地 Mac 或已连接的 iOS 设备生成性能报告。\n\n*   **预期效果**：在序列长度 128、Batch Size 1 的配置下，延迟可降低约 2.84 倍；若增加序列长度（如 512）或 Batch Size，延迟最高可降低 **10 倍**，峰值内存消耗降低 **14 倍**。\n*   **注意**：优化模型的操作数量略有增加，导致加载和编译时间稍长，建议异步加载模型以提升用户体验。少量嵌入查找操作仍会在 CPU 上执行以获得最佳效率。","一家初创团队正在开发一款运行在 iPhone 上的实时情感分析应用，需要在用户输入文本的瞬间判断其情绪倾向，且必须完全在本地离线运行以保护隐私。\n\n### 没有 ml-ane-transformers 时\n- **推理延迟过高**：直接使用标准的 Hugging Face DistilBERT 模型在 iPhone 13 上运行时，单次预测耗时较长，导致用户输入后需等待明显卡顿才能看到结果，严重破坏交互体验。\n- **内存占用激增**：基线模型峰值内存消耗巨大，极易触发 iOS 系统的内存警告甚至导致应用闪退，尤其在后台有其他任务运行时更为严重。\n- **发热与耗电严重**：由于无法有效利用苹果神经引擎（ANE），计算压力全落在 CPU\u002FGPU 上，导致设备迅速发热并快速耗尽电量。\n- **部署优化困难**：开发者需要手动重写大量底层算子才能适配 ANE，技术门槛高且容易引入误差，难以在保证精度的前提下实现硬件加速。\n\n### 使用 ml-ane-transformers 后\n- **速度提升 10 倍**：通过调用专为 ANE 优化的参考实现，模型推理速度大幅提升，实现了真正的“即时”情感反馈，用户几乎感知不到延迟。\n- **内存降低 14 倍**：峰值内存占用显著下降，应用运行极其稳定，即使在低端机型或多任务场景下也能流畅运行，彻底消除了闪退风险。\n- **能效表现优异**：计算负载成功卸载至低功耗的神经引擎，设备保持凉爽，显著延长了用户的电池续航时间。\n- **无缝集成部署**：只需几行代码即可将现有的 Hugging Face 模型转换为数学等价但硬件友好的版本，并通过 Core ML 轻松打包进 Xcode 项目，极大降低了工程落地难度。\n\nml-ane-transformers 让复杂的 Transformer 模型在苹果设备上实现了高性能、低功耗的本地化部署，真正打通了先进 AI 算法与移动端用户体验之间的最后一公里。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fapple_ml-ane-transformers_13631a7b.png","apple","Apple","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fapple_84e0ff25.jpg","",null,"https:\u002F\u002Fapple.com","https:\u002F\u002Fgithub.com\u002Fapple",[80,84],{"name":81,"color":82,"percentage":83},"Python","#3572A5",99.7,{"name":85,"color":86,"percentage":87},"Makefile","#427819",0.3,2707,95,"2026-04-12T14:26:02","NOASSERTION",4,"macOS, iOS","不需要独立显卡或 NVIDIA GPU。必须使用配备 Apple Neural Engine (ANE) 的 Apple Silicon 芯片（Mac: M1 或更新版本；iPhone\u002FiPad: A14 或更新版本）。模型通过 coremltools 转换为 Core ML 格式并在 ANE 上运行。","未说明（文中提到相比基线实现可降低高达 14 倍的峰值内存消耗，具体取决于模型大小和序列长度）",{"notes":97,"python":98,"dependencies":99},"该工具专为苹果生态设计，不支持 Linux 或 Windows。核心功能是将 PyTorch 模型转换为 Core ML (.mlpackage) 格式以利用 Apple Neural Engine 加速。开发环境需在 macOS 上进行模型追踪和转换，最终部署目标为 iOS 设备或 Apple Silicon Mac。若在非指定芯片（如 Intel Mac 或非 A14+ 设备）上运行速度测试单元，会收到警告，但生成的模型在符合要求的设备上仍可正常工作。安装时若遇到 Rust 编译器错误，需参考 Hugging Face 相关解决方案。","未说明（需支持 PyTorch 和 coremltools 的版本）",[100,101,102,103],"torch","transformers","coremltools","numpy",[35,14],"2026-03-27T02:49:30.150509","2026-04-16T08:17:11.699173",[],[109,113,118],{"id":110,"version":111,"summary_zh":76,"released_at":112},280845,"v0.1.3","2022-08-09T04:22:55",{"id":114,"version":115,"summary_zh":116,"released_at":117},280846,"v0.1.2","- `torch.nn.LayerNorm` 和 `ane_transformers.reference.layer_norm.LayerNormANE` 在应用缩放和偏置项时的顺序相反。为了将使用前者训练得到的 state_dict 准确地恢复到后者中，我们对偏置项进行了调整。这一改动略微提升了 Hugging Face PyTorch 模型输出与 ane_transformers CoreML 模型输出之间的对齐度。\n- 为 PyTorch 版本引入 1.11.0 的上限，以确保 coremltools 5.2.0 能够良好适配。该上限将在 coremltools 6.0 发布时移除或更新（目前处于 beta1 阶段）。","2022-07-30T07:20:48",{"id":119,"version":120,"summary_zh":76,"released_at":121},280847,"v0.1.1","2022-06-07T05:31:52"]