-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting memory efficient dropout in flash attention (#23)
1. add dropout to regular flash attention. 2. add philox_cuda_seed_offset to increment offset of pytorch's philox random generator's state. --------- Co-authored-by: Clement Chan <[email protected]>
- Loading branch information
1 parent
13664fc
commit ee91638
Showing
9 changed files
with
308 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import torch | ||
import triton | ||
import triton.language as tl | ||
|
||
def philox_cuda_seed_offset(increment, device=None): | ||
device = device or torch.cuda.current_device() | ||
gen = torch.cuda.default_generators[device] | ||
state_copy = gen.get_state() | ||
c0, c1 = state_copy.view(torch.int64) | ||
seed, offset = int(c0), int(c1) | ||
increment = (increment + 3) // 4 * 4 | ||
c1 += increment | ||
# get_state returns a new tensor, so it needs set_state to update the actual generator state. | ||
gen.set_state(state_copy) | ||
return seed, offset |
Oops, something went wrong.