[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-hasktorch--hasktorch":3,"tool-hasktorch--hasktorch":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 真正成长为懂上",143909,2,"2026-04-07T11:33:18",[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":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":64,"owner_name":64,"owner_avatar_url":73,"owner_bio":74,"owner_company":75,"owner_location":75,"owner_email":75,"owner_twitter":75,"owner_website":75,"owner_url":76,"languages":77,"stars":114,"forks":115,"last_commit_at":116,"license":117,"difficulty_score":118,"env_os":119,"env_gpu":120,"env_ram":121,"env_deps":122,"category_tags":130,"github_topics":75,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":131,"updated_at":132,"faqs":133,"releases":163},5237,"hasktorch\u002Fhasktorch","hasktorch","Tensors and neural networks in Haskell","Hasktorch 是一个专为 Haskell 编程语言设计的开源库，旨在让开发者能够在 Haskell 环境中直接进行张量计算和构建神经网络。它巧妙地复用了 PyTorch 核心的 C++ 底层库，从而在保留 Haskell 类型安全、函数式编程优势的同时，获得了业界领先的深度学习性能支持。\n\n对于习惯使用 Python 进行 AI 开发但希望利用 Haskell 强类型系统来减少运行时错误、提升代码可靠性的研究人员和开发者而言，Hasktorch 提供了理想的解决方案。它特别适合那些对函数式编程有热情，或需要在高可靠性系统中集成机器学习能力的技术团队。\n\n该项目的独特亮点在于其“独立社区驱动”的模式与强大的互操作性：既无需重新发明轮子，又能享受 Haskell 优雅的抽象能力。目前 Hasktorch 已发布 0.2 版本，支持 CPU 及 CUDA 加速，并提供了从环境配置到 MNIST 实战的完整教程与示例。虽然 API 仍在积极演进中，但其活跃的社区（如 Discord 频道）为新老用户提供了良好的交流与协作空间。如果你想在 Haskell 生态中探索深度学习的前沿可能，Ha","Hasktorch 是一个专为 Haskell 编程语言设计的开源库，旨在让开发者能够在 Haskell 环境中直接进行张量计算和构建神经网络。它巧妙地复用了 PyTorch 核心的 C++ 底层库，从而在保留 Haskell 类型安全、函数式编程优势的同时，获得了业界领先的深度学习性能支持。\n\n对于习惯使用 Python 进行 AI 开发但希望利用 Haskell 强类型系统来减少运行时错误、提升代码可靠性的研究人员和开发者而言，Hasktorch 提供了理想的解决方案。它特别适合那些对函数式编程有热情，或需要在高可靠性系统中集成机器学习能力的技术团队。\n\n该项目的独特亮点在于其“独立社区驱动”的模式与强大的互操作性：既无需重新发明轮子，又能享受 Haskell 优雅的抽象能力。目前 Hasktorch 已发布 0.2 版本，支持 CPU 及 CUDA 加速，并提供了从环境配置到 MNIST 实战的完整教程与示例。虽然 API 仍在积极演进中，但其活跃的社区（如 Discord 频道）为新老用户提供了良好的交流与协作空间。如果你想在 Haskell 生态中探索深度学习的前沿可能，Hasktorch 值得尝试。","# Hasktorch\n\nHasktorch is a library for tensors and neural networks in Haskell.\nIt is an independent open source community project which leverages the core C++ libraries shared by PyTorch.\n\nThis project is in active development, so expect changes to the library API as it evolves.\nWe would like to invite new users to [join our Hasktorch discord space](#contributing) for questions and discussions. [Contributions\u002FPR are encouraged](#contributing).\n\nThe second major release of Hasktorch (0.2) is currently available on hackage and nixpkgs.\n\n## Documentation\n\nThe documentation is divided into several sections:\n\n- [Introductory Videos](#introductory-videos)\n- [Getting Started](#getting-started)\n- [Known Issues](#known-issues)\n- [Contributing](#contributing)\n- [Notes for Library Developers](#notes-for-library-developers)\n\n## Introductory Videos\n\n- [High-level MuniHac talk](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=Qu6RIO02m1U) by [@austinvhuang][austin-twitter]\n- [Hands-on live-coding demo](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=ZnYa99QoznE&t=1689) by [@tscholak][torsten-twitter]\n- [Low-level FFI talk](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=qWpD8t_Aodk&feature=youtu.be) by [@junjihashimoto][junji-twitter]\n\n\n## Getting Started\n\nThe following steps will get you started.\nThey assume the hasktorch repository has just been cloned.\nAfter setup is done, read the [online tutorials](https:\u002F\u002Fhasktorch.github.io\u002Ftutorial\u002F) and [API documents](https:\u002F\u002Fhasktorch.github.io\u002F).\n\n* [linux+cabal+cpu](#linuxcabalcpu)\n* [linux+cabal+cuda11](#linuxcabalcuda11)\n* [macos+cabal+cpu](#macoscabalcpu)\n* [linux+stack+cpu](#linuxstackcpu)\n* [macos+stack+cpu](#macosstackcpu)\n* [nixos+cabal+cpu](#nixoscabalcpu)\n* [nixos+cabal+cuda11](#nixoscabalcuda11)\n* [docker+jupyterlab+cuda11](#dockerjupyterlabcuda11)\n\n\n### linux+cabal+cpu\n\nStarting from the top-level directory of the project, run:\n\n```sh\n$ .\u002Fsetup-cabal.sh # Create a cabal project file\n```\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ cabal build hasktorch  # Build the Hasktorch library.\n$ cabal test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ cabal build examples  # Build the Hasktorch examples.\n$ cabal test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=cpu                      # Set device to CPU for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n\n### linux+cabal+cuda\n\nFirst set the `LIBTORCH_CUDA_VERSION` environment variable to\nthe CUDA version you're currently using. E.g\n\n`export LIBTORCH_CUDA_VERSION=cu118` for CUDA 11.8.\n\nIf unspecified, Hasktorch defaults to downloading the cpu\nversion.\n\nStarting from the top-level directory of the project, run:\n\n```sh\n$ .\u002Fsetup-cabal.sh        # Create a cabal project file\n```\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ cabal build hasktorch  # Build the Hasktorch library.\n$ cabal test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ cabal build examples  # Build the Hasktorch examples.\n$ cabal test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=\"cuda:0\"                 # Set device to CUDA for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n\n### macos+cabal+cpu\n\nStarting from the top-level directory of the project, run:\n\n```sh\n$ .\u002Fsetup-cabal.sh # Create a cabal project file\n```\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ cabal build hasktorch  # Build the Hasktorch library.\n$ cabal test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ cabal build examples  # Build the Hasktorch examples.\n$ cabal test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=cpu                      # Set device to CPU for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n\n\n### linux+stack+cpu\n\nInstall the Haskell Tool Stack if you haven't already, following [instructions here](https:\u002F\u002Fdocs.haskellstack.org\u002Fen\u002Fstable\u002FREADME\u002F)\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ stack build hasktorch  # Build the Hasktorch library.\n$ stack test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ stack build examples  # Build the Hasktorch examples.\n$ stack test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=cpu                      # Set device to CPU for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n### macos+stack+cpu\n\nInstall the Haskell Tool Stack if you haven't already, following [instructions here](https:\u002F\u002Fdocs.haskellstack.org\u002Fen\u002Fstable\u002FREADME\u002F)\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ stack build hasktorch  # Build the Hasktorch library.\n$ stack test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ stack build examples  # Build the Hasktorch examples.\n$ stack test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=cpu                      # Set device to CPU for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n\n\n### nixos+cabal+cpu\n\n(Optional) Install and set up Cachix:\n\n```sh\n$ nix-env -iA cachix -f https:\u002F\u002Fcachix.org\u002Fapi\u002Fv1\u002Finstall  # (Optional) Install Cachix.\n# (Optional) Use IOHK's cache. See https:\u002F\u002Finput-output-hk.github.io\u002Fhaskell.nix\u002Ftutorials\u002Fgetting-started\u002F#setting-up-the-binary-cache\n$ cachix use hasktorch                                     # (Optional) Use hasktorch's cache.\n```\n\nStarting from the top-level directory of the project, run:\n\n```sh\n$ nix develop  # Enter the nix shell environment for Hasktorch.\n```\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ cabal build hasktorch  # Build the Hasktorch library.\n$ cabal test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ cabal build examples  # Build the Hasktorch examples.\n$ cabal test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=cpu                      # Set device to CPU for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n\n\n### nixos+cabal+cuda11\n\n(Optional) Install and set up Cachix:\n\n```sh\n$ nix-env -iA cachix -f https:\u002F\u002Fcachix.org\u002Fapi\u002Fv1\u002Finstall  # (Optional) Install Cachix.\n# (Optional) Use IOHK's cache. See https:\u002F\u002Finput-output-hk.github.io\u002Fhaskell.nix\u002Ftutorials\u002Fgetting-started\u002F#setting-up-the-binary-cache\n$ cachix use hasktorch                                     # (Optional) Use hasktorch's cache.\n```\n\nStarting from the top-level directory of the project, run:\n\n```sh\n$ cat > nix\u002Fdev-config.nix\n{\n  profiling = true;\n  cudaSupport = true;\n  cudaMajorVersion = \"11\";\n}\n$ nix develop  # Enter the nix shell environment for Hasktorch.\n```\n\nTo build and test the Hasktorch library, run:\n\n```sh\n$ cabal build hasktorch  # Build the Hasktorch library.\n$ cabal test hasktorch   # Build and run the Hasktorch library test suite.\n```\n\nTo build and test the example executables shipped with hasktorch, run:\n\n```sh\n$ cabal build examples  # Build the Hasktorch examples.\n$ cabal test examples   # Build and run the Hasktorch example test suites.\n```\n\nTo run the MNIST CNN example, run:\n\n```sh\n$ cd examples                            # Change to the examples directory.\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # Download the MNIST dataset.\n$ export DEVICE=\"cuda:0\"                 # Set device to CUDA for the MNIST CNN example.\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # Run the MNIST CNN example.\n```\n\n### docker+jupyterlab+cuda11\n\n[This dockerhub repository](https:\u002F\u002Fhub.docker.com\u002Frepository\u002Fdocker\u002Fhtorch\u002Fhasktorch-jupyter) provides the docker-image of jupyterlab.\nIt supports cuda11, cuda10 and cpu only. When you use jupyterlab with hasktorch, type following command, then click a url in a console.\n\n```sh\n$ docker run --gpus all -it --rm -p 8888:8888 htorch\u002Fhasktorch-jupyter\nor\n$ docker run --gpus all -it --rm -p 8888:8888 htorch\u002Fhasktorch-jupyter:latest-cu11\n```\n\n## Known Issues\n\n### MPS (Metal Performance Shaders) Support on macOS\n\nWhen using Hasktorch on Apple Silicon Macs with MPS device support, you must set the `PYTORCH_ENABLE_MPS_FALLBACK=1` environment variable before running your program:\n\n```sh\n$ export PYTORCH_ENABLE_MPS_FALLBACK=1\n$ cabal test hasktorch   # Run tests with MPS fallback enabled\n```\n\nOr run directly with:\n\n```sh\n$ PYTORCH_ENABLE_MPS_FALLBACK=1 cabal test hasktorch\n```\n\nThis is required because some operations (like `erfc`) are not yet natively implemented for the MPS backend in PyTorch and need to fall back to CPU computation. Without this environment variable, you will see errors like:\n\n```\nThe operator 'aten::erfc.out' is not currently implemented for the MPS device.\n```\n\nNote: When this environment variable is not set, MPS tests will be automatically skipped to prevent failures.\n\n### Tensors Cannot Be Moved to CUDA\n\nIn rare cases, you may see errors like\n\n```\ncannot move tensor to \"CUDA:0\"\n```\n\nalthough you have CUDA capable hardware in your machine and\nhave followed the getting-started instructions for CUDA support.\n\nIf that happens, check if `\u002Frun\u002Fopengl-driver\u002Flib` exists.\nIf not, make sure your CUDA drivers are installed correctly.\n\n\n### Weird Behaviour When Switching from CPU-Only to CUDA-Enabled Nix Shell\n\nIf you have run `cabal` in a CPU-only Hasktorch Nix shell before,\nyou may need to:\n\n* Clean the `dist-newstyle` folder using `cabal clean`.\n* Delete the `.ghc.environment*` file in the Hasktorch root folder.\n\nOtherwise, at best, you will not be able to move tensors to CUDA,\nand, at worst, you will see weird linker errors like\n\n```\ngcc: error: hasktorch\u002Fdist-newstyle\u002Fbuild\u002Fx86_64-linux\u002Fghc-8.8.3\u002Flibtorch-ffi-1.5.0.0\u002Fbuild\u002FTorch\u002FInternal\u002FUnmanaged\u002FAutograd.dyn_o: No such file or directory\n`cc' failed in phase `Linker'. (Exit code: 1)\n```\n\n\n## Contributing\n\nWe welcome new contributors.\n\nContact us for access to the [hasktorch discord channel][discord].\nYou can send an email to [hasktorch@gmail.com][email] or on twitter as [@austinvhuang][austin-twitter],\n[@SamStites][sam-twitter], [@tscholak][torsten-twitter], or [@junjihashimoto3][junji-twitter].\n\n[email]:mailto:hasktorch@gmail.com\n[austin-twitter]:https:\u002F\u002Ftwitter.com\u002Faustinvhuang\n[sam-twitter]:https:\u002F\u002Ftwitter.com\u002Fsamstites\n[torsten-twitter]:https:\u002F\u002Ftwitter.com\u002Ftscholak\n[junji-twitter]:https:\u002F\u002Ftwitter.com\u002Fjunjihashimoto3\n[slack]:https:\u002F\u002Fhasktorch.slack.com\n[gitter-dh]:https:\u002F\u002Fgitter.im\u002FdataHaskell\u002FLobby\n[discord]:https:\u002F\u002Fdiscord.gg\u002Fa5Sw5x6RnG\n\n## Notes for library developers\n\nSee [the wiki](https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fwiki) for developer notes.\n\n### Project Folder Structure\n\nBasic functionality:\n\n- `deps\u002F` - submodules and downloads for build dependencies (libtorch, mklml, pytorch) -- you can ignore this if you are on Nix\n- `examples\u002F` - high level example models (xor mlp, typed cnn, etc.)\n- `experimental\u002F` - experimental projects or tips\n- `hasktorch\u002F` - higher level user-facing library, calls into `ffi\u002F`, used by `examples\u002F`\n\nInternals (for contributing developers):\n\n- `codegen\u002F` - code generation, parses `Declarations.yaml` spec from pytorch and produces `ffi\u002F` contents\n- `inline-c\u002F` - submodule to inline-cpp fork used for C++ FFI\n- `libtorch-ffi\u002F`- low level FFI bindings to libtorch\n- `spec\u002F` - specification files used for `codegen\u002F`\n\n","# Hasktorch\n\nHasktorch 是一个用于 Haskell 中张量和神经网络的库。\n它是一个独立的开源社区项目，利用了 PyTorch 共享的核心 C++ 库。\n\n该项目目前处于积极开发中，因此随着其演进，库的 API 可能会发生变化。\n我们诚挚邀请新用户加入我们的 Hasktorch Discord 社区（[贡献指南](#contributing)），以进行问题讨论和交流。我们也鼓励大家提交 [贡献\u002F拉取请求](#contributing)。\n\nHasktorch 的第二个主要版本 (0.2) 目前已在 hackage 和 nixpkgs 上发布。\n\n## 文档\n\n文档分为几个部分：\n\n- [入门视频](#introductory-videos)\n- [快速上手](#getting-started)\n- [已知问题](#known-issues)\n- [贡献指南](#contributing)\n- [库开发者注意事项](#notes-for-library-developers)\n\n## 入门视频\n\n- [@austinvhuang][austin-twitter] 的 [高级 MuniHac 演讲](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=Qu6RIO02m1U)\n- [@tscholak][torsten-twitter] 的 [动手实操直播编码演示](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=ZnYa99QoznE&t=1689)\n- [@junjihashimoto][junji-twitter] 的 [低级 FFI 演讲](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=qWpD8t_Aodk&feature=youtu.be)\n\n\n## 快速上手\n\n以下步骤将帮助您快速开始使用。这些步骤假设您刚刚克隆了 hasktorch 仓库。设置完成后，请阅读 [在线教程](https:\u002F\u002Fhasktorch.github.io\u002Ftutorial\u002F) 和 [API 文档](https:\u002F\u002Fhasktorch.github.io\u002F)。\n\n* [Linux + Cabal + CPU](#linuxcabalcpu)\n* [Linux + Cabal + CUDA 11](#linuxcabalcuda11)\n* [macOS + Cabal + CPU](#macoscabalcpu)\n* [Linux + Stack + CPU](#linuxstackcpu)\n* [macOS + Stack + CPU](#macosstackcpu)\n* [NixOS + Cabal + CPU](#nixoscabalcpu)\n* [NixOS + Cabal + CUDA 11](#nixoscabalcuda11)\n* [Docker + JupyterLab + CUDA 11](#dockerjupyterlabcuda11)\n\n\n### Linux + Cabal + CPU\n\n从项目的根目录开始，运行：\n\n```sh\n$ .\u002Fsetup-cabal.sh # 创建一个 Cabal 项目文件\n```\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ cabal build hasktorch  # 构建 Hasktorch 库。\n$ cabal test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ cabal build examples  # 构建 Hasktorch 示例。\n$ cabal test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=cpu                      # 将设备设置为 CPU 以运行 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n\n### Linux + Cabal + CUDA\n\n首先将 `LIBTORCH_CUDA_VERSION` 环境变量设置为您当前使用的 CUDA 版本。例如：\n\n对于 CUDA 11.8，运行 `export LIBTORCH_CUDA_VERSION=cu118`。\n\n如果未指定，Hasktorch 默认会下载 CPU 版本。\n\n从项目的根目录开始，运行：\n\n```sh\n$ .\u002Fsetup-cabal.sh        # 创建一个 Cabal 项目文件\n```\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ cabal build hasktorch  # 构建 Hasktorch 库。\n$ cabal test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ cabal build examples  # 构建 Hasktorch 示例。\n$ cabal test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=\"cuda:0\"                 # 将设备设置为 CUDA 以运行 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n\n### macOS + Cabal + CPU\n\n从项目的根目录开始，运行：\n\n```sh\n$ .\u002Fsetup-cabal.sh # 创建一个 Cabal 项目文件\n```\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ cabal build hasktorch  # 构建 Hasktorch 库。\n$ cabal test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ cabal build examples  # 构建 Hasktorch 示例。\n$ cabal test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=cpu                      # 将设备设置为 CPU 以运行 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n\n\n### Linux + Stack + CPU\n\n如果您尚未安装 Haskell Tool Stack，请按照 [此处的说明](https:\u002F\u002Fdocs.haskellstack.org\u002Fen\u002Fstable\u002FREADME\u002F) 进行安装。\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ stack build hasktorch  # 构建 Hasktorch 库。\n$ stack test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ stack build examples  # 构建 Hasktorch 示例。\n$ stack test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=cpu                      # 将设备设置为 CPU 以运行 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n\n### macOS + Stack + CPU\n\n如果您尚未安装 Haskell Tool Stack，请按照 [此处的说明](https:\u002F\u002Fdocs.haskellstack.org\u002Fen\u002Fstable\u002FREADME\u002F) 进行安装。\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ stack build hasktorch  # 构建 Hasktorch 库。\n$ stack test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ stack build examples  # 构建 Hasktorch 示例。\n$ stack test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=cpu                      # 将设备设置为 CPU 以运行 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n\n\n### NixOS + Cabal + CPU\n\n（可选）安装并设置 Cachix：\n\n```sh\n$ nix-env -iA cachix -f https:\u002F\u002Fcachix.org\u002Fapi\u002Fv1\u002Finstall  # （可选）安装 Cachix。\n\n# （可选）使用 IOHK 的缓存。请参阅 https:\u002F\u002Finput-output-hk.github.io\u002Fhaskell.nix\u002Ftutorials\u002Fgetting-started\u002F#setting-up-the-binary-cache\n$ cachix use hasktorch                                     # （可选）使用 hasktorch 的缓存。\n```\n\n从项目的顶级目录开始，运行：\n\n```sh\n$ nix develop  # 进入 Hasktorch 的 Nix shell 环境。\n```\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ cabal build hasktorch  # 构建 Hasktorch 库。\n$ cabal test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ cabal build examples  # 构建 Hasktorch 示例。\n$ cabal test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=cpu                      # 将设备设置为 CPU，用于 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n\n\n### nixos+cabal+cuda11\n\n（可选）安装并设置 Cachix：\n\n```sh\n$ nix-env -iA cachix -f https:\u002F\u002Fcachix.org\u002Fapi\u002Fv1\u002Finstall  # （可选）安装 Cachix。\n# （可选）使用 IOHK 的缓存。请参阅 https:\u002F\u002Finput-output-hk.github.io\u002Fhaskell.nix\u002Ftutorials\u002Fgetting-started\u002F#setting-up-the-binary-cache\n$ cachix use hasktorch                                     # （可选）使用 hasktorch 的缓存。\n```\n\n从项目的顶级目录开始，运行：\n\n```sh\n$ cat > nix\u002Fdev-config.nix\n{\n  profiling = true;\n  cudaSupport = true;\n  cudaMajorVersion = \"11\";\n}\n$ nix develop  # 进入 Hasktorch 的 Nix shell 环境。\n```\n\n要构建并测试 Hasktorch 库，运行：\n\n```sh\n$ cabal build hasktorch  # 构建 Hasktorch 库。\n$ cabal test hasktorch   # 构建并运行 Hasktorch 库的测试套件。\n```\n\n要构建并测试随 Hasktorch 一起提供的示例可执行文件，运行：\n\n```sh\n$ cabal build examples  # 构建 Hasktorch 示例。\n$ cabal test examples   # 构建并运行 Hasktorch 示例的测试套件。\n```\n\n要运行 MNIST CNN 示例，运行：\n\n```sh\n$ cd examples                            # 切换到 examples 目录。\n$ .\u002Fdatasets\u002Fdownload-mnist.sh           # 下载 MNIST 数据集。\n$ export DEVICE=\"cuda:0\"                 # 将设备设置为 CUDA，用于 MNIST CNN 示例。\n$ cabal run static-mnist-cnn -- .\u002Fmnist\u002F # 运行 MNIST CNN 示例。\n```\n\n### docker+jupyterlab+cuda11\n\n[这个 Docker Hub 仓库](https:\u002F\u002Fhub.docker.com\u002Frepository\u002Fdocker\u002Fhtorch\u002Fhasktorch-jupyter) 提供了 JupyterLab 的 Docker 镜像。\n它支持 CUDA 11、CUDA 10 和仅 CPU 模式。当您使用带有 Hasktorch 的 JupyterLab 时，请键入以下命令，然后单击控制台中的 URL。\n\n```sh\n$ docker run --gpus all -it --rm -p 8888:8888 htorch\u002Fhasktorch-jupyter\n或\n$ docker run --gpus all -it --rm -p 8888:8888 htorch\u002Fhasktorch-jupyter:latest-cu11\n```\n\n## 已知问题\n\n### macOS 上的 MPS（Metal Performance Shaders）支持\n\n在支持 MPS 设备的 Apple Silicon Mac 上使用 Hasktorch 时，必须在运行程序之前设置环境变量 `PYTORCH_ENABLE_MPS_FALLBACK=1`：\n\n```sh\n$ export PYTORCH_ENABLE_MPS_FALLBACK=1\n$ cabal test hasktorch   # 在启用 MPS 回退的情况下运行测试\n```\n\n或者直接运行：\n\n```sh\n$ PYTORCH_ENABLE_MPS_FALLBACK=1 cabal test hasktorch\n```\n\n这是必需的，因为某些操作（如 `erfc`）尚未在 PyTorch 的 MPS 后端中原生实现，需要回退到 CPU 计算。如果没有设置此环境变量，您将看到类似以下的错误：\n\n```\n运算符 'aten::erfc.out' 当前未在 MPS 设备上实现。\n```\n\n注意：当未设置此环境变量时，MPS 测试将自动跳过，以防止失败。\n\n### 张量无法移动到 CUDA\n\n在极少数情况下，您可能会看到类似以下的错误：\n\n```\n无法将张量移动到 \"CUDA:0\"\n```\n\n尽管您的机器配备了 CUDA 功能硬件，并且已按照 CUDA 支持的入门说明进行了操作。\n\n如果发生这种情况，请检查 `\u002Frun\u002Fopengl-driver\u002Flib` 是否存在。如果不存在，请确保正确安装了 CUDA 驱动程序。\n\n\n### 从仅 CPU 切换到启用 CUDA 的 Nix Shell 时的奇怪行为\n\n如果您之前曾在仅 CPU 的 Hasktorch Nix Shell 中运行过 `cabal`，您可能需要：\n\n* 使用 `cabal clean` 清理 `dist-newstyle` 文件夹。\n* 删除 Hasktorch 根目录中的 `.ghc.environment*` 文件。\n\n否则，最好的情况是您将无法将张量移动到 CUDA，最坏的情况则是会出现奇怪的链接器错误，例如：\n\n```\ngcc: 错误：hasktorch\u002Fdist-newstyle\u002Fbuild\u002Fx86_64-linux\u002Fghc-8.8.3\u002Flibtorch-ffi-1.5.0.0\u002Fbuild\u002FTorch\u002FInternal\u002FUnmanaged\u002FAutograd.dyn_o：没有这样的文件或目录\n`cc' 在阶段 `Linker' 中失败。（退出代码：1）\n```\n\n\n## 贡献\n\n我们欢迎新的贡献者。\n\n请联系获取 [hasktorch Discord 频道][discord] 的访问权限。\n您可以发送电子邮件至 [hasktorch@gmail.com][email]，或通过 Twitter 联系 [@austinvhuang][austin-twitter]、[@SamStites][sam-twitter]、[@tscholak][torsten-twitter] 或 [@junjihashimoto3][junji-twitter]。\n\n[email]:mailto:hasktorch@gmail.com\n[austin-twitter]:https:\u002F\u002Ftwitter.com\u002Faustinvhuang\n[sam-twitter]:https:\u002F\u002Ftwitter.com\u002Fsamstites\n[torsten-twitter]:https:\u002F\u002Ftwitter.com\u002Ftscholak\n[junji-twitter]:https:\u002F\u002Ftwitter.com\u002Fjunjihashimoto3\n[slack]:https:\u002F\u002Fhasktorch.slack.com\n[gitter-dh]:https:\u002F\u002Fgitter.im\u002FdataHaskell\u002FLobby\n[discord]:https:\u002F\u002Fdiscord.gg\u002Fa5Sw5x6RnG\n\n## 库开发者注意事项\n\n有关开发人员注意事项，请参阅 [维基](https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fwiki)。\n\n### 项目文件夹结构\n\n基本功能：\n\n- `deps\u002F` - 用于构建依赖项（libtorch、mklml、pytorch）的子模块和下载内容——如果您使用 Nix，则可以忽略此部分\n- `examples\u002F` - 高层次示例模型（异或 MLP、类型化 CNN 等）\n- `experimental\u002F` - 实验性项目或技巧\n- `hasktorch\u002F` - 更高层次的面向用户的库，调用 `ffi\u002F`，由 `examples\u002F` 使用\n\n内部结构（供贡献开发者参考）：\n\n- `codegen\u002F` - 代码生成，解析来自 PyTorch 的 `Declarations.yaml` 规范，并生成 `ffi\u002F` 内容\n- `inline-c\u002F` - 用于 C++ FFI 的 inline-cpp 分支子模块\n- `libtorch-ffi\u002F` - 低级的 libtorch FFI 绑定\n- `spec\u002F` - 用于 `codegen\u002F` 的规范文件","# Hasktorch 快速上手指南\n\nHasktorch 是一个基于 Haskell 的张量与神经网络库，它复用了 PyTorch 的核心 C++ 库。本指南将帮助你在不同环境下快速搭建并运行第一个示例。\n\n## 环境准备\n\n在开始之前，请确保你的系统满足以下基本要求：\n\n*   **操作系统**: Linux, macOS 或 NixOS (Windows 用户建议使用 Docker 或 WSL2)。\n*   **Haskell 工具链**: 需安装 `cabal` 或 `stack`。\n    *   推荐安装 GHC (Glasgow Haskell Compiler) 版本与项目兼容（通常较新版本即可）。\n    *   Stack 用户请参考 [官方安装文档](https:\u002F\u002Fdocs.haskellstack.org\u002Fen\u002Fstable\u002FREADME\u002F)。\n*   **GPU 支持 (可选)**: 若需使用 CUDA，请确保已正确安装 NVIDIA 驱动及对应的 CUDA Toolkit (如 CUDA 11.x)。\n*   **网络环境**: 首次构建时会自动下载 LibTorch 二进制文件，请确保网络连接通畅。\n\n## 安装步骤\n\n根据你的操作系统和构建工具选择以下一种方案。所有命令请在克隆 `hasktorch` 仓库后的根目录下执行。\n\n### 方案 A：Linux \u002F macOS + Cabal (CPU 模式)\n\n最通用的安装方式，适用于大多数开发场景。\n\n```sh\n# 1. 生成 Cabal 项目配置文件\n.\u002Fsetup-cabal.sh\n\n# 2. 构建并测试 Hasktorch 核心库\ncabal build hasktorch\ncabal test hasktorch\n\n# 3. 构建示例程序\ncabal build examples\n```\n\n### 方案 B：Linux + Cabal (CUDA 模式)\n\n如需使用 GPU 加速，需先指定 CUDA 版本。\n\n```sh\n# 1. 设置 CUDA 版本环境变量 (例如 CUDA 11.8)\nexport LIBTORCH_CUDA_VERSION=cu118\n\n# 2. 生成配置文件并构建\n.\u002Fsetup-cabal.sh\ncabal build hasktorch\ncabal build examples\n```\n\n### 方案 C：NixOS \u002F Nix Shell (推荐用于隔离环境)\n\n如果你使用 Nix，可以获得最一致的环境体验。\n\n**CPU 模式:**\n```sh\nnix develop\ncabal build hasktorch\n```\n\n**CUDA 模式:**\n```sh\n# 创建启用 CUDA 的配置\ncat > nix\u002Fdev-config.nix \u003C\u003CEOF\n{\n  profiling = true;\n  cudaSupport = true;\n  cudaMajorVersion = \"11\";\n}\nEOF\n\n# 进入开发环境\nnix develop\ncabal build hasktorch\n```\n\n### 方案 D：Docker + JupyterLab (免配置体验)\n\n如果你希望立即尝试而不想配置本地环境，可以使用预构建的 Docker 镜像（支持 CUDA 11）。\n\n```sh\n# 启动 JupyterLab 容器 (需安装 Docker 且支持 GPU)\ndocker run --gpus all -it --rm -p 8888:8888 htorch\u002Fhasktorch-jupyter:latest-cu11\n```\n启动后，点击终端输出的 URL 即可在浏览器中使用。\n\n## 基本使用\n\n构建完成后，你可以运行自带的 MNIST CNN 示例来验证安装是否成功。\n\n### 1. 准备数据\n进入示例目录并下载数据集：\n\n```sh\ncd examples\n.\u002Fdatasets\u002Fdownload-mnist.sh\n```\n\n### 2. 运行示例\n\n**CPU 模式:**\n```sh\nexport DEVICE=cpu\ncabal run static-mnist-cnn -- .\u002Fmnist\u002F\n```\n\n**CUDA 模式:**\n```sh\nexport DEVICE=\"cuda:0\"\ncabal run static-mnist-cnn -- .\u002Fmnist\u002F\n```\n\n### 3. 开始编码\n环境验证无误后，你可以参考 [在线教程](https:\u002F\u002Fhasktorch.github.io\u002Ftutorial\u002F) 和 [API 文档](https:\u002F\u002Fhasktorch.github.io\u002F) 开始编写自己的 Haskell 神经网络代码。\n\n> **提示**: 如果你在 Apple Silicon Mac 上使用 MPS 设备遇到算子不支持的错误，请在运行前设置环境变量：\n> `export PYTORCH_ENABLE_MPS_FALLBACK=1`","某金融科技公司的高频交易团队需要在 Haskell 构建的核心风控系统中集成深度学习模型，以实时识别异常交易模式。\n\n### 没有 hasktorch 时\n- **语言割裂严重**：算法团队需用 Python 编写模型，再通过复杂的 FFI 或微服务与 Haskell 主系统通信，增加了延迟和运维成本。\n- **类型安全缺失**：跨语言调用导致张量形状、数据类型错误无法在编译期发现，只能在运行时排查，生产环境风险极高。\n- **函数式范式受阻**：难以利用 Haskell 强大的纯函数特性组合神经网络层，代码充满副作用，逻辑验证困难。\n- **部署架构复杂**：需同时维护 Python 运行时环境和 Haskell 服务，容器镜像庞大且依赖管理混乱。\n\n### 使用 hasktorch 后\n- **原生无缝集成**：直接复用 PyTorch 底层 C++ 库，在 Haskell 代码中原地定义和训练张量与神经网络，消除跨语言开销。\n- **编译期强保障**：借助 Haskell 类型系统，将维度不匹配等常见深度学习错误拦截在编译阶段，大幅提升系统稳定性。\n- **纯函数式建模**：以声明式风格构建网络结构，利用不可变数据流轻松实现模型组合与数学推导，代码即证明。\n- **统一运行环境**：仅需单一 Haskell 二进制文件即可部署包含推理能力的服务，显著简化 CI\u002FCD 流程并降低资源占用。\n\nhasktorch 让开发者能在享受 Haskell 类型安全与函数式优势的同时，直接驾驭成熟的深度学习生态，实现了高性能与高可靠性的完美统一。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhasktorch_hasktorch_3ecbf6a5.png","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fhasktorch_d6e8c2fb.png","",null,"https:\u002F\u002Fgithub.com\u002Fhasktorch",[78,82,86,90,94,97,100,104,108,111],{"name":79,"color":80,"percentage":81},"Haskell","#5e5086",98.6,{"name":83,"color":84,"percentage":85},"C++","#f34b7d",0.4,{"name":87,"color":88,"percentage":89},"Python","#3572A5",0.3,{"name":91,"color":92,"percentage":93},"HTML","#e34c26",0.2,{"name":95,"color":96,"percentage":93},"Jupyter Notebook","#DA5B0B",{"name":98,"color":99,"percentage":93},"Nix","#7e7eff",{"name":101,"color":102,"percentage":103},"Shell","#89e051",0.1,{"name":105,"color":106,"percentage":107},"CSS","#663399",0,{"name":109,"color":110,"percentage":107},"C","#555555",{"name":112,"color":113,"percentage":107},"Dockerfile","#384d54",1190,121,"2026-04-03T12:47:15","NOASSERTION",4,"Linux, macOS","非必需。若需 GPU 加速，需要支持 CUDA 的 NVIDIA 显卡（文档示例提及 CUDA 11\u002F11.8）；macOS Apple Silicon 芯片支持 MPS (Metal Performance Shaders)，但部分算子需回退到 CPU。","未说明",{"notes":123,"python":124,"dependencies":125},"1. 该项目是 Haskell 编写的张量和神经网络库，底层复用 PyTorch 的 C++ 库 (libtorch)，因此无需安装 Python 或 PyTorch Python 包。\n2. macOS 用户使用 MPS 设备时，必须设置环境变量 PYTORCH_ENABLE_MPS_FALLBACK=1，否则部分操作（如 erfc）会报错。\n3. 在 Nix 环境中从纯 CPU 模式切换到 CUDA 模式时，可能需要清理 dist-newstyle 文件夹和 .ghc.environment* 文件以避免链接错误。\n4. 支持通过 Docker 运行 JupyterLab 环境。","不需要 (Hasktorch 是 Haskell 库，不依赖 Python 运行时)",[126,127,128,129],"GHC (Haskell 编译器)","Cabal 或 Stack (构建工具)","libtorch (PyTorch C++ 核心库)","CUDA Toolkit (可选，用于 GPU 支持)",[14],"2026-03-27T02:49:30.150509","2026-04-08T03:57:08.231303",[134,139,144,149,154,159],{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},23742,"在使用 Stack 进行性能分析（profiling）时遇到 libtorch-ffi 编译错误怎么办？","这是一个已知问题，当使用 `--profile` 标志时，GHC 定义的 `PROFILING` 宏会与 LibTorch 头文件中的枚举值冲突。该问题已通过补丁修复。请确保更新到包含修复的最新版本（master 分支或最新 release）。修复后，即使开启性能分析选项也能正常编译和运行。","https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fissues\u002F706",{"id":140,"question_zh":141,"answer_zh":142,"source_url":143},23743,"安装 hasktorch 时遇到 'Cabal could not resolve dependencies' 依赖解析错误如何解决？","这通常是因为 GHC 版本不匹配或使用了错误的构建命令。建议不要直接使用 vanilla `ghci`，而是使用 `cabal new-repl`（在新版 Cabal 中可能是 `cabal v2-repl`）。GHCi 尝试加载所有符号时可能无法正确处理 Cabal 管理的包依赖。此外，请检查您的 `cabal.project` 或配置文件，确保 `base` 库版本约束与当前安装的 GHC 版本一致（例如错误日志中提到的需要 ==4.11.1.0）。","https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fissues\u002F105",{"id":145,"question_zh":146,"answer_zh":147,"source_url":148},23744,"如何在 Apple M1\u002FM2 (Apple Silicon) 上编译 hasktorch？支持哪些 GHC 版本？","目前 master 分支已支持 Apple Silicon。关于 GHC 版本兼容性：\n1. GHC 9.4.6 在 M1\u002FM2 上工作正常。\n2. GHC 9.2.x 系列在某些情况下可能会遇到 C++ 异常捕获失败的问题（例如抛出 `std::logic_error` 导致程序终止）。\n3. 较新的 GHC 9.6.4 也已得到支持。\n如果在 M1\u002FM2 上遇到链接错误（如 `symbol not found`），请尝试切换到 GHC 9.4.6 或更新到最新的 master 分支。","https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fissues\u002F631",{"id":150,"question_zh":151,"answer_zh":152,"source_url":153},23745,"在没有全局安装 GHC 的情况下（仅使用 Stack 管理），如何在 macOS 上初始化构建环境？","旧版本的 Makefile 强制要求全局安装特定版本的 GHC，这在仅使用 Stack 的环境中会报错（`ghc: command not found`）。该问题已通过移除 Makefile 并简化构建流程解决（见 PR #151）。\n现在的推荐做法是：\n1. 不再使用 `make init`。\n2. 直接使用 `stack build` 或 `cabal v2-build`。\n3. 如果必须使用旧代码，可以通过指向 Stack 管理的 GHC 路径来解决，或者将 `cabal v2-build` 包装在 Stack 脚本中，利用 `stack exec` 来调用 Cabal，从而避免全局安装 GHC。","https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fissues\u002F148",{"id":155,"question_zh":156,"answer_zh":157,"source_url":158},23746,"如何使用 Nix 实现 hasktorch 的可重现构建（Reproducible Builds）？","主仓库中的 `shell.nix` 和 `build.nix` 曾使用 `\u003Cnixpkgs>` 浮动引用，导致构建不可重现。目前主分支（ffi-experimental merged into master）不再积极维护原生的 Nix 工作流。\n推荐的解决方案是使用独立的 [pytorch-world](https:\u002F\u002Fgithub.com\u002Fstites\u002Fpytorch-world) 仓库（原 libtorch-nix），该仓库正确固定了 nixpkgs 的哈希值（pin），遵循 lorri 风格，可确保可重现性。\n如果需要在 hasktorch 中使用 Nix，可以将 `pytorch-world` 作为子模块引入到 `nix` 文件夹中，并使用其中固定的 pin 文件进行构建。","https:\u002F\u002Fgithub.com\u002Fhasktorch\u002Fhasktorch\u002Fissues\u002F143",{"id":160,"question_zh":161,"answer_zh":162,"source_url":148},23747,"在 macOS 上链接时遇到 'stdc++.dylib not found' 或 C++ 异常未捕获导致的崩溃如何处理？","在 Apple Silicon (M1\u002FM2) 上，GHC 与 C++ 异常处理的交互存在已知问题，特别是在 GHC 9.2.x 版本上。表现为程序在捕获 C++ 异常时直接终止（`libc++abi: terminating with uncaught exception`）。\n临时解决方案：\n1. 切换使用 GHC 9.4.6 版本，该版本在测试中能正确处理异常。\n2. 编译时添加链接选项 `-optl='-Wl,-keep_dwarf_unwind' -lc++` 以确保正确的 unwind 信息和 C++ 库链接。\n长期方案请关注项目对 GHC 9.6+ 的支持进展，新版通常修复了此类底层兼容性问题。",[]]