def interpolate_position_embeddings(model, layer, param):
    """
    Fine-tuning at a different resolution than that which a model was
    pretrained at requires interpolating the learned position embeddings.
    """
    if (
        hasattr(model.trunk, "interpolate_position_embedding")
        and layer.shape != param.shape
    ):
        interp = model.trunk.interpolate_position_embedding
        if callable(interp):
            try:
                param = interp(param)
            except BaseException:
                raise RuntimeError("Unable to interpolate position embeddings")
    return param