1. Write the Python code to implement a single neuron.
    2. Write the Python code to implement ReLU.
    3. Write the Python code for a dense layer in terms of matrix multiplication.
    4. Write the Python code for a dense layer in plain Python (that is, with list comprehensions and functionality built into Python).
    5. What is the “hidden size” of a layer?
    6. What does the method do in PyTorch?
    7. Why is matrix multiplication written in plain Python very slow?
    8. In matmul, why is ac==br?
    9. In Jupyter Notebook, how do you measure the time taken for a single cell to execute?
    10. What is “elementwise arithmetic”?
    11. Write the PyTorch code to test whether every element of a is greater than the corresponding element of b.
    12. What is a rank-0 tensor? How do you convert it to a plain Python data type?
    13. What does this return, and why? tensor([1,2]) + tensor([1])
    14. How does elementwise arithmetic help us speed up matmul?
    15. What are the broadcasting rules?
    16. What is ? Show an example of how it can be used to match the results of broadcasting.
    17. How does unsqueeze help us to solve certain broadcasting problems?
    18. How can we use indexing to do the same operation as unsqueeze?
    19. How do we show the actual contents of the memory used for a tensor?
    20. When adding a vector of size 3 to a matrix of size 3×3, are the elements of the vector added to each row or each column of the matrix? (Be sure to check your answer by running this code in a notebook.)
    21. Do broadcasting and expand_as result in increased memory use? Why or why not?
    22. Implement matmul using Einstein summation.
    23. What does a repeated index letter represent on the left-hand side of einsum?
    24. What are the three rules of Einstein summation notation? Why?
    25. What are the forward pass and backward pass of a neural network?
    26. Why do we need to store some of the activations calculated for intermediate layers in the forward pass?
    27. What is the downside of having activations with a standard deviation too far away from 1?
    28. What is the formula to initialize weights such that we get a standard deviation of 1 for a plain linear layer, and for a linear layer followed by ReLU?
    29. Why do we sometimes have to use the squeeze method in loss functions?
    30. What does the argument to the squeeze method do? Why might it be important to include this argument, even though PyTorch does not require it?
    31. What is the “chain rule”? Show the equation in either of the two forms presented in this chapter.
    32. Show how to calculate the gradients of mse(lin(l2, w2, b2), y) using the chain rule.
    33. What is the gradient of ReLU? Show it in math or code. (You shouldn’t need to commit this to memory—try to figure it using your knowledge of the shape of the function.)
    34. In what order do we need to call the functions in the backward pass? Why?
    35. What is __call__?
    36. What methods must we implement when writing a torch.autograd.Function?
    37. Write nn.Linear from scratch, and test it works.
    38. What is the difference between nn.Module and fastai’s Module?
    1. Implement ReLU as a torch.autograd.Function and train a model with it.
    2. If you are mathematically inclined, find out what the gradients of a linear layer are in mathematical notation. Map that to the implementation we saw in this chapter.
    3. Learn about the unfold method in PyTorch, and use it along with matrix multiplication to implement your own 2D convolution function. Then train a CNN that uses it.