Bug fix: contribution renormalization correction for FFNs #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While the
apply_threshold_and_renormalize
method works fine in renormalizing attention contribution scores, it doesn't renormalize correctly for FFNs. The reason is that when using this function for FFNs, theresid_dims
andblock_dims
are the same. Therefore, in this line in the original code:llm-transparency-tool/llm_transparency_tool/routes/contributions.py
Line 197 in d8e249e
the sum operation receives an empty tuple for the dimensions, leading to the entire
c_blocks
tensor being summed and returning a single scalar value for the whole input length. This causes the returned tensors of this function not to sum up to one for each representation.In this fix, I’ve added a condition to check if
resid_dims
andblock_dims
are the same, in which casec_blocks
is added directly toc_residual
to calculatedenom
.