Skip to content

[Bug] TypeError: _get_per_token_logps() takes 5 positional arguments but 6 were given in GRPO training #2916

Closed

Description

@behroozazarkhalili

Bug Description

When attempting to train with GRPO (Group Relative Policy Optimization) using Unsloth, a TypeError occurs due to a method signature mismatch in the compiled cache.

  1. Did you update? Yes
  2. Colab or Kaggle or local / cloud: Remote Server/Notebook
  3. Number GPUs used, use nvidia-smi: 1
  4. Which notebook? Qwen2.5-3B and Gemma-3-1B-it
  5. Which Unsloth version, TRL version, transformers version, PyTorch version? (see below)
  6. Which trainer? GRPOTrainer

Environment

  • Unsloth version: 2025.7.1
  • unsloth_zoo version: 2025.7.1
  • TRL version: 0.19.1
  • Transformers version: 4.53.1
  • PyTorch version: 2.7.0
  • bitsandbytes version: 0.46.1
  • Python version: 3.11
  • Operating System: Linux
  • GPU: CUDA-enabled

Steps to Reproduce

  1. Install Unsloth 2025.7.1 with TRL 0.19.1
  2. Set up a GRPO trainer with Qwen2.5 model
  3. Call trainer.train() on the GRPO trainer

Expected Behavior

Training should proceed without errors.

Actual Behavior

The following error occurs:
TypeError: _UnslothGRPOTrainer._get_per_token_logps() takes 5 positional arguments but 6 were given

Full Error Traceback

File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/unsloth_compiled_cache/UnslothGRPOTrainer.py:1988, in
_UnslothGRPOTrainer.compute_loss.<locals>.<lambda>(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)
-> 1988 get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids,
attention_mask, logits_to_keep, batch_size) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask,
logits_to_keep, batch_size, compute_entropy)['logps']

TypeError: _UnslothGRPOTrainer._get_per_token_logps() takes 5 positional arguments but 6 were given

Root Cause

The issue is in the generated UnslothGRPOTrainer.py file at line 1958, where the lambda function calls self._get_per_token_logps() with a batch_size parameter, but the
method signature only accepts 4 parameters plus self:

get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids,
attention_mask, logits_to_keep, batch_size) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask,
logits_to_keep, batch_size, compute_entropy)['logps']


Additional Context

This appears to be a compatibility issue between the latest versions of Unsloth and TRL, likely introduced in recent updates to the method signatures.

