Skip to content

Conversation

@NanoCode012
Copy link
Collaborator

@NanoCode012 NanoCode012 commented Jul 8, 2025

Description

RL trainer cls plugin does not pass self.model causing TypeError: AtroposGRPOTrainer.__init__() missing 1 required positional argument: 'model'

https://discord.com/channels/1104757954588196865/1117071926926512248/1392125907963084913

Motivation and Context

How has this been tested?

Untested!

Screenshots (if appropriate)

Types of changes

Social Handles (Optional)

Summary by CodeRabbit

  • Refactor
    • Improved the logic for selecting and initializing trainer classes for reinforcement learning workflows, resulting in clearer and more maintainable code. No changes to user-facing features or functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 8, 2025

Walkthrough

The control flow for trainer class selection and argument preparation in the RL trainer builder was refactored. The _get_trainer_cls method no longer handles trainer arguments and now simply returns the trainer class. Argument handling was relocated to the build method, and logic for DPO/IPO trainer selection was streamlined.

Changes

File(s) Change Summary
src/axolotl/core/builders/rl.py Refactored _get_trainer_cls to remove argument handling; updated build to prepare arguments; simplified DPO/IPO trainer selection logic; updated method signature.

Sequence Diagram(s)

sequenceDiagram
    participant Builder as HFRLTrainerBuilder
    participant TrainerClass as Trainer Class

    Builder->>Builder: build()
    Builder->>Builder: _get_trainer_cls()
    Builder-->>TrainerClass: Returns selected trainer class
    Builder->>Builder: Prepare trainer arguments
    Builder->>TrainerClass: Instantiate with arguments
Loading

Suggested labels

ready to merge

Poem

In the warren of code, I hop and refactor,
Trainer class logic now simpler, no need for an actor.
Arguments moved, concerns now apart,
Like carrots and lettuce, each has its part.
With streamlined selection, I bounce with delight—
The RL builder’s future is looking quite bright! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c6a6ea and d47093f.

📒 Files selected for processing (1)
  • src/axolotl/core/builders/rl.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/axolotl/core/builders/rl.py (6)
src/axolotl/core/trainers/dpo/trainer.py (1)
  • AxolotlDPOTrainer (19-102)
src/axolotl/integrations/base.py (6)
  • cfg (350-351)
  • cfg (354-355)
  • PluginManager (312-634)
  • get_instance (341-347)
  • get_trainer_cls (148-156)
  • get_trainer_cls (477-491)
src/axolotl/utils/schemas/enums.py (1)
  • RLType (24-32)
src/axolotl/core/trainers/grpo/__init__.py (4)
  • GRPOStrategy (21-176)
  • get_trainer_class (25-30)
  • set_trainer_args (112-122)
  • set_trainer_kwargs (125-132)
src/axolotl/core/trainers/dpo/__init__.py (1)
  • get_trainer_class (11-12)
src/axolotl/core/builders/base.py (2)
  • model_ref (72-73)
  • model_ref (76-77)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: pre-commit
  • GitHub Check: PyTest (3.11, 2.6.0)
  • GitHub Check: PyTest (3.11, 2.7.1)
  • GitHub Check: pre-commit
  • GitHub Check: PyTest from Source Dist (3.11, 2.6.0)
  • GitHub Check: PyTest (3.11, 2.5.1)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.1)
  • GitHub Check: PyTest from Source Dist (3.11, 2.5.1)
🔇 Additional comments (5)
src/axolotl/core/builders/rl.py (5)

9-9: Import addition looks correct.

The direct import of AxolotlDPOTrainer is necessary since the code now references it directly instead of going through DPOStrategy.get_trainer_class().


40-47: Method signature simplification is well-designed.

The _get_trainer_cls method is now focused on a single responsibility - returning the trainer class. Removing the trainer_kwargs parameter and the tuple return makes the method cleaner and more focused.


56-56: Direct trainer class assignment is consistent with the refactoring.

Using AxolotlDPOTrainer directly instead of DPOStrategy.get_trainer_class() aligns with the architectural change and is consistent with the import added on line 9.


176-184: Critical fix properly addresses the missing model parameter issue.

The key improvement is on line 177 where trainer_cls_args = [self.model] ensures the model is always passed as the first argument to the trainer constructor. This directly resolves the TypeError mentioned in the PR objectives where the required positional argument model was missing.

The subsequent logic correctly handles additional arguments:

  • For GRPO: extends the args list with strategy-specific arguments
  • For DPO/IPO: appends the reference model

This is a clean separation of concerns that makes the argument handling more explicit and reliable.


192-192: Condition update maintains consistency with the refactoring.

The direct comparison with AxolotlDPOTrainer is consistent with the change on line 56 and maintains the same logical behavior while being more direct.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@NanoCode012 NanoCode012 changed the title fix: pass model to plugin for rl trainer builder fix: pass model to plugin trainer_cls for rl trainer builder Jul 8, 2025
@codecov
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/axolotl/core/builders/rl.py 91.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@winglian winglian left a comment

Choose a reason for hiding this comment

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

This pr breaks the contract with plugins that already returns the trainer args.

@NanoCode012 NanoCode012 marked this pull request as draft July 9, 2025 01:53
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