To use the Adan optimizer within the timm (PyTorch Image Models) framework, you must perform two main steps: adding the required hyper-parameters to your training script and modifying the optimizer factory to recognize and instantiate Adan.
Step 1: Add Adan Hyper-parameters
Add the following arguments to your train.py argument parser to support Adan-specific configurations:
--max-grad-norm: L2 norm threshold for gradient clipping (default: 0.0, no clipping).--weight-decay: Weight decay value, similar to AdamW (default: 0.02).--opt-eps: Optimizer epsilon to prevent division by zero (default: None, uses 1e-8 in Adan).--opt-betas: Optimizer betas (default: None, uses [0.98, 0.92, 0.99] in Adan).--no-prox: If set, performs weight decay like AdamW. If unset (default), uses the proximal update rule described in the Adan paper. Note: The paper uses no-prox=False.--bias-decay: If set, performs weight decay on bias terms, batch normalization (BN), and other 1D parameters. By default, these are filtered out in timm.
parser.add_argument('--max-grad-norm', type=float, default=0.0, help='if the l2 norm is large than this hyper-parameter, then we clip the gradient (default: 0.0, no gradient clip)')
parser.add_argument('--weight-decay', type=float, default=0.02, help='weight decay, similar one used in AdamW (default: 0.02)')
parser.add_argument('--opt-eps', default=None, type=float, metavar='EPSILON', help='optimizer epsilon to avoid the bad case where second-order moment is zero (default: None, use opt default 1e-8 in adan)')
parser.add_argument('--opt-betas', default=None, type=float, nargs='+', metavar='BETA', help='optimizer betas in Adan (default: None, use opt default [0.98, 0.92, 0.99] in Adan)')
parser.add_argument('--no-prox', action='store_true', default=False, help='whether perform weight decay like AdamW (default=False)')
parser.add_argument('--bias-decay', action='store_true', default=False, help='Perform the weight decay on bias term (default=False)')