Align KTO with DPO: Align _precompute_ref_logps#5714
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d4484bc. Configure here.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Align KTO with DPO: Align _precompute_ref_logps.
This PR introduces a caching mechanism for precomputing reference log probabilities in the
KTOTrainer, which significantly improves efficiency by avoiding redundant computations. The main changes involve adding new imports, integrating a hash-based cache file system using numpy, and updating the dataset with cached results.Part of:
Changes
Caching and efficiency improvements:
reference_logpsandreference_KL_logps) to a numpy.npzfile, identified by a hash of the dataset and model. On subsequent runs, the code loads from cache if available, reducing redundant computation.hash_moduleanddatasets.fingerprint.Hasherto generate unique cache fingerprints based on the model and dataset, ensuring cache correctness.Dependency and import updates:
os,numpy, andhash_moduleto support caching and hashing functionality.These changes collectively improve the performance and reproducibility of the reference log probability computation process.
Note
Medium Risk
Adds cross-run caching and fingerprint manipulation in
KTOTrainer._precompute_ref_logps, which can affect training correctness if the cache key or synchronization is wrong and introduces file I/O in distributed runs.Overview
KTOTrainer._precompute_ref_logpsnow caches precomputed reference log probabilities to a compressed.npzfile keyed by a fingerprint of the dataset, the (ref) model weights (hash_module), and whether KL is computed.On subsequent runs it loads
reference_logps(andreference_KL_logpswhen enabled) from cache instead of recomputing, and updates dataset columns while settingnew_fingerprintto reflect the cached content for reproducibility across runs/processes.Reviewed by Cursor Bugbot for commit a396005. Bugbot is set up for automated code reviews on this repo. Configure here.