Used `mapPartitions` instead of `map` to aggregate the loss and gradient to global lossSum and gradientSum
for one RDD partition to avoid creating unnecessary objects in order to increase the performance.