code: def sweep_C_values(
      *,
      train_features,
      train_labels,
      test_data_loader,
      metric_type,
      num_classes,
      train_dtype=torch.float64,
      train_features_device=_CPU_DEVICE,
      max_train_iters=DEFAULT_MAX_ITER,
  ):
      if metric_type == MetricType.PER_CLASS_ACCURACY:
          # If we want to output per-class accuracy, we select the hyperparameters with mean per class
          metric_type = MetricType.MEAN_PER_CLASS_ACCURACY
      logreg_metric = build_metric(metric_type, num_classes=num_classes)
      metric_tracker = MetricTracker(logreg_metric, maximize=True)
      ALL_C = 10**C_POWER_RANGE
      logreg_models = {}
  
      train_features = train_features.to(
          dtype=train_dtype, device=train_features_device
      )
      train_labels = train_labels.to(device=train_features_device)
  
      for i in range(get_global_rank(), len(ALL_C), get_global_size()):
          C = ALL_C[i].item()
          logger.info(
              f"Training for C = {C:.5f}, dtype={train_dtype}, "
              f"features: {train_features.shape}, {train_features.dtype}, "
              f"labels: {train_labels.shape}, {train_labels.dtype}"
          )
          logreg_models[C] = train_for_C(
              C=C,
              max_iter=max_train_iters,
              train_features=train_features,
              train_labels=train_labels,
              dtype=train_dtype,
              device=train_features_device,
          )
  
      gather_list = [None for _ in range(get_global_size())]
      torch.distributed.all_gather_object(gather_list, logreg_models)
  
      logreg_models_gathered = {}
      for logreg_dict in gather_list:
          logreg_models_gathered.update(logreg_dict)
  
      for i in range(len(ALL_C)):
          metric_tracker.increment()
          C = ALL_C[i].item()
          evals = evaluate_model(
              logreg_model=logreg_models_gathered[C],
              logreg_metric=metric_tracker,
              test_data_loader=test_data_loader,
              device=torch.cuda.current_device(),
          )
          logger.info(f"Trained for C = {C:.5f}, accuracies = {evals}")
  
          best_stats, which_epoch = metric_tracker.best_metric(
              return_step=True
          )
          best_stats_100 = {k: 100.0 * v for k, v in best_stats.items()}
          if which_epoch["top-1"] == i:
              best_C = C
      logger.info(f"Sweep best {best_stats_100}, best C = {best_C:.6f}")
  
      return best_stats, best_C
  
imports: import argparse
  import gc
  import logging
  import sys
  import time
  from typing import List, Optional
  from cuml.linear_model import LogisticRegression
  import torch
  import torch.backends.cudnn
  import torch.distributed
  from torch import nn
  from torch.utils.data import TensorDataset
  from torchmetrics import MetricTracker
  from dinov2.data import make_dataset
  from dinov2.data.transforms import make_classification_eval_transform
  from dinov2.distributed import get_global_rank, get_global_size
  from dinov2.eval.metrics import MetricType, build_metric
  from dinov2.eval.setup import get_args_parser
  from dinov2.eval.setup import setup_and_build_model
  from dinov2.eval.utils import evaluate, extract_features
  from dinov2.utils.dtype import as_torch_dtype
label_desc: Use image node_id 5 for calling a global function with example usage: sweep_C_values() and returns: best_stats,  best_C