-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access self-attention matrix of vision transformer #6032
Comments
@wyli I would like to help with this issue. I was thinking, the easiest way to achieve this without changing the API could be by making Let me know your thoughts. |
sounds good, please make sure it's backward compatible, e.g. previously saved checkpoints can still be loaded by default. |
Fixes #6032 . ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Ben Murray <ben.murray@gmail.com> Signed-off-by: a-parida12 <abhijeet.parida@tum.de> Signed-off-by: YanxuanLiu <yanxuanl@nvidia.com> Signed-off-by: monai-bot <monai.miccai2019@gmail.com> Signed-off-by: Wenqi Li <wenqil@nvidia.com> Co-authored-by: Ben Murray <ben.murray@gmail.com> Co-authored-by: YanxuanLiu <104543031+YanxuanLiu@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Wenqi Li <831580+wyli@users.noreply.github.com> Co-authored-by: monai-bot <monai.miccai2019@gmail.com> Co-authored-by: Wenqi Li <wenqil@nvidia.com>
Fixes #6032 . ### Description specified the data type of the `att_matrix` to be compliant with torch.jit.compile requirements for conditionals ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: a-parida12 <abhijeet.parida@tum.de>
@wyli I just realized that |
Sure, please help create another feature request to follow up.. |
Is your feature request related to a problem? Please describe.
I am training a vision transformer using monai and would like to carry out some interpretability analysis. However, the current model code does not save the self-attention matrix during training, and it is not straightforward to pass it from the self-attention block to the model output.
MONAI/monai/networks/blocks/selfattention.py
Lines 56 to 65 in 88fb0b1
Describe the solution you'd like
An option to output the
attn_mat
from the self-attention block in the model forward pass (before matrix multiplication with the input) or access it after training as a class attribute.The text was updated successfully, but these errors were encountered: