How can l clear the old cache in GPU, when training different groups of data continuously?

If you delete all references to the model and other tensors, the memory can be freed or reused. Here is a small example.
Make sure you are not storing the model output, loss etc. without detaching it, as this would keep the computation graph with all intermediate tensors alive.