code: def main():
      # Configurations
      configs = {
          "epochs": 10,
          "train_batch_size": 64,
          "valid_batch_size": 100,
          "use_cuda": True,
          "seed": 5,
          "train_log_interval": 10,
          "learning_rate": 0.01,
      }
  
      is_cuda = configs["use_cuda"] and torch.cuda.is_available()
      if not is_cuda:
          device = torch.device("cpu")
      else:
          device = torch.device(f"cuda:0")
  
      data_transform = transforms.Compose(
          [
              transforms.ToTensor(),
              transforms.Normalize((0.1307,), (0.3081,)),
          ]
      )
  
      train_loader = torch.utils.data.DataLoader(
          datasets.MNIST(
              str(lab.get_data_path()),
              train=True,
              download=True,
              transform=data_transform,
          ),
          batch_size=configs["train_batch_size"],
          shuffle=True,
      )
  
      valid_loader = torch.utils.data.DataLoader(
          datasets.MNIST(
              str(lab.get_data_path()),
              train=False,
              download=True,
              transform=data_transform,
          ),
          batch_size=configs["valid_batch_size"],
          shuffle=False,
      )
  
      model = Net().to(device)
      optimizer = optim.Adam(
          model.parameters(), lr=configs["learning_rate"]
      )
  
      torch.manual_seed(configs["seed"])
  
      # ✨ Create the experiment
      experiment.create(name="mnist_labml_monit")
  
      # ✨ Save configurations
      experiment.configs(configs)
  
      # ✨ Start and monitor the experiment
      with experiment.start():
          for _ in monit.loop(range(1, configs["epochs"] + 1)):
              for mode, batch in monit.mix(
                  10, ("train", train_loader), ("valid", valid_loader)
              ):
                  with tracker.namespace(mode):
                      with torch.set_grad_enabled(mode == "train"):
                          data, target = batch[0].to(device), batch[
                              1
                          ].to(device)
                          output = model(data)
                          loss = F.cross_entropy(output, target)
                          pred = output.argmax(dim=1, keepdim=True)
  
                          if mode == "train":
                              optimizer.zero_grad()
                              loss.backward()
                              optimizer.step()
  
                              tracker.add_global_step(data.shape[0])
  
                          tracker.save(
                              {
                                  "loss.": loss,
                                  "accuracy.": pred.eq(
                                      target.view_as(pred)
                                  ).sum()
                                  / pred.shape[0],
                              }
                          )
  
              tracker.new_line()
  
file_path: labml/samples/pytorch/mnist/c2_labml_monit_mix.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import torch.utils.data
  from torchvision import datasets, transforms
  from labml import lab, tracker, experiment, monit
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types