update some source code, move some code to be a function and it is more convenient to implement distributed training