Skip to content

Commit

Permalink
Un-ignore ruff E741; add noqas
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Feb 7, 2024
1 parent 244ce10 commit df81c1a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extend-select = [
ignore = [
"C901", # Function too complex
"E501", # Line length (handled by ruff-format)
"E741", # Ambiguous variable name
"UP007", # X | Y style Unions
]

Expand Down
2 changes: 1 addition & 1 deletion src/peft/tuners/adalora/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def forward(self, *args, **kwargs):
for n, p in self.model.named_parameters():
if ("lora_A" in n or "lora_B" in n) and self.trainable_adapter_name in n:
para_cov = p @ p.T if "lora_A" in n else p.T @ p
I = torch.eye(*para_cov.size(), out=torch.empty_like(para_cov))
I = torch.eye(*para_cov.size(), out=torch.empty_like(para_cov)) # noqa: E741
I.requires_grad = False
num_param += 1
regu_loss += torch.norm(para_cov - I, p="fro")
Expand Down
4 changes: 2 additions & 2 deletions src/peft/tuners/oft/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _cayley_batch(self, data: torch.Tensor) -> torch.Tensor:
b, r, c = data.shape
# Ensure the input matrix is skew-symmetric
skew = 0.5 * (data - data.transpose(1, 2))
I = torch.eye(r, device=data.device).unsqueeze(0).expand(b, r, c)
I = torch.eye(r, device=data.device).unsqueeze(0).expand(b, r, c) # noqa: E741

# Perform the Cayley parametrization
Q = torch.bmm(I - skew, torch.inverse(I + skew))
Expand All @@ -267,7 +267,7 @@ def _block_diagonal(self, oft_r: torch.Tensor, rank: int) -> torch.Tensor:
def _project_batch(self, oft_r, eps=1e-5):
# scaling factor for each of the smaller block matrix
eps = eps * 1 / torch.sqrt(torch.tensor(oft_r.shape[0]))
I = (
I = ( # noqa: E741
torch.zeros((oft_r.size(1), oft_r.size(1)), device=oft_r.device, dtype=oft_r.dtype)
.unsqueeze(0)
.expand_as(oft_r)
Expand Down

0 comments on commit df81c1a

Please sign in to comment.