code: def subsequence(
      sequential,
      first_layer=None,
      last_layer=None,
      after_layer=None,
      upto_layer=None,
      single_layer=None,
      share_weights=False,
  ):
      """
      Creates a subsequence of a pytorch Sequential model, copying over
      modules together with parameters for the subsequence.  Only
      modules from first_layer to last_layer (inclusive) are included,
      or modules between after_layer and upto_layer (exclusive).
      Handles descent into dotted layer names as long as all references
      are within nested Sequential models.
  
      If share_weights is True, then references the original modules
      and their parameters without copying them.  Otherwise, by default,
      makes a separate brand-new copy.
      """
      assert (single_layer is None) or (
          first_layer is last_layer is after_layer is upto_layer is None
      )
      if single_layer is not None:
          first_layer = single_layer
          last_layer = single_layer
      first, last, after, upto = [
          None if d is None else d.split(".")
          for d in [first_layer, last_layer, after_layer, upto_layer]
      ]
      return hierarchical_subsequence(
          sequential,
          first=first,
          last=last,
          after=after,
          upto=upto,
          share_weights=share_weights,
      )
  
imports: import contextlib
  import copy
  import inspect
  from collections import OrderedDict
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: subsequence(sequential, first_layer, last_layer, after_layer, upto_layer, single_layer, share_weights) and returns: hierarchical_subsequence