def _apply_gradients(self, gradients):
    'Applies the optimizer to the model parameters.'
    interpreter = tf.lite.Interpreter(model_content=self.optimizer_model)
    interpreter.allocate_tensors()
    num_variables = len(self.variables)
    variable_ins = interpreter.get_input_details()[:num_variables]
    gradient_ins = interpreter.get_input_details()[num_variables:(num_variables * 2)]
    state_ins = interpreter.get_input_details()[(num_variables * 2):]
    variable_outs = interpreter.get_output_details()[:num_variables]
    state_outs = interpreter.get_output_details()[num_variables:]
    for (variable, gradient, variable_in, gradient_in) in zip(self.variables, gradients, variable_ins, gradient_ins):
        interpreter.set_tensor(variable_in['index'], variable)
        interpreter.set_tensor(gradient_in['index'], gradient)
    for (optim_state_elem, state_in) in zip(self.optim_state, state_ins):
        interpreter.set_tensor(state_in['index'], optim_state_elem)
    interpreter.invoke()
    self.variables = [interpreter.get_tensor(variable_out['index']) for variable_out in variable_outs]
    self.optim_state = [interpreter.get_tensor(state_out['index']) for state_out in state_outs]
Applies the optimizer to the model parameters.
def _apply_gradients(self, gradients):
    
    interpreter = tf.lite.Interpreter(model_content=self.optimizer_model)
    interpreter.allocate_tensors()
    num_variables = len(self.variables)
    variable_ins = interpreter.get_input_details()[:num_variables]
    gradient_ins = interpreter.get_input_details()[num_variables:(num_variables * 2)]
    state_ins = interpreter.get_input_details()[(num_variables * 2):]
    variable_outs = interpreter.get_output_details()[:num_variables]
    state_outs = interpreter.get_output_details()[num_variables:]
    for (variable, gradient, variable_in, gradient_in) in zip(self.variables, gradients, variable_ins, gradient_ins):
        interpreter.set_tensor(variable_in['index'], variable)
        interpreter.set_tensor(gradient_in['index'], gradient)
    for (optim_state_elem, state_in) in zip(self.optim_state, state_ins):
        interpreter.set_tensor(state_in['index'], optim_state_elem)
    interpreter.invoke()
    self.variables = [interpreter.get_tensor(variable_out['index']) for variable_out in variable_outs]
    self.optim_state = [interpreter.get_tensor(state_out['index']) for state_out in state_outs]