Alternatives to torch.mode?

I would really like know if there are any possible workarounds to torch.mode, other than combining torch.unique(input, return_counts=False) and torch.argmax(). Obviously, simply iterating over the input tensor values and counting the number of times each value appear takes too much time when the tensor gets longer…

A slight background into why I want to do this, is because I want to convert a pretrained PyTorch model into a CoreML format. The details of CoreML is irrelevant here, but the converter doesn’t seem to support either torch.mode or torch.unique, so I was wondering how PyTorch actually execute the torch.mode function and if there are any other functions that can similarly do the job.