code: def build_trainer(
      cfg: DictConfig,
      data_module: OpenImagesDataModule,
      module: ImageModule,
  ) -> pl.Trainer:
      """Construct the pl trainer."""
      log_dir = Path.cwd().absolute() / "wandb_logs"
      log_dir.mkdir(exist_ok=True, parents=True)
      if cfg.logger.group == "dev":
          name = "/".join([Path.cwd().parent.name, Path.cwd().name])
      else:
          name = Path.cwd().name
  
      if HAS_WANDB:
          # create an id for this run based on hash of config string
          sha = hashlib.sha256()
          sha.update(str(Path.cwd()).encode())
          wandb_id = sha.hexdigest()
  
          logger = WandbLogger(
              name=name,
              save_dir=str(log_dir),
              project="illm",
              id=wandb_id,
              config=OmegaConf.to_container(cfg),
              **cfg.logger,
          )
  
          image_logger = build_wandb_image_logger(cfg, data_module)
      else:
          logger = None
          image_logger = pl.Callback()
  
      # sometimes we have unused parameters
      strategy: Union[DDPStrategy, str]
      if cfg.training_mode == "train":
          strategy = DDPStrategy(find_unused_parameters=True)
      else:
          strategy = "auto"
  
      # adjust number of steps based on how many optimizers we have
      num_opts = len(module.configure_optimizers()[0])
      trainer_cfg = {**cfg.trainer}
      orig_steps = trainer_cfg["max_steps"]
      new_steps = math.ceil(trainer_cfg["max_steps"] * num_opts)
      LOGGER.info(
          f"found {num_opts} optimizers, changing max steps "
          f"from {orig_steps} to {new_steps}"
      )
      trainer_cfg["max_steps"] = new_steps
  
      trainer = pl.Trainer(
          **trainer_cfg,
          logger=logger,
          strategy=strategy,
          callbacks=[
              LearningRateMonitor(logging_interval="step"),
              ModelCheckpoint(**cfg.checkpoint.callback),
              image_logger,
          ],
      )
  
      return trainer
  
imports: import hashlib
  import logging
  import math
  import pickle
  from pathlib import Path
  from typing import List, Optional, Tuple, Union
  from warnings import warn
  import hydra
  import lightning.pytorch
  import torch
  import torch.nn
  import yaml
  from gan_compression_module import GANCompressionModule
  from image_module import ImageModule
  from lightning.pytorch.callbacks import LearningRateMonitor, ModelCheckpoint
  from lightning.pytorch.strategies import DDPStrategy
  from omegaconf import DictConfig, OmegaConf
  from open_images_datamodule import OpenImagesDataModule
  from target_compression_module import TargetRateCompressionModule
  from torch import Tensor
  from torch.utils.data import DataLoader
  from torchvision.utils import make_grid
  from neuralcompression.loss_fn import TargetRateConfig
  from neuralcompression.models import HyperpriorAutoencoderBase
label_desc: Use image node_id 7 for calling a global function with example usage: build_trainer(cfg, data_module, module) and returns: trainer