If I understand your code correctly, the duration print statement is used after the training is done.
If that’s the case, the code seems to work fine.
PS: you can add code snippets by wrapping them in three backticks ```, which would make debugging a lot easier.