0

This is my evaluate function for federated learning:

def evaluate(num_rounds=10):
    state = trainer.initialize()
    for round in range(num_rounds):
        t1 = time.time()
        state, metrics = trainer.next(state, client_data)
        t2 = time.time()
        print('Round {}: metrics {}, round time {}'.format(
            round+1,metrics, t2 - t1))

I need to save the state after 10 rounds and need to load the state and resume from the 11th round. How to do it? Help me...

1 Answer 1

0

The next() function takes the state as an argument and returns the new one every time it is called. Therefore, the model is updated using the last state at each round.

If your evaluate function performs just 10 evaluation rounds, you can return the variable state at the end: it will contain the state of the 10th round.

Otherwise, if you are interested in the 10th-round state but allow for more rounds, you should save the state in a separate variable and return it at the end.

for round in range(num_rounds):
  t1 = time.time()
  state, metrics = trainer.next(state, client_data)
  t2 = time.time()

  print('Round {}: metrics {}, round time {}'.format(
            round+1,metrics, t2 - t1))
  
  if round == 9:
    state_10 = state

return state_10

The next time you perform the evaluation, you can set that state as the initial one (instead of calling trainer.initialize()) to resume the training process

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.