The H-Net paper multiplies the base learning rate by a per-stage scalar, because outer stages see far more positions per batch and run at smaller widths:
Implement the formula and turn it into optimizer parameter groups.
stage_multipliers(ratios, widths, n_gpt=4.6)
ratios holds the downsampling targets (length ) and widths the (length ). Raise ValueError if the lengths do not fit.S + 1 floats .build_param_groups(stages, multipliers, base_lr, weight_decay)
stages is a list of torch.nn.Module, one per stage, each holding only that stage's parameters. Raise ValueError if len(stages) != len(multipliers) or if one parameter appears in two stages.requires_grad=False.bias or any component is norm; all others get weight_decay.torch.optim.AdamW, each with keys params (a list), lr (base_lr * multipliers[s]) and weight_decay. Order: stage 0 first; within a stage the decayed group then the undecayed one. Leave out empty groups.id(param), not by name: stage modules have their own naming.normalizer.weight is not mistaken for a norm.