Skip to content

GRPO: forward TRL 1.7 VLM kwargs (spatial_shapes / num_tiles / image_position_ids) in the logprob replacement #6960

Closed

Description

@danielhanchen

Summary

Unsloth's optimized GRPO _get_per_token_logps_and_entropies replacement (unsloth/models/rl_replacements.py) does not forward the newer TRL 1.7 multimodal kwargs spatial_shapes, num_tiles, and image_position_ids when recomputing per-token logprobs.

TRL 1.7's own _get_per_token_logps_and_entropies accepts these and threads them into model_inputs (per-tile / per-image slicing), so for VLM architectures that require them (for example LFM2-VL and other image-position / tiled vision models), GRPO under Unsloth omits required vision inputs when recomputing old/ref logprobs, causing failures or incorrect logprobs.

The common pixel_values + image_grid_thw path (Qwen2/2.5-VL etc.) already forwards correctly; this only affects models that depend on the newer fields.

Why it is tracked separately

Forwarding these correctly means replicating TRL's per-tile slicing (num_tiles cumsum for spatial_shapes, image_position_ids[img_start:img_end]) through the two chunk-construction paths in the replacement. That cannot be validated on the CPU-only fake-run canary and needs a real tiled VLM (for example LFM2-VL) under GRPO on GPU to confirm, so it is intentionally out of scope for the TRL >= 1.7 crash/arity fix in #6904.

Acceptance

  • Extract spatial_shapes / num_tiles / image_position_ids from kwargs in the replacement.
  • Slice them per chunk consistently with pixel_values / image_grid_thw, matching TRL 1.7's boundaries.
  • Validate logprob parity against stock TRL GRPO on a tiled VLM.

Ref: #6904 review thread.

Activity

  1. added 3 commits that reference this issue on Sep 16, 2026
    e50be2c
    13e724a
    878103b
  2. added a commit that references this issue on Sep 17, 2026
    448bf6b
  3. added a commit that references this issue on Sep 29, 2026
    b4af5fb
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions