def merge_nested_dicts(
    original: Dict[str, Any],
    update: Dict[str, Any]) -> Tuple[Sequence[str], Sequence[str]]:
  """Merges `update` nested dict into the `original` dict.

  Args:
    original: target nested dictionary to be updated in-place.
    update: nested dictionary which values are copied into the `original` dict.

  Returns:
    Returns a pair of lists. The first list contains "unexpected" keys,
    which existed in the `update` dictionary, but not in the `original`.
    The second list contains "missing" keys, which existed in the
    `original` one, but not in the `update`.
  """
  unexpected, missing = [], []
  original_keys = frozenset(flatten_nested_dict(original).keys())
  update_keys = frozenset(flatten_nested_dict(update).keys())
  unexpected = frozenset(_merge_nested_dicts_rec(original, update))
  missing = original_keys.difference(update_keys)
  assert unexpected == update_keys.difference(original_keys)
  return list(unexpected), list(missing)
Merges `update` nested dict into the `original` dict.

  Args:
    original: target nested dictionary to be updated in-place.
    update: nested dictionary which values are copied into the `original` dict.

  Returns:
    Returns a pair of lists. The first list contains "unexpected" keys,
    which existed in the `update` dictionary, but not in the `original`.
    The second list contains "missing" keys, which existed in the
    `original` one, but not in the `update`.
  
language/mentionmemory/utils/checkpoint_utils.py