[Fix] Fix the Error of q, k, and v states must have the same dtype when using flash attention forward. #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Step for Error Reproduction
Once we enable the argument
use_cache=True
in the Hugging Face generation_config something like the following:You can simply pass the generation config with
use_cache=True
to model and make it forward as usual, and I believe you'll get the error I met.Error Message
I will get the following error message: "query and key must have the same dtype". And I found that this is due to the misalignment between the
dtype
ofquery_state
andvalue_state
.Potential Solution
I guess there exists potential casting for q, k, and v states. Hence, I try to cast back the
dtype
of q, k, and v to the same targetdtype
.Reference
The committed code I wrote strongly refers to the existing implementation in mergoo.