def resize_position_embeddings(max_position_embeddings, old_vocab_size,
                                   _k='backbone.bottom_up.backbone.embeddings.position_embeddings.weight',
                                   initializer_range=0.02, reuse_position_embedding=True):
        '''
        Reference: unilm
        ALso see discussions:
        https://github.com/pytorch/fairseq/issues/1685
        https://github.com/google-research/bert/issues/27
        '''

        new_position_embedding = state_dict[_k].data.new_tensor(torch.ones(
            size=(max_position_embeddings, state_dict[_k].shape[1])), dtype=torch.float)
        new_position_embedding = nn.Parameter(data=new_position_embedding, requires_grad=True)
        new_position_embedding.data.normal_(mean=0.0, std=initializer_range)
        if max_position_embeddings > old_vocab_size:
            logger.info("Resize > position embeddings !")
            max_range = max_position_embeddings if reuse_position_embedding else old_vocab_size
            shift = 0
            while shift < max_range:
                delta = min(old_vocab_size, max_range - shift)
                new_position_embedding.data[shift: shift + delta, :] = state_dict[_k][:delta, :]
                logger.info("  CP [%d ~ %d] into [%d ~ %d]  " % (0, delta, shift, shift + delta))
                shift += delta
            state_dict[_k] = new_position_embedding.data
            del new_position_embedding
        elif max_position_embeddings < old_vocab_size:
            logger.info("Resize < position embeddings !")
            new_position_embedding.data.copy_(state_dict[_k][:max_position_embeddings, :])
            state_dict[_k] = new_position_embedding.data
            del new_position_embedding

        Reference: unilm
        ALso see discussions:
        https://github.com/pytorch/fairseq/issues/1685
        https://github.com/google-research/bert/issues/27
        
layoutlmv3/examples/object_detection/ditod/mycheckpointer.py