docstr: Test to ensure that we always keep top_k checkpoints, even after resuming.
code: def test_exp_manager_ema_weights_topk_resume(self, tmpdir):
      """Test to ensure that we always keep top_k checkpoints, even after resuming."""
      tmp_path = tmpdir / "exp_manager_test"
      model = ExampleModel()
      save_top_k = 3
  
      trainer = Trainer(
          max_epochs=10,
          enable_checkpointing=False,
          logger=False,
          devices=1,
      )
      exp_manager(
          trainer,
          {
              "ema": {"enable": True},
              "explicit_log_dir": str(tmp_path),
              "checkpoint_callback_params": {"save_top_k": save_top_k},
          },
      )
      trainer.fit(model)
  
      # we save 3 checkpoints for the model, 3 accompanied EMA weights, the last checkpoint and nemo model.
      assert (
          len(os.listdir(tmp_path / "checkpoints/"))
          == (save_top_k + 1) * 2 + 1
      )
  
      # reduce the top_k number when resuming, we should see only 2 top_k checkpoints now (one is deleted).
      save_top_k = 2
  
      trainer = Trainer(
          max_epochs=10,
          enable_checkpointing=False,
          logger=False,
          devices=1,
      )
      exp_manager(
          trainer,
          {
              "ema": {"enable": True},
              "explicit_log_dir": str(tmp_path),
              "resume_if_exists": True,
              "checkpoint_callback_params": {"save_top_k": save_top_k},
          },
      )
      trainer.fit(model)
  
      # we save 2 checkpoints for the model, 2 accompanied EMA weights, the last checkpoint and nemo model.
      assert (
          len(os.listdir(tmp_path / "checkpoints/"))
          == (save_top_k + 1) * 2 + 1
      )
  
imports: import os.path
  from typing import Any, Dict, Union
  import pytest
  import pytorch_lightning
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Callback, Trainer
  from pytorch_lightning.utilities.exceptions import MisconfigurationException
  from pytorch_lightning.utilities.types import STEP_OUTPUT
  from nemo.collections.common.callbacks import EMA
  from nemo.collections.common.callbacks.ema import EMAOptimizer
  from nemo.core import ModelPT
  from nemo.utils.exp_manager import exp_manager
label_desc: Use image node_id 5 for calling the TestEMAConfig obj's underlying member method code with example usage: obj.test_exp_manager_ema_weights_topk_resume(tmpdir) without return types