def __init__(self,
                 d_model=256,
                 n_levels=4,
                 n_heads=8,
                 n_points=4,
                 ratio=1.0):
        """Multi-Scale Deformable Attention Module.
        
        Args:
            d_model(int, optional): The hidden dimension. Default: 256
            n_levels(int, optional): The number of feature levels. Default: 4
            n_heads(int, optional): The number of attention heads. Default: 8
            n_points(int, optional): The number of sampling points per attention head per feature level. Default: 4
            ratio (float, optional): The ratio of channels for Linear. Default: 1.0
        """
        super().__init__()
        if d_model % n_heads != 0:
            raise ValueError('d_model must be divisible by n_heads, '
                             'but got {} and {}'.format(d_model, n_heads))
        _d_per_head = d_model // n_heads
        # you'd better set _d_per_head to a power of 2
        # which is more efficient in our CUDA implementation
        if not self._is_power_of_2(_d_per_head):
            warnings.warn("You'd better set d_model in MSDeformAttn to make "
                          'the dimension of each attention head a power of 2 '
                          'which is more efficient in our CUDA implementation.')

        self.im2col_step = 64
        self.d_model = d_model
        self.n_levels = n_levels
        self.n_heads = n_heads
        self.n_points = n_points
        self.ratio = ratio

        self.sampling_offsets = nn.Linear(d_model,
                                          n_heads * n_levels * n_points * 2)
        self.attention_weights = nn.Linear(d_model,
                                           n_heads * n_levels * n_points)
        self.value_proj = nn.Linear(d_model, int(d_model * ratio))
        self.output_proj = nn.Linear(int(d_model * ratio), d_model)

        self._reset_parameters()
Multi-Scale Deformable Attention Module.
        
        Args:
            d_model(int, optional): The hidden dimension. Default: 256
            n_levels(int, optional): The number of feature levels. Default: 4
            n_heads(int, optional): The number of attention heads. Default: 8
            n_points(int, optional): The number of sampling points per attention head per feature level. Default: 4
            ratio (float, optional): The ratio of channels for Linear. Default: 1.0
        
paddleseg/models/layers/ms_deformable_attention.py