134 points · by valine · 2y ago · 20 comments
If it is the first time you look at this, or first time for this specific visualization, or first time for a new type of model, it will not tell you much, and you cannot really tell when things are wrong. You really need to compare it.
E.g. in the readme, it shows the example of overfitting, where you see that activations became too large. But to tell whether this is unexpectedly large or not, you need to compare it to some other plots where everything is fine.
There will typically be visual artifacts in the heat-map that appear right around the time the model starts to go off the rails. Due to the nature of residual layers, problems at lower layers cascade and light up when visualized this way.
More details in this r/locallama thread if you’re interested.
https://www.reddit.com/r/LocalLLaMA/comments/198x01d/openpir...
https://old.reddit.com/r/LocalLLaMA/comments/1ap8mxh/what_ca...
> I’ve done some investigation into this. In a well trained model, if you plot the intermediate output for the last token in the sequence, you see the values update gradually layer to layer. In a model that produces repeating sequences I almost always see a sudden discontinuity at some specific layer. The residual connections are basically flooding the next layer with a distribution of values outside anything else in the dataset.
> The discontinuity is pretty classic overfitting. You’ve both trained a specific token to attend primarily to itself and also incentivized that token to be sampled more often. The result is that if that token is ever included at the end of the context the model is incentivized to repeat it again.
...
> Literally just plotting the output of the layer normalized between zero and one. For one token in mistral 7B it’s a 4096 dimension tensor. Because of the residual connections if you plot that graph for every layer you get a really nice visualization.
> Edit: Here's my visualization. It’s a simple idea but I've never personally seen it done before. AFAIK this is a somewhat novel way to look at transformer layer output.
> Initial output: https://imgur.com/sMwEFEw
> Over-fit output: https://imgur.com/a0obyUj
> Second edit: Code to generate the visualization: https://github.com/valine/NeuralFlow
This is nearly identical to the overfitting example in the repo, only really representing a binary, but it's a good start. Perhaps some transformations can be applied to help further?
My process is to periodically prompt the model as I fine-tune. The features that seem to correlate with the model losing coherence are highlighted nicely with this color mapping. More of an art than a science.
https://cdn.swisscows.com/image?url=https%3A%2F%2Fi.pinimg.c...