Skip to content

[Docs] Update DPO example to use DPOConfig instead of TrainingArguments #4155

Closed

Description

@pesuchin

Description

The current DPO example code in the documentation causes an AttributeError because it uses TrainingArguments from transformers instead of DPOConfig from trl. Recent versions of trl require DPOConfig for the DPOTrainer to properly handle DPO-specific arguments like padding_value.

URL: https://unsloth.ai/docs/get-started/reinforcement-learning-rl-guide/preference-dpo-orpo-and-kto

Error Log

Traceback (most recent call last):
  File "/workspace/work/main.py", line 74, in <module>
    dpo_trainer = DPOTrainer(
                  ^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/unsloth/trainer.py", line 314, in new_init
    original_init(self, *args, **kwargs)
  ...
  File "/workspace/work/unsloth_compiled_cache/UnslothDPOTrainer.py", line 903, in __init__
    if args.padding_value is not None:
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'TrainingArguments' object has no attribute 'padding_value'

Environment

  • unsloth: 2026.3.3
  • trl: 0.23.1
  • transformers: 4.57.1

Suggested Fix

Replacing TrainingArguments with DPOConfig resolves the issue.

Current:

from transformers import TrainingArguments
...
dpo_trainer = DPOTrainer(
    model = model,
    args = TrainingArguments(
        ...
    ),
)

Proposed:

from trl import DPOConfig # Changed from TrainingArguments
...
dpo_trainer = DPOTrainer(
    model = model,
    args = DPOConfig( # Use DPOConfig
        per_device_train_batch_size = 4,
        ...
    ),
)

How can I contribute?

I would like to submit a Pull Request to update the documentation if this is acceptable. However, I couldn't find the source files for the documentation (GitBook) in this repository.

Could you please guide me on where the documentation source is located or how I should proceed with a PR?

Activity

  1. added
    help wanted
    on Mar 5, 2026
  2. adityaghai07 commented on Mar 5, 2026

    @adityaghai07
    Contributor

    @Datta0 would appreciate if you could guide me aswell on how do I contribute on the documentations part aswell. I am a previous contributor and felt there were some docs which could be improved. Thank You!

  3. shimmyshimmer commented on Mar 5, 2026

    @shimmyshimmer
    Member

    Hello @pesuchin I have updated the docs to include it thank you for your help: https://unsloth.ai/docs/get-started/reinforcement-learning-rl-guide/preference-dpo-orpo-and-kto

    Currently we do not have a public Github for our docs. Maybe in the future.

    @adityaghai07 if you have any suggestions let me know an overview where improvements are needed thank you so much!

  4. adityaghai07 commented on Mar 6, 2026

    @adityaghai07
    Contributor

    @shimmyshimmer

    First of all, thank you for the amazing docs. They help the community a lot and are genuinely one of the easiest resources to follow when getting started with Unsloth.

    I wanted to start by pointing out a few small typos. They are minor, but since the docs are frequently visited, fixing them would slightly improve the overall reading experience.

    Typos

    1. "unquatinzed" → "unquantized"
      https://docs.unsloth.ai/get-started/fine-tuning-guide
    Image
    1. "internaly" → "internally"
      https://docs.unsloth.ai/basics/gpt-oss-how-to-run-and-fine-tune
    Image
    1. "A bit issue" → "A big issue"
      Appears in multiple places:
    Image

    Technical Details

    RAG vs Fine-tuning claim (Fine-tuning Guide)

    Current statement:

    Fine-tuning can replicate all of RAG's capabilities, but not vice versa
    

    This feels slightly oversimplified and could be misleading for beginners. It might help to clarify that the two approaches serve different purposes. Fine-tuning is typically used for behavior, style, or task adaptation, while RAG is better suited for dynamic or frequently changing knowledge.


    Hyperparameter Tuning

    Page: Hyperparameters Guide

    The current section is already quite good for beginners. One small suggestion would be to expand slightly on learning rate intuition and guide users through a few key questions before choosing hyperparameters.

    For example, it might help to prompt users to think about things like:

    • What is your model size?
    • What is your effective batch size?
    • How much training data do you have?
    • How complex is the task you are fine-tuning for?

    These factors heavily influence good hyperparameter choices, especially the learning rate. In many setups, the learning rate can also scale with the effective batch size, so mentioning that relationship could help users reason about adjustments rather than relying only on fixed defaults.

    Adding a short explanation around this decision process could help beginners better understand why certain hyperparameters work, not just which ones to use.


    Overall, the docs are already very strong. These are just a few small suggestions that might make them even clearer and more polished. Will try to get back with more!
    Thank You!

  5. added a commit that references this issue on Mar 14, 2026
    b6a69df
  6. hnshah commented on Mar 23, 2026

    @hnshah

    Documentation Location

    The Unsloth documentation at https://unsloth.ai/docs is hosted on GitBook and the source files are not in this repository. The documentation is managed externally by the Unsloth team.

    How to Contribute This Fix

    Since the docs aren't in the repo, here are your options:

    Option 1: Let the maintainers handle it ✅ (Easiest)

    The Unsloth team monitors issues labeled good first issue. Since you've clearly documented:

    • The problem (AttributeError with TrainingArguments)
    • The fix (use DPOConfig instead)
    • The exact code changes needed

    They can update the GitBook docs directly. This issue is well-written and actionable as-is!

    Option 2: Create a PR with an example ⚡

    Since the docs source isn't accessible, you could:

    1. Create a working example file in the repo (e.g., examples/dpo_correct_usage.py)
    2. Show the correct DPOConfig usage
    3. Link to it from this issue

    Example:

    # examples/dpo_training_example.py
    from unsloth import FastLanguageModel
    from trl import DPOTrainer, DPOConfig  # ✅ Use DPOConfig, not TrainingArguments
    
    model, tokenizer = FastLanguageModel.from_pretrained(...)
    
    dpo_trainer = DPOTrainer(
        model=model,
        args=DPOConfig(  # ✅ Correct
            per_device_train_batch_size=4,
            gradient_accumulation_steps=4,
            warmup_steps=10,
            learning_rate=5e-5,
            num_train_epochs=1,
            logging_steps=1,
            output_dir="outputs",
        ),
        ...
    )

    This gives the team a tested reference to update the docs from.

    Option 3: Engage on Discord/Slack 💬

    If Unsloth has a community Discord or Slack, you could share this there for faster visibility.


    My recommendation: This issue is perfect as-is. The maintainers have everything they need to update the GitBook docs. If you want to go further, Option 2 (PR with working example) would be valuable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions