instead of apex I have used torch.cuda.amp for mixed precision implementation. but same error information has been shown. because the variablel label is on CPU. In order to accumulate
the label value from 4 different processes I have used the torch API torch.distributed.all_gather. But the API must run on cuda. And then I transfered the label value from CPU to GPU. After getting all of label value, I transfered the label value from GPU to CPU for calculating the metric value(f1 score) by using  sklearn.metrics.f1_score. But when the code runs to this row labels_c = labels.cpu(). the error information has been shown again.
I dont know what caused this.