code: def main(args):
      # Set device
      # check if selected GPU is available or use CPU
      assert (
          args.cuda == -1 or args.cuda >= 0
      ), "cuda must be -1 or >= 0."
      device = torch.device(
          f"cuda:{args.cuda}"
          if torch.cuda.is_available() and args.cuda >= 0
          else "cpu"
      )
      print(f"Using device: {device}")
  
      # Initialize model and specify shape
      model = ExpertGate(shape=(3, 227, 227), device=device)
  
      # Vanilla optimization
      optimizer = SGD(
          model.expert.parameters(),
          lr=args.lr,
          momentum=0.9,
          weight_decay=0.0005,
      )
  
      # Set up strategy
      strategy = ExpertGateStrategy(
          model,
          optimizer,
          device=device,
          train_mb_size=args.minibatch_size,
          train_epochs=args.epochs,
          eval_every=-1,
          ae_train_mb_size=args.minibatch_size,
          ae_train_epochs=int(args.epochs * 2),
          ae_lr=1e-3,
      )
  
      # Build scenario (fast or MNIST)
      scenario = build_scenario(args.mnist)
  
      # Train loop
      for experience in scenario.train_stream:
          t = experience.task_label
          exp_id = experience.current_experience
          training_dataset = experience.dataset
          print()
          print(f"Task {t} batch {exp_id}")
          print(f"This batch contains {len(training_dataset)} patterns")
          print(
              f"Current Classes: {experience.classes_in_this_experience}"
          )
  
          strategy.train(experience)
  
      # Evaluation loop
      print("\nEVALUATION")
      for experience in scenario.test_stream:
          strategy.eval(experience)
  
file_path: avalanche/examples/expert_gate.py
imports: import torch
  import argparse
  from torch.utils.data import DataLoader
  from torch.utils.data import TensorDataset
  from torchvision import transforms
  from torch.optim import SGD
  from sklearn.datasets import make_classification
  from sklearn.model_selection import train_test_split
  from avalanche.models import ExpertGate
  from avalanche.benchmarks.classic import SplitMNIST
  from avalanche.training.supervised import ExpertGateStrategy
  from avalanche.models.utils import avalanche_model_adaptation
  from avalanche.benchmarks import nc_benchmark
label_desc: Use image node_id 1 for calling a global function with example usage: main(args) without return types