Activity

  1. rolandtannous commented on Jul 10, 2025

    @rolandtannous
    Contributor

    @behroozazarkhalili
    we just made a new release that should solve this problem for you.
    If you're running the code on a local vm, make sure to upgrade your install of unsloth via

    pip install --force-reinstall --upgrade unsloth-zoo
    pip install --force-reinstall --upgrade unsloth
    

    On the other hand, If you're running the notebooks on colab no need to do introduce any changes to the install cells as the notebook will grab the newest version from pypi for you anyway.

    Make sure to leave a comment if this doesn't work out for you and we'll take it from there.

  2. MadBonzz commented on Jul 10, 2025

    @MadBonzz

    I am getting the same issue. Using unsloth/Qwen3-1.7B-Base model. The error comes when I run trainer.train().

    This is the link to the colab notebook : https://colab.research.google.com/drive/1JcdaNYhwP4iYyzoRxjdaKs53pGJX_qcq?usp=sharing
    I am running running it on colab via the kaggle jupyter server. On kaggle, the model itself is unable to load. This is the error I get on kaggle for loading the model :
    Unsupported conversion from f16 to f16
    LLVM ERROR: Unsupported rounding mode for conversion.
    RuntimeError: PassManager::run failed

  3. behroozazarkhalili commented on Jul 10, 2025

    @behroozazarkhalili
    Author

    pip install --force-reinstall --upgrade unsloth-zoo

    Environment

    • Unsloth version: 2025.7.2
    • unsloth_zoo version: 2025.7.4
    • TRL version: 0.19.1
    • Transformers version: 4.53.1
    • PyTorch version: 2.7.1
    • bitsandbytes version: 0.46.1
    • peft: 0.16.0
    • Python version: 3.11
    • Operating System: Linux
    • GPU: CUDA-enabled

    No! The issue is still there! I have followed all the instructions you gave. :(
    The identical error was raised again.

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    Cell In[5], line 1
    ----> 1 trainer.train()
    
    File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/grpo_qwen.py:399, in GRPOModelTrainer.train(self)
        385         trainer = GRPOTrainer(
        386                     model=self.model,
        387                     processing_class=self.tokenizer,
       (...)    396             train_dataset=dataset,
        397 )
        398         logger.info("Beginning GRPO training...")
    --> 399         trainer.train()
        400         logger.info("Training completed!")
    
    File ~/.conda/envs/behrooz/lib/python3.11/site-packages/transformers/trainer.py:2206, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
       2204         hf_hub_utils.enable_progress_bars()
       2205 else:
    -> 2206     return inner_training_loop(
       2207         args=args,
       2208         resume_from_checkpoint=resume_from_checkpoint,
       2209         trial=trial,
       2210         ignore_keys_for_eval=ignore_keys_for_eval,
       2211     )
    
    File <string>:323, in _fast_inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
    
    File <string>:34, in _unsloth_training_step(self, model, inputs, num_items_in_batch)
    
    File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/unsloth_compiled_cache/UnslothGRPOTrainer.py:1990, in _UnslothGRPOTrainer.compute_loss(self, model, inputs, return_outputs, num_items_in_batch)
       1986 _logits_to_keep = logits_to_keep
       1988 get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids, attention_mask, logits_to_keep, batch_size) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)['logps']
    -> 1990 per_token_logps = get_logps_func(model, input_ids, attention_mask, logits_to_keep)
       1992 # Compute the KL divergence between the model and the reference model
       1993 # _prepare_inputs doesn't return reference log probs anymore. We need to calculate it ourselves.
       1994 # https://github.com/huggingface/trl/blob/05bc43e960396581e458195b8388efe6b82cae1f/trl/trainer/grpo_trainer.py#L1328
       1995 if self.beta != 0.0:
    
    File ~/GRPO-Unsloth-Finetuning/GRPO-Qwen-Finetuning-Unsloth/unsloth_compiled_cache/UnslothGRPOTrainer.py:1988, in _UnslothGRPOTrainer.compute_loss.<locals>.<lambda>(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)
       1985 _input_ids = input_ids
       1986 _logits_to_keep = logits_to_keep
    -> 1988 get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids, attention_mask, logits_to_keep, batch_size) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)['logps']
       1990 per_token_logps = get_logps_func(model, input_ids, attention_mask, logits_to_keep)
       1992 # Compute the KL divergence between the model and the reference model
       1993 # _prepare_inputs doesn't return reference log probs anymore. We need to calculate it ourselves.
       1994 # https://github.com/huggingface/trl/blob/05bc43e960396581e458195b8388efe6b82cae1f/trl/trainer/grpo_trainer.py#L1328
    
    TypeError: _UnslothGRPOTrainer._get_per_token_logps() takes 5 positional arguments but 6 were given

    I specifically mentioned the line issue, and it seems that it has been changed in the new version.

  4. Lucas-Fernandes-Martins commented on Jul 10, 2025

    @Lucas-Fernandes-Martins

    Hi, I think the problem is line 376 of rl_replacements.py:

            get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids, attention_mask, logits_to_keep, batch_size) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)['logps']
    
    

    Function _get_per_token_logps accepts only 5 parameters:

       def _get_per_token_logps(self, model, input_ids, attention_mask, logits_to_keep):
    

    So it seems one must add the batch_size argument to the function signature?

  5. rolandtannous commented on Jul 10, 2025

    @rolandtannous
    Contributor

    @Lucas-Fernandes-Martins already pushed a fix , Should be hopefully merged soon :)

  6. Lucas-Fernandes-Martins commented on Jul 10, 2025

    @Lucas-Fernandes-Martins

    Thank you :) that was so quick

  7. behroozazarkhalili commented on Jul 11, 2025

    @behroozazarkhalili
    Author

    @Lucas-Fernandes-Martins already pushed a fix , Should be hopefully merged soon :)

    #863 and #2910 back again after this update to the merged version.

  8. rolandtannous commented on Jul 12, 2025

    @rolandtannous
    Contributor

    closing this as _get_per_token_logps() issue is resolved
    let's follow up on the absmax issue on thread #2910

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

    bugfixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions