Using the book and d2l module

The book took use of module file’d2l’ (written in python) to implement all its code. The ‘d2l’ module file contains custom functions and classes (built on top of pytorch/numpy/tensorflow etc.) which the book uses directly.

My question is: is this the right approach to use a custom module (built on top of pytorch/tensorflow) and uses its function directly without actually implementing the underlying pytorch/tensorflow code that it use.

What do you mean by "without actually implementing the underlying pytorch/tensorflow code that it use."?

We do implement everything in PyTorch/MXNet/Tensorflow and you can select your framework of choice to view the code. To make things Object Oriented, we have a simple wrapper around the frameworks for training etc. But at the heart of it, everything is written in these frameworks.

We also have sections where we implement everything in scratch.

Hi Anirudh, thanks for the prompt reply. Let me clarify my question a bit more. In the book, certain code wrappers(as you mentioned) are used for specific purposes. For eg. d2l.load_array, d2l.evaluate_loss etc.

While actually implementing the models, should I use these wrappers directly(without considering the pytorch/tensorflow code underneath it) or should I practice writing these functions(or wrappers) myself and use them directly later once I get an understanding of what they are doing.

I would like to take your advice at this point on how to start implementing the code from the D2L book. Thanks

Hi Shobhit!

There is more to the story. We implement these functions/classes but also explain everything behind them if you read the chapters/sections sequentially in the book.

For example, d2l.load_array is introduced in Section 3.3.2 and we only make use of this post section 3.3.2. Similarly for other methods.

The idea is to reuse code in later (more complex) chapters of the book, and make use of what we’ve already defined. Some of these functions like evaluate_loss will be common to numerous sections of the book and we do not want to implement these n times.

Understanding what a function/class aims to do, is extremely important, and we don’t want our readers to take these as black-boxes, hence we try to explain everything sequentially.