def pad_vocab_to_eight(vocab):
  """Pads vocabulary so that it is divisible by 8.

  Args:
    vocab (dict): vocabulary in the form token->id

  Returns:
    dict: vocab with new tokens added if necessary, such that the total
    vocab size is divisible by 8.
  """
  v_len = len(vocab)
  if v_len % 8 == 0:
    return vocab
  for id_add in range(0, 8 - v_len % 8):
    vocab['<$'+str(id_add)+'$>'] = v_len + id_add
  return vocab