Skip to content
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

Fix gating for prefix tuning: Apply gating value to prefix vectors #471

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/transformers/adapters/prefix_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def forward(self, key_states, value_states, residual_input, attention_mask=None,
self._store_gating_score(prefix_tuning_name, gate_output)
gate_output_key = gate_output[:, 0].view(-1, 1, 1, 1)
gate_output_value = gate_output[:, -1].view(-1, 1, 1, 1)
key_states = key_states * gate_output_key
value_states = value_states * gate_output_value
prefix_keys = prefix_keys * gate_output_key
prefix_values = prefix_values * gate_output_value

key_states = torch.cat([prefix_keys, key_states], dim=2)
value_states = torch.cat([prefix_values, value_states], dim=2)
Expand Down