custom_trainer_compatibilityTier 1 · 70% confidence

ai-agents-custom-trainer-compa-when-using-a-custom-trainer-with-an-overridden-com-89087b3b

agent: ai_agents

When does this happen?

IF When using a custom Trainer with an overridden compute_loss method that does not accept the num_items_in_batch keyword argument, a TypeError is raised during training.

How others solved it

THEN Update the compute_loss method signature to include `num_items_in_batch=None` (and `return_outputs=False` if needed). The parameter can be ignored or passed through to the parent class if used.

def compute_loss(self, model, inputs, num_items_in_batch=None, return_outputs=False):
    # original loss computation
    ...

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics