Skip to content

Conversation

@rolandtannous
Copy link
Collaborator

@rolandtannous rolandtannous commented Jul 12, 2025

Problem

After resolving the initial state2 in unsloth PR 2943 attribute errors in GRPO training, users encountered a secondary validation error when initializing GRPOConfig:

ValueError: --dataloader_prefetch_factor can only be set when data is loaded in a different process, i.e. when --dataloader_num_workers > 1

This error occurs because Unsloth's RL patching system sets default values for dataloader optimization, including dataloader_prefetch_factor = 2 and dataloader_num_workers = 0. However, the Transformers library validation logic

However, the Transformers library transformers validation logic

if self.dataloader_num_workers == 0 and self.dataloader_prefetch_factor is not None:
            raise ValueError(
                "--dataloader_prefetch_factor can only be set when data is loaded in a different process, i.e."
                " when --dataloader_num_workers > 1."
            )

requires dataloader_num_workers > 1 when dataloader_prefetch_factor is specified, as prefetching only makes sense when data loading happens in separate worker processes.

The conflict arises from Unsloth's optimization defaults being incompatible with Transformers' validation requirements, preventing GRPO training from starting.

Solution

Modified the dataloader configuration logic in rl.py and set dataloader_num_workers default to 0, to ensure compatibility with Transformers validation.

Tests

We tested end-to-end the following GRPO notebooks to ensure both training and inference work correctly.
After applying the fixes in both unsloth PR 2943 and this PR, all notebooks now complete successfully without errors

Notebook Training Inference
Advanced Llama-3.1-(3B)-GRPO-Lora
Advanced_Llama3_2_(3B)_GRPO_LoRA
Phi-14B-GRPO
MMistral_v0.3_(7B)-GRPO
qwen3_4b-GRPO

@rolandtannous rolandtannous changed the title fix dataloader_num_workers value error in GRPOTrainer GRPO fix dataloader_num_workers value error in GRPOTrainer Jul 12, 2025
@danielhanchen danielhanchen merged commit c972010 into unslothai:main Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants