Skip to content

Update sub_quadratic_attention.py#10266

Merged
AUTOMATIC1111 merged 1 commit into
AUTOMATIC1111:devfrom
nero-dv:dev
May 11, 2023
Merged

Update sub_quadratic_attention.py#10266
AUTOMATIC1111 merged 1 commit into
AUTOMATIC1111:devfrom
nero-dv:dev

Conversation

@nero-dv

@nero-dv nero-dv commented May 11, 2023

Copy link
Copy Markdown
Contributor

Fixes modules/sub_quadratic_attention.py:205

TODO: maybe we should use torch.empty_like(query) to allocate storage in-advance, and pass slices to be mutated, instead of torch.cat()ing the returned slices

  1. Determine the number of query chunks.
  2. Calculate the final shape of the res tensor.
  3. Initialize the tensor with the calculated shape and dtype, (same dtype as the input tensors, usually)

Can initialize the tensor as a zero-filled tensor with the correct shape and dtype, then compute the attention scores for each query chunk and fill the corresponding slice of tensor.

1. Determine the number of query chunks.
2. Calculate the final shape of the res tensor.
3. Initialize the tensor with the calculated shape and dtype, (same dtype as the input tensors, usually)

Can initialize the tensor as a zero-filled tensor with the correct shape and dtype, then compute the attention scores for each query chunk and fill the corresponding slice of tensor.
@nero-dv nero-dv requested a review from AUTOMATIC1111 as a code owner May 11, 2023 03:09
@AUTOMATIC1111 AUTOMATIC1111 merged commit c9e5b92 into AUTOMATIC1111:dev May 11, 2023
AUTOMATIC1111 added a commit that referenced this pull request May 11, 2023
@AUTOMATIC1111

Copy link
Copy Markdown
Owner

I don't think you did any testing on this. np is not imported, and after that is fixed, any generation is just broken because your implementation returns incorrect sizes at dimension 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants