Skip to content

Commit 1ae7fb1

Browse files
authored
Merge pull request #2203 from d2l-ai/master
Release 1.0.0-alpha0
2 parents ae5c400 + 7328e01 commit 1ae7fb1

File tree

266 files changed

+37580
-21772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+37580
-21772
lines changed

CONTRIBUTING.md

+158-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ We look forward to receiving your pull requests for:
2222

2323
## How to contribute
2424

25-
To contribute, send us a pull request. For small changes, such as fixing a typo or adding a link, you can use the [GitHub Edit Button](https://blog.github.com/2011-04-26-forking-with-the-edit-button/). For larger changes:
25+
To contribute, start by reading [contributing section](https://d2l.ai/chapter_appendix-tools-for-deep-learning/contributing.html) and eventually
26+
send us a pull request. For small changes, such as fixing a typo or adding a link, you can use the [GitHub Edit Button](https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files). For larger changes:
2627

2728
1. [Fork the repository](https://help.github.com/articles/fork-a-repo/).
2829
2. In your fork, make your change in a new branch (e.g., by [`git branch`](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging)) that's based on this repo's **master** branch.
@@ -39,10 +40,165 @@ For contributions that will take a significant amount of time, [open a new issue
3940

4041
## Finding contributions to work on
4142

42-
If you'd like to contribute, but don't have a project in mind, look at the [open issues](https://github.com/d2l-ai/d2l-en/issues) in this repository for some ideas. Any issues with the [help wanted](https://github.com/d2l-ai/d2l-en/labels/help%20wanted) or [enhancement](https://github.com/d2l-ai/d2l-en/labels/enhancement) labels are a great place to start.
43+
If you'd like to contribute, but don't have a project in mind, look at the [open issues](https://github.com/d2l-ai/d2l-en/issues) in this repository for some ideas. Issues with the [help wanted](https://github.com/d2l-ai/d2l-en/labels/help%20wanted), [good first issue](https://github.com/d2l-ai/d2l-en/labels/good%20first%20issue) or [enhancement](https://github.com/d2l-ai/d2l-en/labels/enhancement) labels are a great place to start.
4344

4445
In addition to written content, we really appreciate new examples and code samples for our documentation, such as examples for different platforms or environments, and code samples in additional languages.
4546

47+
48+
## How to change code in one of the frameworks?
49+
50+
This section describes the development environment setup and workflow
51+
which should be followed when modifying/porting python code and making
52+
changes to one of the machine learning frameworks in the book.
53+
We follow a set of pre-defined [style guidelines](https://github.com/d2l-ai/d2l-en/blob/master/STYLE_GUIDE.md)
54+
for consistent code quality throughout the book and expect the same
55+
from our community contributors. You may need to check other chapters
56+
from other contributors as well for this step.
57+
58+
All the chapter sections are generated from markdown (.md file, not .ipynb file)
59+
source files. When making changes in code, for the ease of development
60+
and making sure it is error free, we never edit the markdown files directly.
61+
Instead we can read/load these markdown files as jupyter notebooks
62+
and then make the required changes in the notebook to edit the markdown
63+
file automatically (more on that below). This way, before raising the PR,
64+
one can easily test the changes locally in the jupyter notebook.
65+
66+
Start by cloning the repo.
67+
68+
* Clone your d2l-en repo fork to a local machine.
69+
```
70+
git clone https://github.com/<UserName>/d2l-en.git
71+
```
72+
73+
* Setup your local environment: Create an empty conda environment
74+
(you may refer to our [Miniconda Installaton](https://d2l.ai/chapter_installation/index.html#installing-miniconda) section in the book).
75+
76+
* Install the required packages after activating the environment.
77+
What are the required packages? This depends on the framework you wish to edit. Note that master and release branches may have different
78+
versions of a framework. For more details, you may refer to our [installation section](https://d2l.ai/chapter_installation/index.html).
79+
See example installation below:
80+
81+
```bash
82+
conda activate d2l
83+
84+
# PyTorch
85+
pip install torch==<version> torchvision==<version>
86+
# pip install torch==1.11.0 torchvision==0.12.0
87+
88+
# MXNet
89+
pip install mxnet==<version>
90+
# pip install mxnet==1.7.0
91+
# or for gpu
92+
# pip install mxnet-cu102==1.7.0
93+
94+
# Tensorflow
95+
pip install tensorflow==<version> tensorflow-probability==<version>
96+
# pip install tensorflow==2.8.0 tensorflow-probability==0.16.0
97+
```
98+
99+
Compilation of the book is powered by the
100+
[`d2lbook`](https://github.com/d2l-ai/d2l-book) package.
101+
Simply run `pip install git+https://github.com/d2l-ai/d2l-book` in the
102+
d2l conda environment to install the package.
103+
We'll explain some of the basic `d2lbook` features below.
104+
105+
NOTE: `d2l` and `d2lbook` are different packages. (avoid any confusion)
106+
107+
* Install the `d2l` library in development mode (only need to run once)
108+
109+
```bash
110+
# Inside root of local repo fork
111+
cd d2l-en
112+
113+
# Install the d2l package
114+
python setup.py develop
115+
```
116+
117+
Now you can use `from d2l import <framework_name> as d2l` within the
118+
environment to access the saved functions and also edit them on the fly.
119+
120+
When adding a code cell from a specific framework, one needs to specify
121+
the framework by commenting the following on top of a cell: `#@tab tensorflow`
122+
for example. If the code tab is exactly the same for all frameworks then
123+
use `#@tab all`. This information is required by the `d2lbook` package to
124+
build the website, pdf, etc. We recommend looking at some of the notebooks
125+
for reference.
126+
127+
128+
### How to open/edit markdown files using Jupyter Notebook?
129+
130+
Using the notedown plugin we can modify notebooks in md format directly
131+
in jupyter. First, install the notedown plugin, run jupyter, and
132+
load the plugin as shown below:
133+
134+
```bash
135+
pip install mu-notedown # You may need to uninstall the original notedown.
136+
jupyter notebook --NotebookApp.contents_manager_class='notedown.NotedownContentsManager'
137+
```
138+
139+
To turn on the notedown plugin by default whenever you run
140+
`jupyter notebook` do the following: First, generate a
141+
Jupyter Notebook configuration file
142+
(if it has already been generated, you can skip this step).
143+
144+
```bash
145+
jupyter notebook --generate-config
146+
```
147+
148+
Then, add the following line to the end of the Jupyter Notebook
149+
configuration file (for Linux/macOS, usually in the path `~/.jupyter/jupyter_notebook_config.py`):
150+
151+
```bash
152+
c.NotebookApp.contents_manager_class = 'notedown.NotedownContentsManager'
153+
```
154+
155+
After that, you only need to run the jupyter notebook
156+
command to turn on the notedown plugin by default.
157+
158+
Please refer to the section on [markdown files in jupyter](https://d2l.ai/chapter_appendix-tools-for-deep-learning/jupyter.html#markdown-files-in-jupyter)
159+
for more details.
160+
161+
162+
#### d2lbook activate
163+
164+
Now to start working on a particular framework for a section,
165+
only activate the framework tab you wish to use,
166+
like this -> `d2lbook activate <framework_name> chapter_preliminaries/ndarray.md`,
167+
so the `<framework_name>` code blocks become python blocks and
168+
other frameworks are ignored when running the notebook.
169+
170+
When you are done editing a notebook, please save it and
171+
remember to strictly clear all outputs and activate all
172+
tabs by using `d2lbook activate`.
173+
174+
```bash
175+
# Example
176+
d2lbook activate all chapter_preliminaries/ndarray.md`
177+
```
178+
179+
#### d2lbook build lib
180+
181+
Note: Remember to mark a function which will be reused later by
182+
`#save` and in the end when all the above steps are completed
183+
just run the following in the root directory to copy all the
184+
saved functions/classes into `d2l/<framework_name>.py`
185+
186+
```bash
187+
d2lbook build lib
188+
```
189+
190+
If the saved functions require some packages to be imported, you can add
191+
them to `chapter_preface/index.md` under the respective framework tab and
192+
run `d2lbook build lib`. Now the import will also be reflected in the d2l
193+
library after running and the saved functions can access the imported lib.
194+
195+
NOTE: Ensure that the output/results are consistent after the change, across the frameworks, by multiple runs of the notebook locally.
196+
197+
198+
Finally send in a PR, if all checks succeed, with a review of the PR from the authors, your contributions shall be merged. :)
199+
200+
Hope this is comprehensive enough to get you started. Feel free to ask the authors and other contributors in case of any doubt. We always welcome feedback.
201+
46202
## Code of conduct
47203

48204
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For more information, see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

Jenkinsfile

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ stage("Build and Publish") {
1616
sh label: "Build Environment", script: """set -ex
1717
conda env update -n ${ENV_NAME} -f static/build.yml
1818
conda activate ${ENV_NAME}
19-
pip uninstall -y d2lbook
2019
pip install git+https://github.com/d2l-ai/d2l-book
2120
pip list
2221
nvidia-smi
@@ -31,15 +30,15 @@ stage("Build and Publish") {
3130
conda activate ${ENV_NAME}
3231
./static/cache.sh restore _build/eval/data
3332
d2lbook build eval
33+
d2lbook build slides --tab pytorch
3434
./static/cache.sh store _build/eval/data
3535
"""
3636

37-
sh label: "Execute Notebooks [PyTorch]", script: """set -ex
37+
sh label: "Execute Notebooks [MXNet]", script: """set -ex
3838
conda activate ${ENV_NAME}
39-
./static/cache.sh restore _build/eval_pytorch/data
40-
d2lbook build eval --tab pytorch
41-
d2lbook build slides --tab pytorch
42-
./static/cache.sh store _build/eval_pytorch/data
39+
./static/cache.sh restore _build/eval_mxnet/data
40+
d2lbook build eval --tab mxnet
41+
./static/cache.sh store _build/eval_mxnet/data
4342
"""
4443

4544
sh label: "Execute Notebooks [TensorFlow]", script: """set -ex
@@ -61,9 +60,9 @@ stage("Build and Publish") {
6160
d2lbook build pdf
6261
"""
6362

64-
sh label:"Build Pytorch PDF", script:"""set -ex
63+
sh label:"Build MXNet PDF", script:"""set -ex
6564
conda activate ${ENV_NAME}
66-
d2lbook build pdf --tab pytorch
65+
d2lbook build pdf --tab mxnet
6766
"""
6867

6968
if (env.BRANCH_NAME == 'release') {
@@ -77,7 +76,6 @@ stage("Build and Publish") {
7776
conda activate ${ENV_NAME}
7877
pip install setuptools wheel twine
7978
python setup.py bdist_wheel
80-
# twine upload dist/*
8179
"""
8280
} else {
8381
sh label:"Publish", script:"""set -ex

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![Build Status](http://ci.d2l.ai/job/d2l-en/job/master/badge/icon)](http://ci.d2l.ai/job/d2l-en/job/master/)
88

9-
[Book website](https://d2l.ai/) | [STAT 157 Course at UC Berkeley, Spring 2019](http://courses.d2l.ai/berkeley-stat-157/index.html)
9+
[Book website](https://d2l.ai/) | [STAT 157 Course at UC Berkeley](http://courses.d2l.ai/berkeley-stat-157/index.html)
1010

1111
<h5 align="center"><i>The best way to understand deep learning is learning by doing.</i></h5>
1212

@@ -87,7 +87,7 @@ If you find this book useful, please star (★) this repository or cite this boo
8787

8888
This open source book has benefited from pedagogical suggestions, typo corrections, and other improvements from community contributors. Your help is valuable for making the book better for everyone.
8989

90-
**Dear [D2L contributors](https://github.com/d2l-ai/d2l-en/graphs/contributors), please email your GitHub ID and name to d2lbook.en AT gmail DOT com so your name will appear on the [acknowledgments](https://d2l.ai/chapter_preface/index.html#Acknowledgments). Thanks.**
90+
**Dear [D2L contributors](https://github.com/d2l-ai/d2l-en/graphs/contributors), please email your GitHub ID and name to d2lbook.en AT gmail DOT com so your name will appear on the [acknowledgments](https://d2l.ai/chapter_preface/index.html#acknowledgments). Thanks.**
9191

9292

9393
## License Summary

0 commit comments

Comments
 (0)