Support Chunked DPO Loss Kernel#378
Conversation
| run_benchmarks, | ||
| ) | ||
|
|
||
| from liger_kernel.alignment.dpo_loss import HF_DPO_Loss, LigerFusedLinearDPOFunction |
There was a problem hiding this comment.
Should I use HF DPO impl here in benchmarking for function reusability purpose? Or write another naive impl in pure torch?
| return grad_input, grad_weight, None, grad_bias, None, None, None | ||
|
|
||
|
|
||
| class HF_DPO_Loss: |
There was a problem hiding this comment.
Should I move this HF impl to file test_dpo_loss.py?
There was a problem hiding this comment.
yes, since HF impl is only for testing purpose
|
can we modify |
pramodith
left a comment
There was a problem hiding this comment.
Just a FYI, I think we should wait until @shivam15s pushes a generic/inheritable class that handles all the chunking and other repetitive logic common to different loss functions, before pushing new loss functions.
|
Great work @austin362667 ! The additional summing of NLL loss is going to be useful for IRPO loss as well :). I'll be creating a simple base class which adds the boilerplate code (backward/torch compile logic) that you can inherit from, as @pramodith mentioned |
76017b7 to
b88708d
Compare
|
Issue addressed. Thanks @Tcc0403 @lancerts @pramodith @shivam15s and @ByronHsu for review! |
|
I think we should make chunked_loss functions nn.Module (like flce and fljsd) for users? same for orpo? cc @shivam15s @ByronHsu |
|
@Tcc0403 that is the plan! |
Signed-off-by: Austin Liu <austin362667@gmail.com> Fix benchmark script
Signed-off-by: Austin Liu <austin362667@gmail.com>
Signed-off-by: Austin Liu <austin362667@gmail.com>
Signed-off-by: Austin Liu <austin362667@gmail.com>
a995bc4 to
854c1b3
Compare
Summary
Add support for a fused, torch-compiled, and chunked DPO (Direct Preference Optimization) loss kernel, as requested in #371.
This implementation is largely based on the excellent work done on ORPO (#362) by @shivam15s.
DPO Loss Formulation
In a reference setting:
Corresponds to:
Testing Done
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence