code: def pretrain(
      model: LightningModule,
      method: str,
      train_dir: Path,
      val_dir: Path,
      log_dir: Path,
      batch_size_per_device: int,
      epochs: int,
      num_workers: int,
      accelerator: str,
      devices: int,
      precision: str,
      ckpt_path: Union[Path, None],
  ) -> None:
      print_rank_zero(f"Running pretraining for {method}...")
  
      # Setup training data.
      train_transform = METHODS[method]["transform"]
      train_dataset = LightlyDataset(
          input_dir=str(train_dir), transform=train_transform
      )
      train_dataloader = DataLoader(
          train_dataset,
          batch_size=batch_size_per_device,
          shuffle=True,
          num_workers=num_workers,
          drop_last=True,
          persistent_workers=False,
      )
  
      # Setup validation data.
      val_transform = T.Compose(
          [
              T.Resize(256),
              T.CenterCrop(224),
              T.ToTensor(),
              T.Normalize(
                  mean=IMAGENET_NORMALIZE["mean"],
                  std=IMAGENET_NORMALIZE["std"],
              ),
          ]
      )
      val_dataset = LightlyDataset(
          input_dir=str(val_dir), transform=val_transform
      )
      val_dataloader = DataLoader(
          val_dataset,
          batch_size=batch_size_per_device,
          shuffle=False,
          num_workers=num_workers,
          persistent_workers=False,
      )
  
      # Train model.
      metric_callback = MetricCallback()
      trainer = Trainer(
          max_epochs=epochs,
          accelerator=accelerator,
          devices=devices,
          callbacks=[
              LearningRateMonitor(),
              # Stop if training loss diverges.
              EarlyStopping(
                  monitor="train_loss",
                  patience=int(1e12),
                  check_finite=True,
              ),
              DeviceStatsMonitor(),
              metric_callback,
          ],
          logger=TensorBoardLogger(
              save_dir=str(log_dir), name="pretrain"
          ),
          precision=precision,
          strategy="ddp_find_unused_parameters_true",
          sync_batchnorm=accelerator
          != "cpu",  # Sync batchnorm is not supported on CPU.
          num_sanity_val_steps=0,
      )
  
      trainer.fit(
          model=model,
          train_dataloaders=train_dataloader,
          val_dataloaders=val_dataloader,
          ckpt_path=ckpt_path,
      )
      for metric in ["val_online_cls_top1", "val_online_cls_top5"]:
          print_rank_zero(
              f"max {metric}: {max(metric_callback.val_metrics[metric])}"
          )
  
imports: from argparse import ArgumentParser
  from datetime import datetime
  from pathlib import Path
  from typing import Sequence, Union
  import barlowtwins
  import byol
  import dcl
  import dclw
  import dino
  import finetune_eval
  import knn_eval
  import linear_eval
  import mocov2
  import simclr
  import swav
  import tico
  import torch
  import vicreg
  from pytorch_lightning import LightningModule, Trainer
  from pytorch_lightning.callbacks import DeviceStatsMonitor, EarlyStopping, LearningRateMonitor
  from pytorch_lightning.loggers import TensorBoardLogger
  from torch.utils.data import DataLoader
  from torchvision import transforms
  from lightly.data import LightlyDataset
  from lightly.transforms.utils import IMAGENET_NORMALIZE
  from lightly.utils.benchmarking import MetricCallback
  from lightly.utils.dist import print_rank_zero
label_desc: Use image node_id 2 for calling a global function with example usage: pretrain(model, method, train_dir, val_dir, log_dir, batch_size_per_device, epochs, num_workers, accelerator, devices, precision, ckpt_path) without return types