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

Update sub_quadratic_attention.py #10266

Merged
merged 1 commit into from
May 11, 2023
Merged

Update sub_quadratic_attention.py #10266

merged 1 commit into from
May 11, 2023

Conversation

nero-dv
Copy link
Contributor

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

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.
@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
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