-
Notifications
You must be signed in to change notification settings - Fork 542
fix LLMAttribution for old pytorch/python versions #1353
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request was exported from Phabricator. Differential Revision: D63016032 |
1 similar comment
This pull request was exported from Phabricator. Differential Revision: D63016032 |
DianjingLiu
added a commit
to DianjingLiu/captum
that referenced
this pull request
Sep 19, 2024
Summary: Pull Request resolved: pytorch#1353 When setting `use_cached_outputs=False`, the `LLMAttribution` failed to run on some old versions of pytorch/python. ## Error message ``` ====================================================================== ERROR: test_llm_attr_hf_compatibility_0 (tests.attr.test_llm_attr_hf_compatibility.TestLLMAttrHFCompatibility_1_cpu) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func return func(*(a + p.args), **p.kwargs, **kw) File "/data/users/liudj/captum/tests/attr/test_llm_attr_hf_compatibility.py", line 80, in test_llm_attr_hf_compatibility res = llm_attr.attribute( File "/data/users/liudj/captum/captum/attr/_core/llm_attr.py", line 461, in attribute cur_attr = self.attr_method.attribute( File "/data/users/liudj/captum/captum/log/__init__.py", line 52, in wrapper return func(*args, **kwargs) File "/data/users/liudj/captum/captum/attr/_core/feature_ablation.py", line 292, in attribute initial_eval: Union[Tensor, Future[Tensor]] = _run_forward( File "/data/users/liudj/captum/captum/_utils/common.py", line 599, in _run_forward output = forward_func( File "/data/users/liudj/captum/captum/attr/_core/llm_attr.py", line 335, in _forward_func outputs = self.model.forward(model_inp, **model_kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 1189, in forward outputs = self.model( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 1001, in forward layer_outputs = decoder_layer( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 734, in forward hidden_states, self_attn_weights, present_key_value = self.self_attn( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 428, in forward attn_weights = attn_weights + causal_mask RuntimeError: The size of tensor a (8) must match the size of tensor b (7) at non-singleton dimension 3 ``` ## Root cause The `attention_mask` was not updated to adapt to the growth of input size. Error message see test plan. ## Impacted versions - Python 3.8-3.10, PyTorch 1.10-1.12, transformers 4.44.2 - Python 3.8-3.11, PyTorch 1.13-2.1.0, transformers 4.44.2 {F1876426564} Differential Revision: D63016032
6823dfd
to
5b5d99c
Compare
This pull request was exported from Phabricator. Differential Revision: D63016032 |
5b5d99c
to
00dab20
Compare
DianjingLiu
added a commit
to DianjingLiu/captum
that referenced
this pull request
Sep 19, 2024
Summary: Pull Request resolved: pytorch#1353 When setting `use_cached_outputs=False`, the `LLMAttribution` failed to run on some old versions of pytorch/python. ## Error message ``` ====================================================================== ERROR: test_llm_attr_hf_compatibility_0 (tests.attr.test_llm_attr_hf_compatibility.TestLLMAttrHFCompatibility_1_cpu) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func return func(*(a + p.args), **p.kwargs, **kw) File "/data/users/liudj/captum/tests/attr/test_llm_attr_hf_compatibility.py", line 80, in test_llm_attr_hf_compatibility res = llm_attr.attribute( File "/data/users/liudj/captum/captum/attr/_core/llm_attr.py", line 461, in attribute cur_attr = self.attr_method.attribute( File "/data/users/liudj/captum/captum/log/__init__.py", line 52, in wrapper return func(*args, **kwargs) File "/data/users/liudj/captum/captum/attr/_core/feature_ablation.py", line 292, in attribute initial_eval: Union[Tensor, Future[Tensor]] = _run_forward( File "/data/users/liudj/captum/captum/_utils/common.py", line 599, in _run_forward output = forward_func( File "/data/users/liudj/captum/captum/attr/_core/llm_attr.py", line 335, in _forward_func outputs = self.model.forward(model_inp, **model_kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 1189, in forward outputs = self.model( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 1001, in forward layer_outputs = decoder_layer( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 734, in forward hidden_states, self_attn_weights, present_key_value = self.self_attn( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 428, in forward attn_weights = attn_weights + causal_mask RuntimeError: The size of tensor a (8) must match the size of tensor b (7) at non-singleton dimension 3 ``` ## Root cause The `attention_mask` was not updated to adapt to the growth of input size. Error message see test plan. ## Impacted versions - Python 3.8-3.10, PyTorch 1.10-1.12, transformers 4.44.2 - Python 3.8-3.11, PyTorch 1.13-2.1.0, transformers 4.44.2 {F1876426564} Reviewed By: vivekmig Differential Revision: D63016032
Summary: Pull Request resolved: pytorch#1353 When setting `use_cached_outputs=False`, the `LLMAttribution` failed to run on some old versions of pytorch/python. ## Error message ``` ====================================================================== ERROR: test_llm_attr_hf_compatibility_0 (tests.attr.test_llm_attr_hf_compatibility.TestLLMAttrHFCompatibility_1_cpu) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/parameterized/parameterized.py", line 620, in standalone_func return func(*(a + p.args), **p.kwargs, **kw) File "/data/users/liudj/captum/tests/attr/test_llm_attr_hf_compatibility.py", line 80, in test_llm_attr_hf_compatibility res = llm_attr.attribute( File "/data/users/liudj/captum/captum/attr/_core/llm_attr.py", line 461, in attribute cur_attr = self.attr_method.attribute( File "/data/users/liudj/captum/captum/log/__init__.py", line 52, in wrapper return func(*args, **kwargs) File "/data/users/liudj/captum/captum/attr/_core/feature_ablation.py", line 292, in attribute initial_eval: Union[Tensor, Future[Tensor]] = _run_forward( File "/data/users/liudj/captum/captum/_utils/common.py", line 599, in _run_forward output = forward_func( File "/data/users/liudj/captum/captum/attr/_core/llm_attr.py", line 335, in _forward_func outputs = self.model.forward(model_inp, **model_kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 1189, in forward outputs = self.model( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 1001, in forward layer_outputs = decoder_layer( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 734, in forward hidden_states, self_attn_weights, present_key_value = self.self_attn( File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "/home/liudj/local/anaconda3/envs/captum_py38/lib/python3.8/site-packages/transformers/models/llama/modeling_llama.py", line 428, in forward attn_weights = attn_weights + causal_mask RuntimeError: The size of tensor a (8) must match the size of tensor b (7) at non-singleton dimension 3 ``` ## Root cause The `attention_mask` was not updated to adapt to the growth of input size. Error message see test plan. ## Impacted versions - Python 3.8-3.10, PyTorch 1.10-1.12, transformers 4.44.2 - Python 3.8-3.11, PyTorch 1.13-2.1.0, transformers 4.44.2 {F1876426564} Reviewed By: vivekmig Differential Revision: D63016032
This pull request was exported from Phabricator. Differential Revision: D63016032 |
00dab20
to
3c16990
Compare
This pull request has been merged in fc910e5. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
When setting
use_cached_outputs=False
, theLLMAttribution
failed to run on some old versions of pytorch/python.Error message
Root cause
The
attention_mask
was not updated to adapt to the growth of input size. Error message see test plan.Impacted versions
{F1876426564}
Differential Revision: D63016032