class_docstr: Class for generating images from a Stable Diffusion checkpoint trained using Determined
  AI. Initialize with no arguments in order to run plain Stable Diffusion without any trained
  textual inversion embeddings. Can optionally be run on a Determined cluster through the
  .generate_on_cluster() method for large-scale generation. Only intended for use with a GPU.
docstr: Load concepts from a checkpoint directory which is expected contain a file with the name
  matching the provided `learned_embeddings_filename` or, if omitted, the __init__
  `learned_embeddings_filename`. The file is expected to contain a dictionary
  whose keys are the `concept_str`s and whose values are dictionaries containing an
  `initializer_token` key and a `learned_embeddings` whose corresponding values are the
  initializer string and learned embedding tensors, respectively.
docstr_tok: ["Load","concepts","from","a","checkpoint","directory","which","is","expected","contain","a","file","with","the","name","matching","the","provided","`","learned_embeddings_filename","`","or",",","if","omitted",",","the","__init__","`","learned_embeddings_filename","`",".","The","file","is","expected","to","contain","a","dictionary","whose","keys","are","the","`","concept_str","`","s","and","whose","values","are","dictionaries","containing","an","`","initializer_token","`","key","and","a","`","learned_embeddings","`","whose","corresponding","values","are","the","initializer","string","and","learned","embedding","tensors",",","respectively","."]
code: def load_from_checkpoint_dir(
      self,
      checkpoint_dir: Union[str, pathlib.Path],
      learned_embeddings_filename: Optional[str] = None,
  ) -> None:
      """Load concepts from a checkpoint directory which is expected contain a file with the name
      matching the provided `learned_embeddings_filename` or, if omitted, the __init__
      `learned_embeddings_filename`. The file is expected to contain a dictionary
      whose keys are the `concept_str`s and whose values are dictionaries containing an
      `initializer_token` key and a `learned_embeddings` whose corresponding values are the
      initializer string and learned embedding tensors, respectively.
      """
      if not checkpoint_dir:
          return
  
      learned_embeddings_filename = (
          learned_embeddings_filename
          or self.learned_embeddings_filename
      )
      if isinstance(checkpoint_dir, str):
          checkpoint_dir = pathlib.Path(checkpoint_dir)
      learned_embeddings_dict = torch.load(
          checkpoint_dir.joinpath(learned_embeddings_filename)
      )
  
      # Update embedding matrix and attrs.
      for (
          concept_str,
          embedding_dict,
      ) in learned_embeddings_dict.items():
          if concept_str in self.learned_embeddings_dict:
              raise ValueError(
                  f"Checkpoint concept conflict: {concept_str} already exists."
              )
          initializer_strs = embedding_dict["initializer_strs"]
          learned_embeddings = embedding_dict["learned_embeddings"]
          (
              _,
              dummy_placeholder_ids,
              dummy_placeholder_strs,
          ) = utils.add_new_tokens_to_tokenizer(
              concept_str=concept_str,
              initializer_strs=initializer_strs,
              tokenizer=self.hf_pipeline.tokenizer,
          )
  
          self.hf_pipeline.text_encoder.resize_token_embeddings(
              len(self.hf_pipeline.tokenizer)
          )
          token_embeddings = (
              self.hf_pipeline.text_encoder.get_input_embeddings().weight.data
          )
          # Sanity check on length.
          assert len(dummy_placeholder_ids) == len(
              learned_embeddings
          ), "dummy_placeholder_ids and learned_embeddings must have the same length"
          for d_id, tensor in zip(
              dummy_placeholder_ids, learned_embeddings
          ):
              token_embeddings[d_id] = tensor
          self.learned_embeddings_dict[concept_str] = embedding_dict
          self.all_added_concepts.append(concept_str)
          self.concept_to_dummy_tokens_map[
              concept_str
          ] = dummy_placeholder_strs
      self.all_checkpoint_dirs.append(checkpoint_dir)
  
imports: import json
  import logging
  import os
  import pathlib
  from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple, Union
  import torch
  from detsd import defaults, utils
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipeline, StableDiffusionPipelineOutput
  from torch.utils.tensorboard import SummaryWriter
  from torchvision.transforms.functional import pil_to_tensor
  import determined
  from determined.experimental import client
label_desc: Use image node_id 3 for calling the DetSDTextualInversionPipeline obj's underlying member method code with example usage: obj.load_from_checkpoint_dir(checkpoint_dir, learned_embeddings_filename) without return types