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

Add FP32 and Bias to fulfill the functionalities required by torch.nn.attention.SDPBackend.EFFICIENT_ATTENTION #22

Merged
merged 24 commits into from
May 3, 2024

Conversation

xinyazhang
Copy link
Collaborator

@xinyazhang xinyazhang commented Apr 30, 2024

This PR includes the following major changes

  1. Add Bias support in the Triton kernel, for both forward and backward directions
  2. Add fp32 datatype support, and the corresponding tuning database information
  3. Fix "argument list too long" error during linking
  4. Improved table_tool.py to partially dump/load .csv file, allowing database merging
  5. Refactor the UT to use PyTorch's method to estimate ATOL/RTOL

Known limitations:

  1. Bias assumes real Rank 4 tensor (.expand()-ed ones are unlikely to work) for backward direction. No checking is performed on this requisite and failure may be silent
  2. test_forward.py is still using the old method to estimate ATOL/RTOL

GPU reference code path causes segfaults.
This allows users to select device to compute reference results without
modifying the source file.
Example usage:

```
DB=v2python/rules/tuning_database.sqlite3

python -m v2python.table_tool -k '' --action dumpcsv \
    -f $DB --table_name 'FLASH$attn_fwd' \
    --table_file 'attn_fwd.fp32mi300.csv' \
    --select_where 'inputs$Q_dtype = "torch.float32"'

git checkout another_branch -- $DB

python -m v2python.table_tool -k '' --action loadcsv \
     -f $DB --table_name 'FLASH$attn_fwd' \
     --table_file attn_fwd.fp32mi300.csv \
     --ignore_id
```

Note: --ignored_id does not support cases that 'id' is not the first
column of the CSV file, for simplicity.
If .expand() is called upon a tensor, the result tensor may have one or
more zeros in its stride()
Otherwise the dk result is incorrect for fp32
1. Computed gradients were not stored for future use, which basically
   means the gradients were not tested at all.
2. bias should be created as a Rank 2 tensor and then expand to Rank 4.
Copy link
Collaborator

@groenenboomj groenenboomj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the perf impacts of these changes?

tritonsrc/attn_torch_function.py Show resolved Hide resolved
v2python/rules/tuning_database.sqlite3 Show resolved Hide resolved
@xinyazhang xinyazhang merged commit 00ccbf3 into main May 3, 2024
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.

None yet

2 participants