Skip to content
Open
Show file tree
Hide file tree
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.2
rev: v0.15.12
hooks:
# Run the linter.
- id: ruff
Expand All @@ -18,7 +18,7 @@ repos:
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude_types:
Expand Down
12 changes: 7 additions & 5 deletions src/neurosis/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@ def forward(

b, _, _ = q.shape
q, k, v = map(
lambda t: t.unsqueeze(3)
.reshape(b, t.shape[1], self.heads, self.dim_head)
.permute(0, 2, 1, 3)
.reshape(b * self.heads, t.shape[1], self.dim_head)
.contiguous(),
lambda t: (
t.unsqueeze(3)
.reshape(b, t.shape[1], self.heads, self.dim_head)
.permute(0, 2, 1, 3)
.reshape(b * self.heads, t.shape[1], self.dim_head)
.contiguous()
),
(q, k, v),
)

Expand Down
12 changes: 7 additions & 5 deletions src/neurosis/modules/diffusion/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ def attention(self, h_: Tensor) -> Tensor:
q, k, v = map(lambda x: rearrange(x, "b c h w -> b (h w) c"), (q, k, v))

q, k, v = map(
lambda t: t.unsqueeze(3)
.reshape(B, t.shape[1], 1, C)
.permute(0, 2, 1, 3)
.reshape(B * 1, t.shape[1], C)
.contiguous(),
lambda t: (
t.unsqueeze(3)
.reshape(B, t.shape[1], 1, C)
.permute(0, 2, 1, 3)
.reshape(B * 1, t.shape[1], C)
.contiguous()
),
(q, k, v),
)
out = xops.memory_efficient_attention(q, k, v, attn_bias=None, op=self.attention_op)
Expand Down
Loading