code: def local_1d_halo_exchange(k, v, num_w_blocks, w_dim, mask_right):
    
    if num_w_blocks is not None:
      if mask_right:
        k = mtf.left_halo_exchange(k, num_w_blocks, w_dim, w_dim.size)
        v = mtf.left_halo_exchange(v, num_w_blocks, w_dim, w_dim.size)
      else:
        k = mtf.halo_exchange(k, num_w_blocks, w_dim, w_dim.size)
        v = mtf.halo_exchange(v, num_w_blocks, w_dim, w_dim.size)
    else:
      if mask_right:
        k = mtf.pad(k, [w_dim, None], w_dim.name)
        v = mtf.pad(v, [w_dim, None], w_dim.name)
      else:
        k = mtf.pad(k, [w_dim, w_dim], w_dim.name)
        v = mtf.pad(v, [w_dim, w_dim], w_dim.name)
    return k, v
docs: Halo exchange for keys and values for Local 1D attention.