code: def calculate_gradients(
      batch_size: int = 4,
      epoch_size: int = 64,
      num_epochs: int = 3,
      lr: float = 0.001,
  ) -> typing.List[float]:
      # independently compute expected metrics
      batches = [
          (v[:], v[:])
          for v in (
              [x * 0.1 + 1.0 for x in range(y, y + batch_size)]
              for y in (
                  z % epoch_size
                  for z in range(0, epoch_size * num_epochs, batch_size)
              )
          )
      ]
  
      def compute_expected_weight(
          data: typing.List[float], label: typing.List[float], w: float
      ) -> float:
          n = len(data)
          expected_step = (
              2.0
              * lr
              * sum((d * (l - d * w) for d, l in zip(data, label)))
              / n
          )
          return w + expected_step
  
      expected_weights = []
      weight = 0.0
      data: typing.List[float] = []
      label: typing.List[float] = []
      for i, batch in enumerate(batches):
          if i % 2 == 0:
              # for even-numbered batches the optimizer step is a no-op:
              # the weights don't change
              data, label = batch
          else:
              additional_data, additional_label = batch
              data += additional_data
              label += additional_label
              weight = compute_expected_weight(data, label, weight)
          expected_weights.append(weight)
  
      return expected_weights
  
imports: import contextlib
  import importlib
  import io
  import os
  import pathlib
  import sys
  import typing
  from unittest import mock
  import numpy
  import pytest
  import torch
  from _pytest import monkeypatch
  from torch.distributed import launcher
  import determined
  from determined import pytorch
  from tests.experiment import pytorch_utils, utils
  from tests.experiment.fixtures import pytorch_onevar_model
label_desc: Use image node_id 7 for calling a global function with example usage: calculate_gradients(batch_size, epoch_size, num_epochs, lr) and returns: expected_weights, unknown