code: def get_step_sequence(action_skips: Iterable[int]) -> Sequence[int]:
      """Generates a sequence of step muls for the replay stream.
  
      In SC2 we train on observations with actions but actions in replays are
      reported in frames after they were taken. We need a step sequence so we can
      advance the SC2 environment to the relevant observations before the action was
      taken and then step again with delta=1 to get the actual action on the next
      frame. A step sequence is key from a performance point of view since at the
      steps where no actions were taken we do not really need to render which is the
      expensive part of processing a replay. We can advance the simulation without
      rendering at a relatively low cost.
  
      An example stream looks like this:
      (obs_{0},)------(obs_{k-1},)---(obs_{k}, a_{k-1})---(obs_{k+1}, a_{k})...
  
      The first observation where an action was taken is `obs_{k-1}`, but the replay
      will not report the action until we request the next observation `obs_{k}`.
      In the above case we also have an action taken at timestep k, but it will be
      reported when we request `obs_{k+1}`. A step sequence would allow us to
      get a union of the observations that we want to report for training and
      those that have actions in them. An example step sequence for the above stream
      would be `[k-1, 1, 1]` where we first step k-1 times to get to the first
      observation where an action was taken, then step once to get the actual action
      as it is reported late.
  
      Args:
        action_skips: A sequence of game loops where actions were taken in the
          replay. This contains the game loops of the observations that happened
          before the action was reported by the replay to align it with the time
          step when the player took the action (replays report past actions). Note
          that the provided action skips sequence is assumed to have already been
          processed to include only relevant frames depending on the action types of
          interest (e.g., with or without camera moves).
  
      Returns:
        A sequence of step_muls to use in the replay stream.
      """
      prev_game_loop = 0
      steps = []
      for current_game_loop in action_skips:
          if prev_game_loop == 0:
              steps.append(current_game_loop)
          elif current_game_loop - prev_game_loop > 1:
              # We need to yield twice: to get the observation immediately before the
              # action (this is the game loop number we stored in the index), and to
              # get the replay observation that will return the actual actions. This
              # is needed because replays return actions that humans have taken on
              # previous frames.
              steps.append(1)
              steps.append(current_game_loop - prev_game_loop - 1)
          elif current_game_loop - prev_game_loop == 1:
              # Both previous and current observations had actions, step 1.
              steps.append(1)
          prev_game_loop = current_game_loop
      return steps
  
file_path: pysc2/pysc2/lib/replay/replay_converter.py
imports: import collections
  from typing import Any, Dict, Iterable, Sequence
  import numpy
  from pysc2.env.converter import converter
  from pysc2.env.converter import derive_interface_options
  from pysc2.env.converter.proto import converter_pb2
  from pysc2.lib.replay import replay_observation_stream
  from pysc2.lib.replay import sc2_replay
  from pysc2.lib.replay import sc2_replay_utils
  import tree
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 6 for calling a global function with example usage: get_step_sequence(action_skips) and returns: steps