docstr: brings the cached kv vectors back to a sober baseline
docstr_tok: ["brings","the","cached","kv","vectors","back","to","a","sober","baseline"]
code: def cold_shower(self, force_clean=False):
      r"""
      brings the cached kv vectors back to a sober baseline
      """
      with torch.no_grad():
          if len(self.past_key_values) == 0:
              logger.warn(
                  "the cold_shower() function can only be called on models being run with Dgenerate"
              )
              return self.past_key_values
          if (
              self.past_key_values is None
              or self.dirty_count <= 0
              and not force_clean
          ):
              return self.past_key_values
          if self.dirty_count >= self.sober_interval or force_clean:
              max_clean = min(
                  self.past_key_values[0][0].shape[2] - 6,
                  self.dirty_count,
              )
              new_past_key_values = self._get_truncated_cache(
                  self.past_key_values, max_clean
              )
  
              regen_tokens = self.cached_tokens[
                  :, -(max_clean + 1) : -1
              ]
              old_dose_multiplier = self.get_dose_multiplier()
              self.set_dose_multiplier(0)
              outputs = self.model(
                  input_ids=regen_tokens.to(self.model.device),
                  past_key_values=new_past_key_values,
                  use_cache=True,
              )
              self.past_key_values = DynamicCache()
              for i, (k, v) in enumerate(outputs.past_key_values):
                  self.past_key_values.update(k, v, i)
  
              # TODO: Figure out why this doesn't work the first time when no noise is injected.
              """
                  if torch.max(self.past_key_values[20][0] - outputs.past_key_values[20][0]) > 0:
                      self.past_key_values = outputs.past_key_values
                      self.cold_shower()
                  """
  
              self.set_dose_multiplier(old_dose_multiplier)
              self.dirty_count -= max_clean
              del new_past_key_values
              self.clear_cuda_caches()
      return self.past_key_values
  
imports: import torch
  import json, os, msgpack
  from transformers.utils import logging
  import types
  import inspect
  import copy
  from typing import Optional, List, Callable
  from drugs.inject_mixin import InjectDrugsMixin, MODEL_NAME_MAPPING
  from transformers import GenerationMixin
  from transformers.cache_utils import DynamicCache
  from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList
  from transformers import AutoTokenizer, TextStreamer, GenerationConfig
  import numpy
  import torch
  import torch.nn.functional
  import hashlib
label_desc: Use image node_id 39 for calling the DRUGS obj's underlying member method code with example usage: obj.cold_shower(force_clean) and returns: self, self, self