File size: 926 Bytes
5032722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 29 19:27:33 2025

"""
import optax
import numpy as np

def build_optimizer(args):
    config = args.optimizer_config
    
    learning_rate = optax.warmup_cosine_decay_schedule(init_value= config['init_value'], 
                                                       peak_value= config['peak_value'], 
                                                       end_value = config['end_value'],
                                                       warmup_steps= config['warmup_steps'], 
                                                       decay_steps= args.num_epochs)
    
    base_optimizer = optax.adamw(learning_rate = learning_rate,
                                 weight_decay = config['weight_decay'])
    
    tx = optax.MultiSteps(opt = base_optimizer,
                          every_k_schedule = config['every_k_schedule'])
    
    return tx