PythiloLesson 4 of 8 · progress kept in this browser

Practice in Lab: Update a detached Group DRO adversary from group means →

Update a detached Group DRO adversary from group means

Average risk can hide a poorly served subgroup when that group is rare. Group DRO maintains an adversary over declared groups, increasing mass on groups with larger observed mean loss. The adversary state is an optimization state, not a differentiable shortcut through every previous batch. Normalizing by each group count prevents duplicated rows from becoming an unintended group weight. Observing only a subset of groups requires an explicit estimator; this exercise instead declares complete group coverage per batch.

Your task

Return (robust_loss, next_log_weights). All G declared groups must occur in this batch. Average losses within each group, update adversary log weights by eta times DETACHED group means, normalize in log space, then weight differentiable group means by detached updated probabilities. Do not backpropagate into old adversary state. Reject empty/missing/out-of-range groups, nonfinite losses/state and nonpositive eta. This deliberately balanced-batch contract avoids silently inventing loss for unobserved groups.

This lesson uses torch, which Python in this browser does not include. Read it here, and run and check it in the Pythilo app on iPhone or iPad.