code: def do_minibatch_sgd(
      samples,
      policies,
      local_worker,
      num_sgd_iter,
      sgd_minibatch_size,
      standardize_fields,
  ):
      """Execute minibatch SGD.
  
      Args:
          samples: Batch of samples to optimize.
          policies: Dictionary of policies to optimize.
          local_worker: Master rollout worker instance.
          num_sgd_iter: Number of epochs of optimization to take.
          sgd_minibatch_size: Size of minibatches to use for optimization.
          standardize_fields: List of sample field names that should be
              normalized prior to optimization.
  
      Returns:
          averaged info fetches over the last SGD epoch taken.
      """
  
      # Handle everything as if multi-agent.
      samples = samples.as_multi_agent()
  
      # Use LearnerInfoBuilder as a unified way to build the final
      # results dict from `learn_on_loaded_batch` call(s).
      # This makes sure results dicts always have the same structure
      # no matter the setup (multi-GPU, multi-agent, minibatch SGD,
      # tf vs torch).
      learner_info_builder = LearnerInfoBuilder(num_devices=1)
      for policy_id, policy in policies.items():
          if policy_id not in samples.policy_batches:
              continue
  
          batch = samples.policy_batches[policy_id]
          for field in standardize_fields:
              batch[field] = standardized(batch[field])
  
          # Check to make sure that the sgd_minibatch_size is not smaller
          # than max_seq_len otherwise this will cause indexing errors while
          # performing sgd when using a RNN or Attention model
          if (
              policy.is_recurrent()
              and policy.config["model"]["max_seq_len"]
              > sgd_minibatch_size
          ):
              raise ValueError(
                  "`sgd_minibatch_size` ({}) cannot be smaller than"
                  "`max_seq_len` ({}).".format(
                      sgd_minibatch_size,
                      policy.config["model"]["max_seq_len"],
                  )
              )
  
          for i in range(num_sgd_iter):
              for minibatch in minibatches(batch, sgd_minibatch_size):
                  results = (
                      local_worker.learn_on_batch(
                          MultiAgentBatch(
                              {policy_id: minibatch}, minibatch.count
                          )
                      )
                  )[policy_id]
                  learner_info_builder.add_learn_on_batch_results(
                      results, policy_id
                  )
  
      learner_info = learner_info_builder.finalize()
      return learner_info
  
file_path: ray/rllib/utils/sgd.py
imports: import logging
  import numpy
  import random
  from ray.rllib.utils.annotations import DeveloperAPI
  from ray.rllib.policy.sample_batch import SampleBatch, MultiAgentBatch
  from ray.rllib.utils.metrics.learner_info import LearnerInfoBuilder
label_desc: Use image node_id 3 for calling a global function with example usage: do_minibatch_sgd(samples, policies, local_worker, num_sgd_iter, sgd_minibatch_size, standardize_fields) and returns: learner_info