If you cannot provide proper cooling, you could try to artificially slow down the code e.g. by adding sleeps to the code or reducing the number of used threads (via torch.set_num_threads and torch.set_num_interop_threads).