Properly define a non differentiable layer


I would like to create a layer containing non differentiable operations (such as a K-means for example) and I would like to combine it with deep neural network (pre-)trained using SGD.
How to properly and clearly create using PyTorch, my layer and define it as non differentiable in order that the gradient is not be computed.

Thank you