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

Refactor LigerFusedLinearPreferenceBase #381

Merged

Conversation

pramodith
Copy link
Collaborator

Summary

This PR refactors the LigerFusedLinearPreferenceBase class to contain an abstractmethod corresponding to the calculation of the loss that needs to be implemented by all sub-classes.

It also adds a new function to the class called _compute_loss which is mostly the same as the _compute_orpo_loss function introduced in #362 but makes it generic to calculate the NLL/Cross Entropy Loss plus accepts a custom loss function that implements a new alignment loss function.

Most RLHF/RLAIF/Alignment algorithms state their final loss as NLL + Beta * (Alignment_Loss) so adding the NLL logic inside the base class reduces repeated code.

The _compute_loss function accepts

Testing Done

On A100-80G-SXM

  • Hardware Type:
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

@shivam15s
Copy link
Collaborator

This was quick. Great refactor!

shivam15s
shivam15s previously approved these changes Nov 14, 2024
Copy link
Collaborator

@shivam15s shivam15s left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines 47 to 50
_input,
weight,
target,
bias,
Copy link
Collaborator

@shivam15s shivam15s Nov 14, 2024

Choose a reason for hiding this comment

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

nit: I wrongly assumed that forward just takes positional arguments.
Could you also make input, weight target, bias keyword args?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Copy link
Collaborator

@shivam15s shivam15s left a comment

Choose a reason for hiding this comment

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

lgtm

@pramodith pramodith merged commit 2281b7e into linkedin:main Nov 14, 2024
1 of 3 checks passed
@pramodith pramodith deleted the pramodith/preference_loss_interface branch November 15, 2024 14:46
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.

2 participants