Skip to content

Commit

Permalink
Fix in-place modification when autotuning triton Lion update
Browse files Browse the repository at this point in the history
  • Loading branch information
yousufmo authored Mar 19, 2024
1 parent 6629519 commit 974b754
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions lion_pytorch/triton.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
print('triton is not installed, please install by running `pip install triton -U --pre`')
exit()

# clone param and exp_avg before autotuning takes place
# as those are updated in-place

def clone_inplace_updated_params(nargs):
nargs['p_ptr'] = nargs['p_ptr'].clone()
nargs['exp_avg_ptr'] = nargs['exp_avg_ptr'].clone()

# triton cuda kernel

@triton.autotune(configs = [
triton.Config({'BLOCK_SIZE': 128}, num_warps = 4, pre_hook = clone_inplace_updated_params),
triton.Config({'BLOCK_SIZE': 1024}, num_warps = 8, pre_hook = clone_inplace_updated_params),
], key = ['n_elements'])
triton.Config({'BLOCK_SIZE': 128}, num_warps = 4),
triton.Config({'BLOCK_SIZE': 1024}, num_warps = 8),
], key = ['n_elements'], restore_value=['p_ptr', 'exp_avg_ptr'])
@triton.jit
def update_fn_kernel(
p_ptr,
Expand Down

0 comments on commit 974b754

Please sign in to comment.