Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/test_grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,25 @@ def test_liger_kernel_with_peft_prompt_learning_raises(self):
peft_config=PromptTuningConfig(task_type=TaskType.CAUSAL_LM, num_virtual_tokens=8),
)

@require_liger_kernel
def test_init_fails_with_moe_aux_loss_and_liger(self):
dataset = load_dataset("trl-internal-testing/zen", "standard_prompt_only", split="train")

# The MoE auxiliary loss is on by default; it is incompatible with the Liger fused loss.
training_args = GRPOConfig(
output_dir=self.tmp_dir,
use_liger_kernel=True,
report_to="none",
)

with pytest.raises(ValueError, match="does not support the Mixture-of-Experts load-balancing auxiliary loss"):
GRPOTrainer(
model="trl-internal-testing/tiny-Qwen3MoeForCausalLM",
reward_funcs="trl-internal-testing/tiny-Qwen2ForSequenceClassification-2.5",
args=training_args,
train_dataset=dataset,
)

@require_peft
def test_train_peft_model(self):
model = AutoModelForCausalLM.from_pretrained("trl-internal-testing/tiny-Qwen2ForCausalLM-2.5", dtype="float32")
Expand Down
6 changes: 6 additions & 0 deletions trl/trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ def get_reward(environments, _env_type=env_type, **kwargs):
is_moe = getattr(text_config, "output_router_logits", None) is not None
self.aux_loss_enabled = is_moe and args.router_aux_loss_coef != 0.0
self.router_aux_loss_coef = args.router_aux_loss_coef
if self.aux_loss_enabled and self.use_liger_kernel:
raise ValueError(
"Liger GRPO loss does not support the Mixture-of-Experts load-balancing auxiliary loss, because it "
"fuses the loss without materializing the router logits. Either set `router_aux_loss_coef` to `0.0` "
"to disable the auxiliary loss, or set `use_liger_kernel` to False."
)
self.scale_rewards = args.scale_rewards
self.importance_sampling_level = args.importance_sampling_level
self.off_policy_mask_threshold = args.off_policy_mask_threshold
Expand Down