Skip to content

Commit

Permalink
Apply isort and black reformatting
Browse files Browse the repository at this point in the history
Signed-off-by: cuichenx <[email protected]>
  • Loading branch information
cuichenx committed Nov 5, 2024
1 parent 1934957 commit 38d29b9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nemo/collections/llm/peft/dora.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,18 @@ def forward(self, x):
if self.adapter.dropout is None:
dropout_correction = 0
else:
assert self.adapter.dropout_position == "pre", ("DoRA only supports pre-adapter dropout at this time."
"Please set DoRA(..., dropout_position='pre')")
assert self.adapter.dropout_position == "pre", (
"DoRA only supports pre-adapter dropout at this time." "Please set DoRA(..., dropout_position='pre')"
)
"""
When dropout is used, equation becomes
W_0 x + (m /||W_0 + B A|| - 1) W_0 dropout(x) + m /||W_0 + B A|| B A dropout(x)
= ...
= m /||W_0 + B A|| (W_0 x + B A dropout(x)) + (m /||W_0 + B A|| - 1) W_0 (dropout(x) - x)
"""
dropout_correction = (mag_norm_scale - 1) * self.base_linear_forward(self.adapter.dropout(layernorm_output) - x)[0]
dropout_correction = (mag_norm_scale - 1) * self.base_linear_forward(
self.adapter.dropout(layernorm_output) - x
)[0]

return mag_norm_scale * (linear_output + adapter_output) + dropout_correction, bias

Expand Down

0 comments on commit 38d29b9

Please sign in to comment.