翻篇收录说明
翻篇网页快照

27.8 Contributor Guide – Dive into Deep Learning

https://d2l.ai/chapter_appendix-tools-for-deep-learning/developers-guide.html

最近抓取:2026-12-04 14:58:30(北京时间)

最近内容变化:2026-12-04 14:58:30(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

正文摘录

By now you have run many of this book’s notebooks, and you may have found a sentence that confused you, a transposed subscript in an equation, or a cell that fails with a newer library. A fix should appear wherever that text or code appears: on the website, in the PDF, in the notebook of every framework, and on the slide that quotes the same cell. How does a one-line correction reach all of these places, and how do we know that it broke nothing? The book is maintained the way open-source software is. Every page comes from one Markdown file under version control, a build system derives everything else from these files, and a change is ready for review once the notebooks it touches execute and the site renders. We describe the build, the Git workflow for proposing a change, the optional use of coding agents, and the checks a change must pass. The same concerns arise in any machine learning repository whose documents must run. 27.8.1 The Build 27.8.1.1 One Source, Many Artifacts Each section is stored in a single Markdown file; this one is chapter_appendix-tools-for-deep-learning/developers-guide.md. The build derives everything else from these sources: chapter_*/*.md source of truth (edit these) ├── chapter_*/*.qmd generated Quarto input → HTML site and PDFs ├── _notebooks/<fw>/... generated Jupyter notebooks, one set per framework ├── _slides/<fw>/... generated lecture slides └── d2l/*.py generated d2l library, from the #@save blocks outputs/<fw>/... executed outputs, captured from _notebooks/, committed This design has three practical consequences: Never edit generated files. A .qmd or .ipynb edit is destroyed by the next build. Edit the .md source and regenerate. Framework tabs live in one file. A code block tagged %%tab pytorch appears only in the PyTorch view; an untagged Python block appears in every notebook of the file. The file yields one notebook for each framework that at least one of its blocks is tagged for, and a file without tagged blocks yields a PyTorch notebook only. One source file thus yields up to four notebooks that must all execute. Chapters of the Basics, Image Models, Mathematics for Deep Learning, and Tools for Deep Learning parts carry all four frameworks; chapters of the Advanced part carry PyTorch and JAX (with Chapter 14 in PyTorch), and the Language Models part carries PyTorch. Cell identity is stable. Every Python block carries a permanent ID (assigned by tools/add_cell_ids.py) so that slides, executed outputs, and framework views can refer to a cell across renames and moves. The sources are Markdown rather than notebooks because of version control. A .ipynb file is JSON that mixes code, outputs, execution counts, and editor metadata, so a one-word edit followed by a re-run changes many lines besides that word; a Markdown diff shows only the changed prose and code. Executed outputs are stored separately and are re-captured only when the code that produced them, the library code it uses, or the framework version changes. The d2l library you have imported throughout the book is generated the same way. make lib extracts every block marked #@save into the per-framework modules d2l/torch.py, d2l/tensorflow.py, d2l/jax.py, and d2l/mxnet.py. A fix made where a function is taught reaches every later chapter after a rebuild, which is why those files carry a banner that says not to edit them directly. The Colab and Kaggle notebooks of Section 27.2 are generated too, onto a separate branch, notebooks, that is rebuilt from the sources and never edited by hand. 27.8.1.2 Repository Layout The top level of the repository holds the sources, the build entry points, and the documentation that explains them: d2l-neu/ ├── chapter_*/ source Markdown, one directory per chapter ├── img/ figures; illustrative SVGs come from tools/gen_*_figures.py ├── d2l/ the generated d2l library ├── outputs/ committed store of executed notebook outputs ├── tools/ build scripts (preprocessing, notebooks, slides, audits) ├── docs/ build-system documentation, writing and code guides ├── Makefile, make/ entry point: make html, make lib, make capture-outputs ... ├── bootstrap.sh one-time setup of a fresh clone └── CLAUDE.md build summary, written for coding agents On a fresh clone, ./bootstrap.sh installs Git LFS, which stores the images of the committed outputs, fetches those images, and creates .venv-build, the environment that holds Quarto. After that, make html renders the whole site from the committed outputs on a laptop without a GPU; executing notebooks is a separate step. The Makefile needs GNU Make 4.3 or newer, which macOS provides only as an extra install (gmake from MacPorts, for example). make help lists the targets, and docs/build-system.md explains them. 27.8.2 Git Basics Every change to the book travels as a Git commit on a branch of your own copy of the repository. If you already use Git daily, skip ahead. First, make that copy: click Fork on the repository page, then clone your fork and create a branch for your change: git clone https://github.com/<your-username>/d2l-neu.git cd d2l-neu git switch -c fix-typo-in-attention # a branch per change Edit the source .md file, then record and publish the change: git status # what changed? git diff # show the exact edits git add chapter_attention/attention-scoring.md git commit -m "Fix transposed subscript in attention equation" git push -u origin fix-typo-in-attention GitHub will offer to open a pull request: your branch, proposed for merging, with a diff the maintainers can review and comment on. (The gh command-line tool does the same with gh pr create.) Small, focused pull requests are easier to review than changes spanning several chapters. 27.8.3 Coding Agents A coding agent is a language model that reads the repository, edits files, and runs commands. It helps with bounded tasks: finding where a function is defined, propagating a mechanical change across framework variants, or running the checks and reading their failures. Its use is optional, and its edits need the same review as anyone else’s. Three properties of this repository make such help practical: The build is documented. CLAUDE.md and docs/ tell an agent how to regenerate, execute, and render the artifacts. The same instructions serve human contributors. Verification is executable. An edit works when the notebook executes top to bottom in every framework it has, the audit of the committed outputs passes, and the page renders. An agent can run the loop of editing, regenerating, executing, and inspecting failures, but the contributor reviews both the final diff and the evidence from the checks. The tedious parts are mechanical. Keeping framework implementations in sync, checking that every :numref: resolves, and regenerating figures are multi-file tasks that an agent can carry out and a person can review. A useful request states the change and how to verify it, for example: “the contour plot of the momentum section mislabels its axes; correct the source and rerun the affected notebooks.” Review for two failure modes. An agent may edit a generated file, as newcomers do, unless the project documentation warns against it (ours does). And an agent asked to make a failing check pass may weaken the check or the code instead of fixing the cause: a notebook that runs again may no longer teach the right thing. 27.8.4 Submitting Changes Contributions range from one-line corrections to new code, and the checks grow with the change. A one-line fix does not even need a local checkout: open the source file on GitHub and press the edit (pencil) button. GitHub offers to fork the repository, and after the edit it leads you through the commit to a pull request, all in the browser. For code and content changes, clone, branch, and edit the source .md. Check the edited file with tools/lint_source.py, which catches unbalanced tab and slide markers, duplicate cell IDs, and equation labels that would not attach; with --corpus it also checks that every cross-reference points to an existing label. Then re-execute every notebook that the edit touches, copy its outputs into the committed store, and render the site: make venv-pytorch # once per framework make -B _notebooks/pytorch/<chapter>/<file>.executed # repeat per framework make capture-outputs FILES=<chapter>/<file>.md make html If you edit code that carries #@save, rebuild the library with make lib before you execute any notebook. Notebooks of other sections that use the edited symbol then become stale too, and make audit-outputs lists them. A laptop without a GPU cannot re-execute GPU notebooks; make html warns about such a notebook instead of stopping, and the pull request should name the notebooks that still need a GPU run. New prose follows docs/writing-guide.md, and new code follows docs/code-guide.md. If you prefer editing notebooks to raw Markdown, the VS Code extension in .vscode-extension/ (its README explains how to build and install it) opens the generated notebook of the current section with the right kernel preselected, switches between its framework views, previews the slide deck live, and re-executes and captures a notebook with one command. It writes edits made in the notebook back into the Markdown source, so a generated file never becomes the thing you edited. make kernels registers the Jupyter kernels it uses. Whatever the route, a change is ready when it executes cleanly from a fresh state in every framework it touches, and when the source, never a generated file, is what changed. 27.8.5 Summary A single Markdown source per section generates the website, PDFs, per-framework notebooks, slides, and the d2l package, while executed outputs live separately under version control and generated files are never edited by hand. Keeping prose and code in plain Markdown yields clean, line-level Git diffs so a book of more than 600 notebooks remains straightforward to review and maintain. Every contribution follows the same loop: fork the repository, create a focus