code: def _position_bucket(
      self, relative_position, num_buckets=32, max_distance=128
  ):
      relative_buckets = 0
      num_buckets //= 2
      relative_buckets = (relative_position > 0).to(
          torch.int32
      ) * num_buckets
      relative_position = torch.abs(relative_position)
  
      max_exact = num_buckets // 2
      is_small = relative_position < max_exact
      relative_postion_if_large = max_exact + (
          torch.log(relative_position.float() / max_exact)
          / math.log(max_distance / max_exact)
          * (num_buckets - max_exact)
      ).to(torch.int32)
      relative_postion_if_large = torch.min(
          relative_postion_if_large,
          torch.full_like(relative_postion_if_large, num_buckets - 1),
      )
      relative_buckets += torch.where(
          is_small,
          relative_position.to(torch.int32),
          relative_postion_if_large,
      )
      return relative_buckets
  
file_path: DeepKE/example/llm/CPM-Bee/src/cpm_live/native_layers/position_embedding.py
imports: import math
  from typing import Union
  import torch
  import torch.nn.functional
label_desc: Use image node_id 3 for calling the BucketPositionBias obj's underlying member method code with example usage: obj._position_bucket(relative_position, num_buckets, max_distance) and returns: relative_buckets