code: def update_loss(self, iteration: int, loss_map: Dict[str, float]):
      loss_spike_result = []
      for task, loss in loss_map.items():
          if task in self._last_loss:
              if loss > self._last_loss[task] * 3:
                  # loss spike!
                  loss_spike_result.append(
                      {
                          "prev": self._last_loss[task],
                          "curr": loss,
                          "task": task,
                      }
                  )
          self._last_loss[task] = float(loss)
      if len(loss_spike_result) > 0:
          self._write_log(
              iteration, self._last_data[-1], loss_spike_result
          )
  
imports: import json
  import time
  from typing import Any, Dict, List, Union
  import torch
  import bmtrain
  import os
  from cpm_live.arguments import get_args
  from cpm_live.models import CPMBee, CPMBeeConfig
  from cpm_live.tokenizers import CPMBeeTokenizer
  from cpm_live.utils import allgather_objects, LogManager
  from cpm_live.training_tasks.bee import MixedDataset
label_desc: Use image node_id 3 for calling the LossSpikeDetector obj's underlying member method code with example usage: obj.update_loss(iteration, loss_map) without return types