Trainable Weight Averaging: A General Approach for Subspace Training