Skip to content

[Feature] Port GRPO chunked/hidden-state optimizations to ORPO/DPO/CPO trainers #5291

Closed

Description

@Ola-Vish

Hi guys! First off, thank you for the great library!

When I read about all the optimizations you did to enable RL GRPO with 7x longer context, I was super excited. However, I was a bit sad to find out that this optimization doesn't seem to be wired into the other preference trainer types yet.

Reading through the auto-generated unsloth_compiled_cache/UnslothORPOTrainer.py (and the DPO/CPO equivalents), I noticed the loss-computation methods (concatenated_forward, get_batch_logps, odds_ratio_loss, get_batch_loss_metrics) are essentially stock TRL.

Specifically, concatenated_forward materializes the full [2*B, S, V] logits tensor and runs a standard nn.CrossEntropyLoss over it. So, as far as I can tell:

ORPO/DPO/CPO end up running TRL's preference loss math on top of an Unsloth-patched model and training loop.

But the loss path itself doesn't use any of the memory-efficient chunked / hidden-state infrastructure that SFT and GRPO use to avoid materializing the full vocab tensor.

I think the other trainer types would massively benefit from the same optimizations you built for GRPO. Is there a plan to add these optimizations in the future, or am I missing some technical limitation why it won't work for these loss types?

I'd love to hear your thoughts 😄

Activity

  1. added
    feature request
    on May 5, 2026
  2. liordon commented on May 17, 2026

    @liordon

    huh, I encountered the same issue and was wondering whether that was on purpose. thatnks for bringing this up!

    is there a reason not to optimize this specific part?

  3. assafmu commented on May 17, 2026

    @assafmu

    Same! I've noticed the improvement for GRPO, but was kinda surprised I didn't notice any change for ORPO. Thought I mis-configured something, turns out the optimization wasn't implemented yet.

  4. daniella184 commented on May 17, 2026

    @daniella184

    Super interesting issue! I’ve seen the GRPO speed/memory gains too and was also hoping ORPO/DPO/CPO would benefit from the same tricks..
    Curious if you already have some workaround or internal approach for this, or if it’s something that’s planned soon

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

Metadata

Metadata

Assignees

Labels

feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions