[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-dvgodoy--PyTorchStepByStep":3,"tool-dvgodoy--PyTorchStepByStep":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},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,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},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 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":79,"owner_twitter":75,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":23,"env_os":96,"env_gpu":97,"env_ram":98,"env_deps":99,"category_tags":111,"github_topics":112,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":119,"updated_at":120,"faqs":121,"releases":149},3545,"dvgodoy\u002FPyTorchStepByStep","PyTorchStepByStep","Official repository of my book: \"Deep Learning with PyTorch Step-by-Step: A Beginner's Guide\"","PyTorchStepByStep 是畅销书《Deep Learning with PyTorch Step-by-Step》的官方配套代码库，旨在为深度学习初学者提供一套完整、可交互的学习资源。它解决了传统技术书籍中代码难以复现、环境配置复杂以及理论脱离实践的痛点，让读者能够直接运行书中每一章对应的 Jupyter Notebook，并重现与书本完全一致的输出结果，从而建立学习信心。\n\n这套资源非常适合希望系统掌握 PyTorch 框架的开发者、学生及研究人员。内容涵盖从梯度下降可视化、基础回归与分类，到计算机视觉（如卷积神经网络、迁移学习）、序列模型以及自然语言处理等核心领域。其独特的技术亮点在于紧跟技术前沿，已针对 PyTorch 2.x、Torchvision 及 HuggingFace 等库的最新变化进行了全面修订，确保代码的时效性与可用性。此外，项目提供了便捷的 Google Colab 链接，用户无需本地配置环境，即可利用云端 GPU 资源按顺序执行代码单元格，真正实现“手把手”的沉浸式学习体验。无论是想要夯实基础的入门者，还是寻求最新实践参考的从业者，都能从中获益。","# Deep Learning with PyTorch Step-by-Step\n\n## New book: \"A Hands-On Guide to Fine-Tuning LLMs\"\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdvgodoy_PyTorchStepByStep_readme_3eeb2f1dbe46.png\" width=\"200\"\u002F>\n  \u003Cbr>\n  \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002FB0DV3Y1GMP\">Kindle\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002FB0DV4H7YW2\">Paperback\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fleanpub.com\u002Ffinetuning\">PDF [Leanpub]\u003Ca> | \u003Ca href=\"https:\u002F\u002Fdanielgodoy.gumroad.com\u002Fl\u002Ffinetuning\">PDF [Gumroad]\u003Ca>\u003C\u002Fstrong>\n\u003C\u002Fp>\n\n## Revised for PyTorch 2.x!\nThe revised version addresses changes in PyTorch, Torchvision, HuggingFace, and other libraries. The chapters most affected were Chapter 4 (in Volume II) and Chapter 11 (in Volume III).\n\nPlease check the PDFs below containing the changes (check the paragraphs highlighted in red):\n- [Changes to Volume I](https:\u002F\u002Fraw.githubusercontent.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster\u002Frevision\u002Fv1.2\u002FRevision_Volume1_v1.2.pdf)\n- [Changes to Volume II](https:\u002F\u002Fraw.githubusercontent.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster\u002Frevision\u002Fv1.2\u002FRevision_Volume2_v1.2.pdf)\n- [Changes to Volume III](https:\u002F\u002Fraw.githubusercontent.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster\u002Frevision\u002Fv1.2\u002FRevision_Volume3_v1.2.pdf)\n\n[![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdvgodoy_PyTorchStepByStep_readme_ae1bb79aa2d2.png)](https:\u002F\u002Fpytorchstepbystep.com)\n\nThis is the official repository of my book \"**Deep Learning with PyTorch Step-by-Step**\". Here you will find **one Jupyter notebook** for every **chapter** in the book.\n\nEach notebook contains **all the code shown** in its corresponding chapter, and you should be able to\n**run its cells in sequence** to get the **same outputs as shown in the book**. I strongly believe that being able to **reproduce the results** brings **confidence** to the reader.\n\nThere are **three** options for you to run the Jupyter notebooks:\n\n### Google Colab\n\nYou can easily **load the notebooks directly from GitHub** using Colab and run them using a **GPU** provided by Google. You need to be logged in a Google Account of your own.\n\nYou can go through the chapters already using the links below:\n\n#### Part I - Fundamentals\n\n- [Chapter 0 - Visualizing Gradient Descent](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter00.ipynb)\n- [Chapter 1 - A Simple Regression Problem](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter01.ipynb)\n- [Chapter 2 - Rethinking the Training Loop](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter02.ipynb)\n- [Chapter 2.1 - Going Classy](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter02.1.ipynb)\n- [Chapter 3 - A Simple Classification Problem](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter03.ipynb)\n\n#### Part II - Computer Vision\n\n- [Chapter 4 - Classifying Images](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter04.ipynb)\n- [Chapter 5 - Convolutions](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter05.ipynb)\n- [Chapter 6 - Rock, Paper, Scissors](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter06.ipynb)\n- [Chapter 7 - Transfer Learning](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter07.ipynb)\n- [Extra Chapter - Vanishing and Exploding Gradients](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapterExtra.ipynb)\n\n#### Part III - Sequences\n\n- [Chapter 8 - Sequences](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter08.ipynb)\n- [Chapter 9 - Sequence-to-Sequence](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter09.ipynb)\n- [Chapter 10 - Transform and Roll Out](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter10.ipynb)\n\n#### Part IV - Natural Language Processing\n\n- [Chapter 11 - Down the Yellow Brick Rabbit Hole](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter11.ipynb)\n\n### Binder\n\nYou can also **load the notebooks directly from GitHub** using Binder, but the process is slightly different. It will create an environment on the cloud and allow you to access **Jupyter's Home Page** in your browser, listing all available notebooks, just like in your own computer.\n\nIf you **make changes** to the notebooks, **make sure to download** them, since Binder **does not keep the changes** once you close it.\n\nYou can start your environment on the cloud right now using the button below:\n\n[![Binder](https:\u002F\u002Fmybinder.org\u002Fbadge_logo.svg)](https:\u002F\u002Fmybinder.org\u002Fv2\u002Fgh\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster)\n\n### Local Installation\n\nThis option will give you more **flexibility**, but it will require **more effort to set up**. I encourage you to try setting up your own environment. It may seem daunting at first, but you can surely accomplish it following **seven easy steps**:\n\n**1 - Anaconda**\n\nIf you don’t have [**Anaconda’s Individual Edition**](https:\u002F\u002Fwww.anaconda.com\u002Fproducts\u002Findividual) installed yet, that would be a good time to do it - it is a very handy way to start - since it contains most of the Python libraries a data scientist will ever need to develop and train models. \n\nPlease follow **the installation instructions** for your OS:\n\n- [Windows](https:\u002F\u002Fdocs.anaconda.com\u002Fanaconda\u002Finstall\u002Fwindows\u002F)\n- [macOS](https:\u002F\u002Fdocs.anaconda.com\u002Fanaconda\u002Finstall\u002Fmac-os\u002F)\n- [Linux](https:\u002F\u002Fdocs.anaconda.com\u002Fanaconda\u002Finstall\u002Flinux\u002F)\n\nMake sure you choose **Python 3.X** version since Python 2 was discontinued in January 2020.\n\n**2 - Conda (Virtual) Environments**\n\nVirtual environments are a convenient way to isolate Python installations associated with different projects.\n\nFirst, you need to choose a **name** for your environment :-) Let’s call ours `pytorchbook` (or anything else you find easier to remember). Then, you need to open a **terminal** (in Ubuntu) or **Anaconda Prompt** (in Windows or macOS) and type the following command:\n\n`conda create -n pytorchbook anaconda`\n\nThe command above creates a conda environment named `pytorchbook` and includes **all anaconda packages** in it (time to get a coffee, it will take a while...). If you want to learn more about creating and using conda environments, please check Anaconda’s [**Managing Environments**](https:\u002F\u002Fdocs.conda.io\u002Fprojects\u002Fconda\u002Fen\u002Flatest\u002Fuser-guide\u002Ftasks\u002Fmanage-environments.html) user guide.\n\nDid it finish creating the environment? Good! It is time to **activate it**, meaning, making that Python installation the one to be used now. In the same terminal (or Anaconda Prompt), just type:\n\n`conda activate pytorchbook`\n\nYour prompt should look like this (if you’re using Linux)...\n\n`(pytorchbook)$`\n\nor like this (if you’re using Windows):\n\n`(pytorchbook)C:\\>`\n\nDone! You are using a **brand new conda environment** now. You’ll need to **activate it** every time you open a new terminal or, if you’re a Windows or macOS user, you can open the corresponding Anaconda Prompt (it will show up as **Anaconda Prompt (pytorchbook)**, in our case), which will have it activated from start.\n\n**IMPORTANT**: From now on, I am assuming you’ll activate the `pytorchbook` environment every time you open a terminal \u002F Anaconda Prompt. Further installation steps **must** be executed inside the environment.\n\n**3 - PyTorch**\n\nIt is time to install the star of the show :-) We can go straight to the [**Start Locally**](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F) section of its website and it will automatically select the options that best suit your local environment and it will show you the command to run.\n\nYour choices should look like:\n\n- PyTorch Build: \"Stable\"\n- Your OS: your operating system\n- Package: \"Conda\"\n- Language: \"Python\"\n- CUDA: \"None\" if you **don't** have a **GPU**, or the latest version (e.g. \"10.1\"), if you **have** a **GPU**.\n\nThe installation command will be shown right below your choices, so you can copy it. If you have a **Windows** computer and **no GPU**, you'd have to run the following command in your **Anaconda Prompt (pytorchbook)**:\n\n`(pytorchbook) C:\\> conda install pytorch torchvision cpuonly -c pytorch`\n\n**4 - TensorBoard**\n\nTensorBoard is a powerful tool and we can use it even if we are developing models in PyTorch. Luckily, you don’t need to install the whole TensorFlow to get it, you can easily **install TensorBoard alone** using **conda**. You just need to run this command in your **terminal** or **Anaconda Prompt** (again, after activating the environment):\n\n`(pytorchbook)C:\\> conda install -c conda-forge tensorboard`\n\n**5 - GraphViz and TorchViz (optional)**\n\n> This step is optional, mostly because the installation of GraphViz can be challenging sometimes (especially on Windows). If, for any reason, you do not succeed in installing it correctly, or if you\n> decide to skip this installation step, you will still be **able to execute the code in this book** (except for a couple of cells that generate images of a model’s structure in the Dynamic Computation Graph section of Chapter 1).\n\nWe need to install GraphViz to be able to use **TorchViz**, a neat package that allows us to visualize a  model’s structure. Please check the [**installation instructions**]( https:\u002F\u002Fwww.graphviz.org\u002Fdownload\u002F) for your OS. \n\n> If you are using **Windows**, please use the installer at [GraphViz's Windows Package](https:\u002F\u002Fgraphviz.gitlab.io\u002F_pages\u002FDownload\u002Fwindows\u002Fgraphviz-2.38.msi). You also need to  add GraphViz to the PATH (environment variable) in Windows. Most likely, you can find GraphViz executable file at `C:\\ProgramFiles(x86)\\Graphviz2.38\\bin`. Once you found it, you need to set or change the PATH accordingly, adding GraphViz's location to it. For more details on how to do that, please refer to [How to Add to Windows PATH Environment Variable](https:\u002F\u002Fbit.ly\u002F3fIwYA5).\n\nFor additional information, you can also check the [How to Install Graphviz Software](https:\u002F\u002Fbit.ly\u002F30Ayct3) guide. \n\nIf you installed GraphViz successfully, you can install the [torchviz](https:\u002F\u002Fgithub.com\u002Fszagoruyko\u002Fpytorchviz) package. This package is not part of Anaconda Distribution Repository and is only available at PyPI , the Python Package Index, so we need to pip install it.\n\nOnce again, open a **terminal** or **Anaconda Prompt** and run this command (just once\nmore: after activating the environment):\n\n`(pytorchbook)C:\\> pip install torchviz`\n\n**6 - Git**\n\nIt is way beyond the scope of this guide to introduce you to version control and its most popular tool: `git`. If you are familiar with it already, great, you can skip this section altogether!\n\nOtherwise, I’d recommend you to learn more about it, it will **definitely** be useful for you later down the line. In the meantime, I will show you the bare minimum, so you can use `git` to **clone this repository** containing all code used in this book - so you have your own, local copy of it and can modify and experiment with it as you please.\n\nFirst, you need to install it. So, head to its [downloads](https:\u002F\u002Fgit-scm.com\u002Fdownloads) page and follow instructions for your OS. Once installation is complete, please open a **new terminal** or **Anaconda Prompt** (it's OK to close the previous one). In the new terminal or Anaconda Prompt, you should be able to **run `git` commands**. To clone this repository, you only need to run:\n\n`(pytorchbook)C:\\> git clone https:\u002F\u002Fgithub.com\u002Fdvgodoy\u002FPyTorchStepByStep.git`\n\nThe command above will create a `PyTorchStepByStep` folder which contains a **local copy** of everything available on this GitHub’s repository.\n\n**7 - Jupyter**\n\nAfter cloning the repository, navigate to the `PyTorchStepByStep` and, **once inside it**, you only need to **start Jupyter** on your terminal or Anaconda Prompt:\n\n`(pytorchbook)C:\\> jupyter notebook`\n\nThis will open your browser up and you will see **Jupyter's Home Page** containing this repository's notebooks and code.\n\nCongratulations! You are ready to go through the chapters' notebooks!\n\n","# 使用 PyTorch 的深度学习逐步指南\n\n## 新书：《大型语言模型微调实战指南》\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdvgodoy_PyTorchStepByStep_readme_3eeb2f1dbe46.png\" width=\"200\"\u002F>\n  \u003Cbr>\n  \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002FB0DV3Y1GMP\">Kindle\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fwww.amazon.com\u002Fdp\u002FB0DV4H7YW2\">平装本\u003C\u002Fa> | \u003Ca href=\"https:\u002F\u002Fleanpub.com\u002Ffinetuning\">PDF [Leanpub]\u003Ca> | \u003Ca href=\"https:\u002F\u002Fdanielgodoy.gumroad.com\u002Fl\u002Ffinetuning\">PDF [Gumroad]\u003Ca>\u003C\u002Fstrong>\n\u003C\u002Fp>\n\n## 针对 PyTorch 2.x 进行了修订！\n修订版针对 PyTorch、Torchvision、HuggingFace 等库的更新进行了调整。受影响最大的章节是第二卷中的第4章和第三卷中的第11章。\n\n请查看下方包含变更内容的 PDF 文件（红色高亮部分）：\n- [第一卷变更](https:\u002F\u002Fraw.githubusercontent.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster\u002Frevision\u002Fv1.2\u002FRevision_Volume1_v1.2.pdf)\n- [第二卷变更](https:\u002F\u002Fraw.githubusercontent.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster\u002Frevision\u002Fv1.2\u002FRevision_Volume2_v1.2.pdf)\n- [第三卷变更](https:\u002F\u002Fraw.githubusercontent.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster\u002Frevision\u002Fv1.2\u002FRevision_Volume3_v1.2.pdf)\n\n[![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdvgodoy_PyTorchStepByStep_readme_ae1bb79aa2d2.png)](https:\u002F\u002Fpytorchstepbystep.com)\n\n这是我的书籍“**使用 PyTorch 的深度学习逐步指南**”的官方仓库。在这里，您将找到书中每一章对应的 **一个 Jupyter 笔记本**。\n\n每个笔记本都包含了相应章节中展示的 **所有代码**，您可以按照顺序运行其中的单元格，以获得与书中一致的 **输出结果**。我坚信，能够 **复现结果**会为读者带来 **信心**。\n\n您有三种方式可以运行这些 Jupyter 笔记本：\n\n### Google Colab\n\n您可以通过 Colab 轻松地从 GitHub **直接加载笔记本**，并在 Google 提供的 **GPU** 上运行它们。您需要登录自己的 Google 帐户。\n\n您可以通过以下链接直接浏览各章节：\n\n#### 第一部分 - 基础知识\n\n- [第0章 - 可视化梯度下降](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter00.ipynb)\n- [第1章 - 一个简单的回归问题](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter01.ipynb)\n- [第2章 - 重新思考训练循环](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter02.ipynb)\n- [第2.1章 - 面向对象编程](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter02.1.ipynb)\n- [第3章 - 一个简单的分类问题](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter03.ipynb)\n\n#### 第二部分 - 计算机视觉\n\n- [第4章 - 图像分类](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter04.ipynb)\n- [第5章 - 卷积](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter05.ipynb)\n- [第6章 - 石头剪刀布](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter06.ipynb)\n- [第7章 - 迁移学习](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter07.ipynb)\n- [额外章节 - 梯度消失与爆炸](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapterExtra.ipynb)\n\n#### 第三部分 - 序列数据\n\n- [第8章 - 序列数据](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter08.ipynb)\n- [第9章 - 序列到序列模型](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter09.ipynb)\n- [第10章 - Transformer 与展开](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter10.ipynb)\n\n#### 第四部分 - 自然语言处理\n\n- [第11章 - 走进黄砖路的兔子洞](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fblob\u002Fmaster\u002FChapter11.ipynb)\n\n### Binder\n\n您也可以通过 Binder **直接从 GitHub 加载笔记本**，但流程稍有不同。Binder 会在云端创建一个环境，并允许您在浏览器中访问 **Jupyter 主页**，列出所有可用的笔记本，就像在您自己的电脑上一样。\n\n如果您对笔记本进行了 **修改**，请务必将其 **下载保存**，因为 Binder 在您关闭后不会保留这些更改。\n\n您现在就可以通过下面的按钮启动云端环境：\n\n[![Binder](https:\u002F\u002Fmybinder.org\u002Fbadge_logo.svg)](https:\u002F\u002Fmybinder.org\u002Fv2\u002Fgh\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fmaster)\n\n### 本地安装\n\n这种方式能为您提供更多的 **灵活性**，但设置起来需要 **更多精力**。我鼓励您尝试搭建自己的环境。虽然一开始可能会觉得有些复杂，但只要按照 **七个简单步骤**，您一定可以成功：\n\n**1 - Anaconda**\n\n如果您还没有安装 [**Anaconda Individual 版**](https:\u002F\u002Fwww.anaconda.com\u002Fproducts\u002Findividual)，现在正是好时机——它是一个非常方便的工具，因为它包含了数据科学家开发和训练模型所需的大多数 Python 库。\n\n请根据您的操作系统遵循 **安装说明**：\n\n- [Windows](https:\u002F\u002Fdocs.anaconda.com\u002Fanaconda\u002Finstall\u002Fwindows\u002F)\n- [macOS](https:\u002F\u002Fdocs.anaconda.com\u002Fanaconda\u002Finstall\u002Fmac-os\u002F)\n- [Linux](https:\u002F\u002Fdocs.anaconda.com\u002Fanaconda\u002Finstall\u002Flinux\u002F)\n\n请确保选择 **Python 3.X** 版本，因为 Python 2 已于 2020 年 1 月停止维护。\n\n**2 - Conda（虚拟）环境**\n\n虚拟环境是一种方便的方式，可以隔离与不同项目相关的 Python 安装。\n\n首先，您需要为您的环境选择一个 **名字** :-) 我们就叫它 `pytorchbook`（或者任何您更容易记住的名字）。然后，在终端（Ubuntu）或 Anaconda Prompt（Windows 或 macOS）中输入以下命令：\n\n`conda create -n pytorchbook anaconda`\n\n上述命令会创建一个名为 `pytorchbook` 的 conda 环境，并包含 **所有 Anaconda 包**（该喝杯咖啡了，这可能需要一些时间……）。如果您想了解更多关于创建和使用 conda 环境的信息，请查阅 Anaconda 的 [**管理环境**](https:\u002F\u002Fdocs.conda.io\u002Fprojects\u002Fconda\u002Fen\u002Flatest\u002Fuser-guide\u002Ftasks\u002Fmanage-environments.html) 用户指南。\n\n环境创建完成了吗？太好了！现在是时候 **激活它**了，也就是让这个 Python 安装成为当前使用的版本。在同一终端（或 Anaconda Prompt）中输入：\n\n`conda activate pytorchbook`\n\n您的提示符应该看起来像这样（如果您使用的是 Linux）……\n\n`(pytorchbook)$`\n\n或者像这样（如果您使用的是 Windows）：\n\n`(pytorchbook)C:\\>`\n\n完成了！你现在正使用一个**全新的 conda 环境**。每次打开新的终端时，你都需要**激活它**；如果你是 Windows 或 macOS 用户，可以直接打开对应的 Anaconda Prompt（在我们的例子中会显示为 **Anaconda Prompt (pytorchbook)**），这样它就会从一开始就处于激活状态。\n\n**重要提示**：从现在开始，我假设你每次打开终端或 Anaconda Prompt 时都会激活 `pytorchbook` 环境。后续的所有安装步骤都**必须**在这个环境中执行。\n\n**3 - PyTorch**\n\n现在该安装今天的主角了 :-) 我们可以直接访问 PyTorch 官网的[本地安装](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F)部分，网站会自动根据你的本地环境选择最适合的选项，并给出需要运行的命令。\n\n你的选择应该如下：\n\n- PyTorch 版本：“稳定版”\n- 操作系统：你的操作系统\n- 包管理器：“Conda”\n- 编程语言：“Python”\n- CUDA：如果你**没有 GPU**，选择“无”；如果你**有 GPU**，则选择最新版本（例如“10.1”）。\n\n安装命令会直接显示在你的选择下方，你可以将其复制下来。如果你使用的是**Windows**电脑且**没有 GPU**，就需要在 **Anaconda Prompt (pytorchbook)** 中运行以下命令：\n\n`(pytorchbook) C:\\> conda install pytorch torchvision cpuonly -c pytorch`\n\n**4 - TensorBoard**\n\nTensorBoard 是一个功能强大的工具，即使我们在用 PyTorch 开发模型时也可以使用它。幸运的是，你不需要安装整个 TensorFlow 才能使用 TensorBoard，只需通过 **conda** 单独安装 TensorBoard 即可。你只需要在**终端**或**Anaconda Prompt**中运行以下命令（同样是在激活环境之后）：\n\n`(pytorchbook)C:\\> conda install -c conda-forge tensorboard`\n\n**5 - GraphViz 和 TorchViz（可选）**\n\n> 这一步是可选的，主要是因为 GraphViz 的安装有时可能会比较困难（尤其是在 Windows 上）。如果由于某种原因你未能正确安装它，或者决定跳过这一步，你仍然**可以运行本书中的代码**，除了第 1 章动态计算图部分中用于生成模型结构图的少数几个单元格之外。\n\n我们需要安装 GraphViz 才能使用 **TorchViz**，这是一个非常实用的工具，可以帮助我们可视化模型的结构。请根据你的操作系统查看[安装说明](https:\u002F\u002Fwww.graphviz.org\u002Fdownload\u002F)。\n\n> 如果你使用的是**Windows**，请下载 [GraphViz 的 Windows 安装包](https:\u002F\u002Fgraphviz.gitlab.io\u002F_pages\u002FDownload\u002Fwindows\u002Fgraphviz-2.38.msi)。此外，你还需将 GraphViz 添加到 Windows 的 PATH 环境变量中。通常，GraphViz 的可执行文件位于 `C:\\ProgramFiles(x86)\\Graphviz2.38\\bin`。找到该路径后，你需要相应地设置或修改 PATH，将 GraphViz 的位置添加进去。有关具体操作方法，请参考[如何向 Windows PATH 环境变量添加路径](https:\u002F\u002Fbit.ly\u002F3fIwYA5)。\n\n你还可以参考[如何安装 GraphViz 软件](https:\u002F\u002Fbit.ly\u002F30Ayct3)的指南以获取更多信息。如果成功安装了 GraphViz，接下来就可以安装 [torchviz](https:\u002F\u002Fgithub.com\u002Fszagoruyko\u002Fpytorchviz) 包了。这个包并不包含在 Anaconda 发行版中，而只存在于 Python 包索引 PyPI 上，因此我们需要使用 pip 来安装。\n\n再次打开**终端**或**Anaconda Prompt**，并运行以下命令（记住：务必先激活环境）：\n\n`(pytorchbook)C:\\> pip install torchviz`\n\n**6 - Git**\n\n本指南无法深入介绍版本控制及其最流行的工具——`git`。如果你已经熟悉它，那太好了，可以直接跳过这一节！\n\n否则，我建议你花点时间学习一下，这在以后的工作中**绝对**会派上用场。在此期间，我将向你展示最基本的使用方法，以便你能用 `git` 来**克隆本书所用的所有代码仓库**——这样你就拥有了一个属于自己的本地副本，可以随意修改和实验。\n\n首先，你需要安装 `git`。前往其[下载页面](https:\u002F\u002Fgit-scm.com\u002Fdownloads)，按照你的操作系统说明进行操作。安装完成后，请打开一个新的**终端**或**Anaconda Prompt**（之前的可以关闭）。在新窗口中，你应该能够**运行 `git` 命令**。要克隆本书的代码仓库，只需运行以下命令：\n\n`(pytorchbook)C:\\> git clone https:\u002F\u002Fgithub.com\u002Fdvgodoy\u002FPyTorchStepByStep.git`\n\n上述命令会在当前目录下创建一个名为 `PyTorchStepByStep` 的文件夹，其中包含了 GitHub 仓库中的所有内容的**本地副本**。\n\n**7 - Jupyter**\n\n克隆完仓库后，进入 `PyTorchStepByStep` 目录，然后**在该目录内**，只需在终端或 Anaconda Prompt 中启动 Jupyter 即可：\n\n`(pytorchbook)C:\\> jupyter notebook`\n\n这将会打开你的浏览器，并显示 Jupyter 的首页，其中包含了本书的所有笔记本和代码。\n\n恭喜你！现在你已经准备好开始阅读各章节的笔记本了！","# PyTorchStepByStep 快速上手指南\n\n本指南基于《Deep Learning with PyTorch Step-by-Step》官方仓库，帮助开发者快速搭建环境并运行书中的配套代码。\n\n## 环境准备\n\n*   **操作系统**：Windows, macOS, 或 Linux\n*   **Python 版本**：Python 3.x (Python 2 已停止维护)\n*   **硬件要求**：\n    *   基础运行：任意 CPU\n    *   加速训练（可选）：NVIDIA GPU (需安装对应版本的 CUDA)\n*   **前置知识**：具备基础的 Python 编程知识\n\n## 安装步骤\n\n推荐通过 **Anaconda** 管理虚拟环境，以确保依赖隔离和安装简便。\n\n### 1. 安装 Anaconda\n如果尚未安装，请前往 [Anaconda 官网](https:\u002F\u002Fwww.anaconda.com\u002Fproducts\u002Findividual) 下载并安装 Individual Edition。安装时请选择 **Python 3.x** 版本。\n\n### 2. 创建并激活虚拟环境\n打开终端（Linux\u002FmacOS）或 Anaconda Prompt（Windows），执行以下命令创建名为 `pytorchbook` 的环境：\n\n```bash\nconda create -n pytorchbook anaconda\n```\n\n创建完成后，激活该环境：\n\n```bash\nconda activate pytorchbook\n```\n*注：激活成功后，命令行提示符前会出现 `(pytorchbook)` 标识。后续所有命令均需在此环境下执行。*\n\n### 3. 安装 PyTorch\n访问 [PyTorch 官网启动页](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F)，根据你的系统配置获取安装命令。\n*   **无 GPU 用户** (以 Windows 为例)：\n    ```bash\n    conda install pytorch torchvision cpuonly -c pytorch\n    ```\n*   **有 GPU 用户**：请在官网选择对应的 CUDA 版本后复制生成的命令执行。\n*   **国内加速建议**：若下载速度慢，可使用清华源或中科大源。例如：\n    ```bash\n    conda install pytorch torchvision cpuonly -c https:\u002F\u002Fmirrors.tuna.tsinghua.edu.cn\u002Fanaconda\u002Fcloud\u002Fpytorch\u002F\n    ```\n\n### 4. 安装 TensorBoard\n用于可视化训练过程，无需安装完整的 TensorFlow：\n\n```bash\nconda install -c conda-forge tensorboard\n```\n\n### 5. 安装可视化工具 (可选)\n若需查看模型结构图（如第 1 章部分示例），需安装 GraphViz 和 TorchViz。\n\n*   **安装 GraphViz**：\n    *   **Windows**: 下载 [安装包](https:\u002F\u002Fgraphviz.gitlab.io\u002F_pages\u002FDownload\u002Fwindows\u002Fgraphviz-2.38.msi) 安装，并将 `bin` 目录（通常在 `C:\\ProgramFiles(x86)\\Graphviz2.38\\bin`）添加到系统环境变量 `PATH` 中。\n    *   **Linux\u002FmacOS**: 使用包管理器安装 (如 `sudo apt-get install graphviz` 或 `brew install graphviz`)。\n*   **安装 TorchViz**：\n    ```bash\n    pip install torchviz\n    ```\n\n### 6. 克隆项目代码\n安装 Git 后，克隆官方仓库到本地：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fdvgodoy\u002FPyTorchStepByStep.git\n```\n\n进入项目目录并启动 Jupyter Notebook：\n\n```bash\ncd PyTorchStepByStep\njupyter notebook\n```\n\n浏览器将自动打开，显示所有章节的 Notebook 文件。\n\n## 基本使用\n\n本项目为书籍的每一章提供了一个独立的 Jupyter Notebook 文件（例如 `Chapter01.ipynb`）。\n\n1.  **选择章节**：在 Jupyter 界面中点击对应的 `.ipynb` 文件（如 `Chapter01.ipynb`）。\n2.  **顺序执行**：按照书中逻辑，从上到下依次点击单元格左侧的 **Run** 按钮（或按 `Shift + Enter`）。\n3.  **验证结果**：每个 Notebook 包含书中展示的所有代码，顺序执行后应能得到与书中完全一致的输出结果和图表。\n\n**替代方案（无需本地安装）：**\n如果不想配置本地环境，可直接点击仓库 README 中的 **Google Colab** 链接，在云端免费使用 GPU 直接运行各章节代码。","一名刚入门深度学习的数据科学实习生，正试图从零开始构建一个图像分类模型以完成公司分配的原型验证任务。\n\n### 没有 PyTorchStepByStep 时\n- **环境配置劝退**：面对 PyTorch 2.x、Torchvision 及 HuggingFace 等库的版本迭代，手动搭建兼容环境耗时耗力，常因依赖冲突导致代码无法运行。\n- **理论落地困难**：书本上的梯度下降或卷积原理抽象难懂，缺乏可执行的代码参照，难以将数学公式转化为实际的训练循环。\n- **复现结果受阻**：网上碎片化的教程代码往往缺少关键细节或已过时，跑出的结果与预期不符，无法判断是算法问题还是代码错误，严重打击学习信心。\n- **硬件门槛限制**：本地电脑缺乏高性能 GPU，无法进行大规模的图像训练实验，导致学习进程被迫停滞。\n\n### 使用 PyTorchStepByStep 后\n- **开箱即用体验**：直接通过 Google Colab 加载书中配套的 Jupyter Notebook，自动利用云端 GPU 资源，且代码已针对最新库版本修订，彻底免除环境配置烦恼。\n- **代码逐行拆解**：每个章节对应一个完整的 Notebook，从简单的回归问题到复杂的 Transformer 架构，所有代码均可按顺序执行，直观展示数据流转与模型构建过程。\n- **结果精准复现**：严格遵循书中的代码逻辑，能够轻松复现完全一致的输出结果，快速验证算法有效性，让学习者确信自己的理解无误。\n- **渐进式实战路径**：按照“基础原理→计算机视觉→序列模型→自然语言处理”的结构化路径，手把手指导完成从理论推导到微调大模型的全流程实战。\n\nPyTorchStepByStep 通过提供可复现、模块化且紧跟技术前沿的实战代码，将深度学习的学习曲线从“陡峭悬崖”变成了“平缓阶梯”。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdvgodoy_PyTorchStepByStep_ae1bb79a.png","dvgodoy","Daniel Voigt Godoy","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fdvgodoy_618ef895.jpg","Data scientist, developer, teacher and writer.\r\n\r\nAuthor of \"Deep Learning with PyTorch Step-by-Step: A Beginner's Guide\".",null,"Portugal","https:\u002F\u002Fpytorchstepbystep.com","https:\u002F\u002Fgithub.com\u002Fdvgodoy",[84,88],{"name":85,"color":86,"percentage":87},"Jupyter Notebook","#DA5B0B",97.9,{"name":89,"color":90,"percentage":91},"Python","#3572A5",2.1,1437,497,"2026-04-01T09:00:07","MIT","Linux, macOS, Windows","非必需。如有 NVIDIA GPU 可加速，需安装对应版本的 CUDA（文中示例提及 10.1，具体取决于 PyTorch 版本）；无 GPU 可使用 CPU 模式运行。","未说明",{"notes":100,"python":101,"dependencies":102},"建议使用 Anaconda 创建虚拟环境（如 pytorchbook）进行管理。若无 GPU，安装 PyTorch 时需指定'cpuonly'参数。GraphViz 为可选依赖，主要用于可视化模型结构，在 Windows 上配置较复杂（需手动添加环境变量 PATH），若安装失败不影响大部分代码运行。可通过 Google Colab、Binder 或本地安装三种方式运行笔记本。","3.x (Python 2 已停止支持)",[103,104,105,106,107,108,109,110],"pytorch (2.x)","torchvision","tensorboard","graphviz (可选)","torchviz (可选)","git","jupyter","anaconda",[13],[113,114,115,116,117,118],"deep-learning","pytorch","pytorch-tutorial","python","cnn-pytorch","rnn-pytorch","2026-03-27T02:49:30.150509","2026-04-06T05:15:15.617035",[122,127,132,137,141,145],{"id":123,"question_zh":124,"answer_zh":125,"source_url":126},16240,"为什么在计算梯度时，有时代码中没有负号，而有时又有？哪种是正确的？","两种情况在数学上都是正确的，结果不会改变。PyTorch 的 Autograd 机制不依赖标准的误差表达式假设，而是根据给定的操作序列自动计算梯度。\n\n如果你定义误差为 error = y_train - y_hat，那么对权重 w 和偏置 b 求导时，链式法则会自然产生一个负号（因为 y_hat 前面有负号）：\n- b_grad = (2 * error) * (-1)\n- w_grad = (2 * error) * (-x_train)\n\n如果你定义误差为 error = y_hat - y_train，则导数中不包含额外的负号。\n为了保持一致性，建议统一使用 error = y_hat - y_train 的形式，但这并不影响最终梯度的方向是否正确，Autograd 会自动处理这些符号差异。","https:\u002F\u002Fgithub.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fissues\u002F21",{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},16241,"书中图 9.3 关于正方形顶点标记（ABCD）和序列编号（1234）的描述令人困惑，它们是如何对应的？","这是一个文档描述错误，应以第三个正方形（Figure 9.3 中的第三个）为准。\n\n具体对应关系如下：\n1. ABCD 代表正方形的四个角：A=左下，B=左上，C=右上，D=右下（顺时针标记）。\n2. 1234 代表节点绘制的顺序，并不直接一一映射到 ABCD。\n3. 无论从哪里开始，源序列（Source Sequence）总是前两个绘制的节点（1 和 2），目标序列（Target Sequence）总是后两个节点（3 和 4）。\n4. 例如，如果从右上角（C）开始顺时针绘制，顺序可能是 C(1)->D(2)->A(3)->B(4)。此时源序列是 C 和 D，目标序列是 A 和 B。\n\n书中的文字描述曾错误地指向了第一个正方形，实际上应参考第三个正方形的逻辑。","https:\u002F\u002Fgithub.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fissues\u002F46",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},16242,"在代码重构过程中，为什么函数名从 `train_step` 变成了 `step`？我找不到定义的地方。","这是代码抽象的一种体现。在辅助函数 #2（Helper Function #2）中，`step` 是一个作为参数传入的函数，它抽象了具体的训练步骤。\n\n当你调用高层训练函数时，你将实际生成的训练函数（例如通过 `make_train_step` 创建的函数）作为参数 `step` 传递进去。因此，在函数内部调用 `step(x_batch, y_batch)` 实际上就是在执行你传入的那个 `train_step` 逻辑。这种设计模式允许在不修改高层循环代码的情况下，灵活替换不同的训练策略或优化步骤。","https:\u002F\u002Fgithub.com\u002Fdvgodoy\u002FPyTorchStepByStep\u002Fissues\u002F11",{"id":138,"question_zh":139,"answer_zh":140,"source_url":131},16243,"尝试导入 `data_generation.square_sequences` 模块时出现 `ModuleNotFoundError`，但类似的自定义目录结构却能正常导入，原因是什么？","虽然提供的评论主要讨论了数据生成的逻辑而非直接解决导入路径问题，但此类问题通常由以下原因导致：\n1. 缺少 `__init__.py` 文件：确保 `data_generation` 目录及其子目录（如果 `square_sequences` 是包）下包含空的 `__init__.py` 文件，以便 Python 将其识别为包。\n2. 运行目录不对：确保你在项目根目录（即包含 `data_generation` 文件夹的目录）下运行 python 命令。\n3. 安装方式：如果该项目是通过 `pip install -e .` 安装的，请确保安装成功且环境变量正确。如果是直接运行脚本，请检查 `sys.path` 是否包含当前目录。\n\n注意：原 Issue 中的讨论主要集中在数据生成逻辑的澄清上，若上述常规方法无效，请参考项目中关于数据生成的最新文档说明。",{"id":142,"question_zh":143,"answer_zh":144,"source_url":136},16244,"对于有数学背景但想转行数据科学的人，有什么推荐的学习路径？","作者建议避免两个极端：\n1. 纯理论派：深入研究每个算法背后的微积分和线性代数细节（适合研究人员，但对实际应用可能过度）。\n2. 纯代码派：只动手尝试而不理解原理（常见于博客教程，但缺乏深度，难以解决复杂问题）。\n\n推荐采用“中间路线”：在动手实践的同时，深入理解“为什么”事物是这样工作的。不需要发明新算法或发表论文级别的数学推导，但要掌握核心原理。作者为此专门开发了基础课程（ML_Fundamentals）来帮助学生建立这种平衡的理解，建议在阅读本书的同时，结合理解底层数学原理进行实践。",{"id":146,"question_zh":147,"answer_zh":148,"source_url":126},16245,"Autograd 是如何处理误差公式中项的顺序（如 y_train - y_hat vs y_hat - y_train）对梯度符号的影响的？","Autograd 不使用任何预设的标准误差公式，也不做假设。它完全依据你定义的运算序列，利用链式法则（Chain Rule）自动计算梯度。\n\n具体来说：\n- 如果你写 `error = y_train - y_hat`，Autograd 会追踪到这个减法操作，并在反向传播时自动应用相应的导数规则（包括产生的负号）。\n- 如果你写 `error = y_hat - y_train`，它同样会追踪这个不同的减法顺序，并计算出对应的梯度。\n\n无论你怎么排列减法的顺序，只要损失函数（Loss Function，通常是误差的平方）定义一致，Autograd 都能算出指向最小值方向的正確梯度。用户无需手动调整符号，系统会自动“算出”正确的数学结果。",[]]