Can I customize a new data type? For example, I want to use 4 bits to store integers in pytorch, but there is no int4 in torch. How can I write an int4 data type?

I want to do some distributed training, in which some integers need to be transmitted, and only a few bits are needed to represent them (such as labels, quantized integers in communication compression). However, there are only 8-bit integers in torch. I can use bytes to encode integers to reduce communication overhead, but this is too time-consuming. Therefore, if I can set the data type of the specified bit myself, I can solve my problem. How do I customize data types?