I suspect my Pytorch model has vanishing gradients. I know I can track the gradients of each layer and record them with writer.add_scalar or writer.add_histogram. However, with a model with a relatively large number of layers, having all these histograms and graphs on the TensorBoard log becomes a bit of a nuisance. I'm not saying it doesn't work, it's just a bit inconvenient to have different graphs and histograms for each layer and scroll through them.
I'm looking for a graph where the y axis (vertical) represents the gradient value (mean of gradient of a specific layer), the x axis (horizontal) shows the layer number (e.g. the value at x=1 is the gradient value for 1st layer), and the z axis (depth) is the epoch number.
This would look like a histogram, but of course, it would be essentially different from a histogram since the x axis does not represent beans. One can write a dirty code that would create a histogram where instead of beans there would be layer numbers, something like (this is a pseudo-code, obviously):
fake_distribution = []
for i, layer in enumerate(model.layers):
fake_distribution += [i for j in range(int(layer.grad.mean()))]
writer.add_histogram('gradients', fake_distribution)
I was wondering if there is a better way for this.