Question: Exercise 2 . 2 ( 5 points ) : implement the BlockDiagonalConv 2 d layer Above, you were provided with the description of the block

Exercise 2.2(5 points): implement the BlockDiagonalConv2d layer
Above, you were provided with the description of the block-diagonal Conv2d layer. Now, you are asked to implement it. I.e. you should
implement a reversible 11 Conv2d layer which weight matrix is structure as above: as a block-diagonal matrix with 22 blocks. This layer
should also compute the logarithm of the absolute value of the determinant of the jacobian ("LADJ") at a given point during the forward pass -
see model. py to figure out the interface.
Rules:
You are not allowed to store a full weight matrix: find a convenient way to store only 2n values instead of nn matrix. For example, for
a diagonal matrix we could store only one vector of size n instead of a nn matrix.
You are not allowed to use functions like torch.slogdet / torch.inverse / torch.det / torch. logdet for this implementation
You are not allowed to unpack your 2n values into nn matrix - otherwise it will be meaningless to have this compressed
representation. For example, a multiplication of a diagonal matrix with a vector x can be computed as an element-
wise multiplication of two vectors: x and a=(a1,dots,an).
Note: a test for reversibility below is useful, but it does not check the correctness of your ladj computation. So be mindful about your ladj
implementation.
fron typing import Tuple
import torch
front torch import Tensor
fron torch inport nn
fron torch.nn import functional as F
fron math import log, pi, exp
import numpy as np
fron scipy inport linalg as la
fron model import Flow, Block, Glow
class BlockDiagonalConv2d(nn.Module):
*"."
A 1x1 Conv2d layer with 2x2 block-diagonal welght matrix as described above
*"n
def (self, in_channel: int):
super().()
\ TODO: Define the parameters
| Hint: think about how we should store the weight matrix in such a way| Hint: we can store it just as 2 vectors of length 'in_channel': for upper values
|l of each block and for lower values of each block. You can also store tham as [n/2,2,2]
| Hint: what initialization should we use for then?
Exercise 2 . 2 ( 5 points ) : implement the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!