Skip to content

[Bug] RuntimeError: No executable batch size found, reached zero. #2974

Closed

Description

@behroozazarkhalili
  1. Did you update? Yes
  2. Colab or Kaggle or local / cloud: Remote Server
  3. Number GPUs used, use nvidia-smi: 1
  4. Which notebook? Gemini-1B-GRPO
  5. Which Unsloth version, TRL version, transformers version, PyTorch version?
transformers: 4.51.3
unsloth: 2025.7.3
numpy: 1.26.4
bitsandbytes: 0.46.1
peft: 0.15.2
vllm: 0.9.2
  1. Which trainer? SFTTrainer, GRPOTrainer etc: GRPO Trainer
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[19], line 13
      1 trainer = GRPOTrainer(
      2     model = model,
      3     processing_class = tokenizer,
   (...)
     11     train_dataset = dataset,
     12 )
---> 13 trainer.train()

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/transformers/trainer.py:2245, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   2243         hf_hub_utils.enable_progress_bars()
   2244 else:
-> 2245     return inner_training_loop(
   2246         args=args,
   2247         resume_from_checkpoint=resume_from_checkpoint,
   2248         trial=trial,
   2249         ignore_keys_for_eval=ignore_keys_for_eval,
   2250     )

File ~/.conda/envs/behrooz/lib/python3.11/site-packages/accelerate/utils/memory.py:172, in find_executable_batch_size.<locals>.decorator(*args, **kwargs)
    170 while True:
    171     if batch_size == 0:
--> 172         raise RuntimeError("No executable batch size found, reached zero.")
    173     try:
    174         return function(batch_size, *args, **kwargs)

RuntimeError: No executable batch size found, reached zero.

Activity

  1. behroozazarkhalili commented on Jul 15, 2025

    @behroozazarkhalili
    Author

    The issue is in the GRPOConfig at Gemma3_(1B)_GRPO.ipynb cell 36. The batch size starts at 4, but the accelerate library keeps reducing it when it runs out of memory, eventually reaching 0.

    Solutions:

    1. Reduce per_device_train_batch_size from 4 to 2
    2. Reduce num_generations from 4 to 2
    3. Reduce max_seq_length if possible
    4. Increase gradient_accumulation_steps to maintain effective batch size

    Try this configuration in cell 36:

      training_args = GRPOConfig(
          per_device_train_batch_size = 2,    # Reduce from 4 to 2
          gradient_accumulation_steps = 8,    # Increase from 4 to 8
          num_generations = 2,                # Reduce from 4 to 2
          # ... rest of config unchanged
      )
  2. rolandtannous commented on Jul 15, 2025

    @rolandtannous
    Contributor

    From the provided information, this doesn't look like an unsloth issue for me. While you might be running out of memory and facing that issue, another user with a larger GPU configuration might not be . That's where choice of model but also hyperparameters are supposed to be made by the user himself. The notebooks are meant for illustration purposes of what unsloth is capable of only. For most cases, you need to change the parameters based on your use case, your data and also your hardware.

  3. maaaax commented on Jul 24, 2025

    @maaaax

    Same here. With an older unsloth/transformers docker image the same py script works.

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

    Discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions