Question: Exercise 2 . 2 ( 5 points ) : implement the BlockDiagonalConv 2 d layer Above, you were provided with the description of the block
Exercise points: implement the BlockDiagonalConvd layer
Above, you were provided with the description of the blockdiagonal Convd layer. Now, you are asked to implement it I.e you should
implement a reversible Convd layer which weight matrix is structure as above: as a blockdiagonal matrix with 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 values instead of matrix. For example, for
a diagonal matrix we could store only one vector of size instead of a 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 values into matrix otherwise it will be meaningless to have this compressed
representation. For example, a multiplication of a diagonal matrix with a vector can be computed as an element
wise multiplication of two vectors: and dots,
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 BlockDiagonalConvdnnModule:
A x Convd layer with x blockdiagonal welght matrix as described above
n
def self inchannel: 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 vectors of length inchannel': for upper values
l of each block and for lower values of each block. You can also store tham as n
Hint: what initialization should we use for then?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
