Skip to content

Conversation

@behroozazarkhalili
Copy link
Collaborator

Summary

Resolves #4395

This PR moves all Mergekit-related functionality to the experimental submodule (trl.experimental.mergekit) as part of v1.0 preparations. The Mergekit integration has seen low usage and may be deprecated or removed in future versions.

Changes

Module Structure

  • Created trl/experimental/mergekit/ module with:
    • mergekit_utils.py - Core mergekit utilities (moved from trl/mergekit_utils.py)
    • callbacks.py - MergeModelCallback class (extracted from trl/trainer/callbacks.py)
    • __init__.py - Module exports

Removed from Main API

  • Removed MergeModelCallback from trl/__init__.py exports
  • Removed MergeModelCallback from trl/trainer/__init__.py exports
  • Removed MergeModelCallback class from trl/trainer/callbacks.py
  • Removed unused imports (is_mergekit_available, MergeConfig, merge_models, upload_model_to_hf)

Updated Imports

  • Updated tests/test_callbacks.py to import from trl.experimental.mergekit
  • All tests continue to work with experimental module

Documentation

  • Updated docs/source/callbacks.md with:
    • Removed MergeModelCallback from main callbacks section
    • Added "Experimental Callbacks" section explaining the move
    • Provided migration example for users

Migration Guide

Before

from trl import MergeModelCallback
from trl.mergekit_utils import MergeConfig

config = MergeConfig()
merge_callback = MergeModelCallback(config)

After

from trl.experimental.mergekit import MergeConfig, MergeModelCallback

config = MergeConfig()
merge_callback = MergeModelCallback(config)

Rationale

As noted in issue #4395:

"I'm not seeing any usage for this part of the library, we may remove it in the future."

Moving to the experimental submodule:

  • Signals potential deprecation to users
  • Maintains backward compatibility through experimental namespace
  • Allows for removal in v1.0 or later if usage doesn't materialize
  • Keeps main API focused on core, well-used features

Testing

  • All existing tests continue to pass with updated imports
  • @require_mergekit decorator still works correctly
  • No changes to functionality, only module location

Breaking Change

⚠️ This is a breaking change for users importing MergeModelCallback from the main trl module. Users will need to update their imports to use trl.experimental.mergekit instead.

Resolves #4404

- Remove SIMPLE_CHAT_TEMPLATE import from 7 trainer scripts
- Remove chat template setting for non-SFT trainers (DPO, CPO, ORPO, PPO, Nash-MD, XPO, Online DPO)
- Chat templates only make sense for SFT (instruction tuning), not for preference optimization or reward-based training
- Scripts modified:
  - examples/scripts/online_dpo.py
  - examples/scripts/orpo.py
  - examples/scripts/cpo.py
  - examples/scripts/nash_md.py
  - examples/scripts/xpo.py
  - examples/scripts/ppo/ppo.py
  - examples/scripts/ppo/ppo_tldr.py
Resolves #4395

- Move mergekit_utils.py to trl/experimental/mergekit/
- Move MergeModelCallback to trl/experimental/mergekit/callbacks.py
- Create trl/experimental/mergekit/__init__.py for module exports
- Remove MergeModelCallback from main trl exports (trl/__init__.py, trl/trainer/__init__.py)
- Remove MergeModelCallback from trl/trainer/callbacks.py
- Update test imports to use trl.experimental.mergekit
- Update callbacks documentation with experimental status note

This change consolidates underutilized Mergekit functionality into the
experimental namespace as part of v1.0 preparations. The module may be
deprecated or removed in future versions if usage does not materialize.

To use MergeModelCallback after this change:
```python
from trl.experimental.mergekit import MergeConfig, MergeModelCallback
```
@HuggingFaceDocBuilderDev

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.


[[autodoc]] WeaveCallback

## Experimental Callbacks
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer having a dedicated section under Experimental instead of(like BEMA)

behroozazarkhalili and others added 2 commits November 4, 2025 17:45
… page

- Created docs/source/merge_model_callback.md following BEMA pattern
- Added merge_model_callback to experimental section in _toctree.yml
- Removed inline experimental section from callbacks.md

This addresses reviewer feedback to have a dedicated documentation
page under Experimental section (like BEMA) instead of inline docs.
@behroozazarkhalili
Copy link
Collaborator Author

@qgallouedec I've restructured the MergeModelCallback documentation as requested.

Changes made:

  • ✅ Created dedicated documentation page: docs/source/merge_model_callback.md
  • ✅ Added to Experimental section in _toctree.yml (alphabetically sorted after GSPO)
  • ✅ Removed inline "Experimental Callbacks" section from callbacks.md

Pattern followed: Matches BEMA's structure with dedicated page under Experimental section, including:

  • Feature description
  • Complete usage example
  • Note about experimental status
  • API reference

The MergeModelCallback now has its own dedicated page in the Experimental section, just like BEMA for Reference Model.

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.

Move everything related to Mergekit to the experimental submodule

4 participants