class_docstr: A almost-drop-in replacement for torch.nn.ModuleList that results in full and unique scope-names when traced
  
  So why do we need this?
    Some flows in Distiller, such as modules fusion and "net-aware" quantization in PostTrainLinearQuantizer, rely
    on the ability to infer the connectivity within the model, at the Python API level. This is done using
    SummaryGraph, which internally uses PyTorch's trace capabilities. When tracing, each operation
    executed creates a node in the trace, which has a "scope-name". Distiller then uses the "scope-name" to do a
    reverse mapping - map from the trace node back to the actual nn.Module defined in the model code.
  
    These "scope-names" are generated by tracking the ".forward()" calls of modules. However, The torch.nn.ModuleList
    class itself doesn't have its own forward method. That makes perfect sense - it is only intended to be used as a
    container of modules which the user accesses explicitly.
    Unfortunately, this means that if an operation is part of a ModuleList, the name of the ModuleList instance
    does not appear in the "scope-name". This makes it impossible for us to do the reverse mapping mentioned
    above.
  
  From here on, we refer to the module which contains the DistillerModuleList instance as the "parent module".
  
  Similarities to torch.nn.ModuleList:
    * A DistillerModuleList can be indexed like a regular Python list, but the modules it contains are properly
      registered and will be visible to all torch.nn.Module methods.
    * The DistllerModuleList instance is registered as an attribute of the "parent module"
    * This means that in terms of accessing the modules and invoking them, DistillerModuleList behaves exactly the
      same as torch.nn.ModuleList. See the example below.
  
  Differences vs. torch.nn.ModuleList:
    * DistillerModuleList is NOT a sub-class of torch.nn.Module
    * This means that the modules in the list are NOT sub-modules of the list itself. They are registered as
      sub-modules of the "parent module". That is - the contents of a DistillerModuleList are "flattened" within the
      "parent module".
    * In addition, we can't use the '.' character to denote the "nesting" of a module within the list. We use '_'.
    * All of this means that calls to functions like state_dict() / named_modules() / named_children() / etc. on the
      "parent_module" return different results when this class is used compared to torch.nn.ModuleList.
  
  At the moment we don't see a usage for this class "in the wild", outside of SummaryGraph generation.
  In the context of SummaryGraph, we're going to take a pre-created model and replace any torch.nn.ModuleList
  instances with DistillerModuleLists. Once that is done, during model execution we expect that lists are being
  used as read-only (no modules are added to/removed from the list). We're not supporting loading state_dict "across"
  converted models.
  This means that:
    * We implement only a subset of the standard API of a Python sequence (see collections.abc.MutableSequence):
      'append()', 'extend()', '__len__()' and '__getitem()_'
      These are the only ones required to perform the conversion for an already created model.
    * We're not implementing:
      'insert()', '__setitem__()' and '__delitem__()'.
  
  If we see in the future that our assumptions break, we'll add the necessary APIs.
  
  For all the reasons mentioned above, and to avoid unnecessary confusion for users, we're keeping this class
  internal to summary_graph for now.
  
  Args:
      name (string): The base name to be used when registering modules added to the list
      parent_module (torch.nn.Module): The module to which the modules added to the list will be registered.
        NOTE: This is expected to be the module containing the list, but we can't enforce this.
      modules (iterable, optional): An iterable of modules to initialize the list with
class_docstr_tok: ["A","almost-drop-in","replacement","for","torch.nn.ModuleList","that","results","in","full","and","unique","scope-names","when","traced","So","why","do","we","need","this","?","Some","flows","in","Distiller",",","such","as","modules","fusion","and","``","net-aware","''","quantization","in","PostTrainLinearQuantizer",",","rely","on","the","ability","to","infer","the","connectivity","within","the","model",",","at","the","Python","API","level",".","This","is","done","using","SummaryGraph",",","which","internally","uses","PyTorch","'s","trace","capabilities",".","When","tracing",",","each","operation","executed","creates","a","node","in","the","trace",",","which","has","a","``","scope-name","''",".","Distiller","then","uses","the","``","scope-name","''","to","do","a","reverse","mapping","-","map","from","the","trace","node","back","to","the","actual","nn.Module","defined","in","the","model","code",".","These","``","scope-names","''","are","generated","by","tracking","the","``",".forward","(",")","''","calls","of","modules",".","However",",","The","torch.nn.ModuleList","class","itself","does","n't","have","its","own","forward","method",".","That","makes","perfect","sense","-","it","is","only","intended","to","be","used","as","a","container","of","modules","which","the","user","accesses","explicitly",".","Unfortunately",",","this","means","that","if","an","operation","is","part","of","a","ModuleList",",","the","name","of","the","ModuleList","instance","does","not","appear","in","the","``","scope-name","''",".","This","makes","it","impossible","for","us","to","do","the","reverse","mapping","mentioned","above",".","From","here","on",",","we","refer","to","the","module","which","contains","the","DistillerModuleList","instance","as","the","``","parent","module","''",".","Similarities","to","torch.nn.ModuleList",":","*","A","DistillerModuleList","can","be","indexed","like","a","regular","Python","list",",","but","the","modules","it","contains","are","properly","registered","and","will","be","visible","to","all","torch.nn.Module","methods",".","*","The","DistllerModuleList","instance","is","registered","as","an","attribute","of","the","``","parent","module","''","*","This","means","that","in","terms","of","accessing","the","modules","and","invoking","them",",","DistillerModuleList","behaves","exactly","the","same","as","torch.nn.ModuleList",".","See","the","example","below",".","Differences","vs.","torch.nn.ModuleList",":","*","DistillerModuleList","is","NOT","a","sub-class","of","torch.nn.Module","*","This","means","that","the","modules","in","the","list","are","NOT","sub-modules","of","the","list","itself",".","They","are","registered","as","sub-modules","of","the","``","parent","module","''",".","That","is","-","the","contents","of","a","DistillerModuleList","are","``","flattened","''","within","the","``","parent","module","''",".","*","In","addition",",","we","ca","n't","use","the","'",".","'","character","to","denote","the","``","nesting","''","of","a","module","within","the","list",".","We","use","'","_","'",".","*","All","of","this","means","that","calls","to","functions","like","state_dict","(",")","\/","named_modules","(",")","\/","named_children","(",")","\/","etc",".","on","the","``","parent_module","''","return","different","results","when","this","class","is","used","compared","to","torch.nn.ModuleList",".","At","the","moment","we","do","n't","see","a","usage","for","this","class","``","in","the","wild","''",",","outside","of","SummaryGraph","generation",".","In","the","context","of","SummaryGraph",",","we","'re","going","to","take","a","pre-created","model","and","replace","any","torch.nn.ModuleList","instances","with","DistillerModuleLists",".","Once","that","is","done",",","during","model","execution","we","expect","that","lists","are","being","used","as","read-only","(","no","modules","are","added","to\/removed","from","the","list",")",".","We","'re","not","supporting","loading","state_dict","``","across","''","converted","models",".","This","means","that",":","*","We","implement","only","a","subset","of","the","standard","API","of","a","Python","sequence","(","see","collections.abc.MutableSequence",")",":","'append","(",")","'",",","'extend","(",")","'",",","'__len__","(",")","'","and","'__getitem","(",")","_'","These","are","the","only","ones","required","to","perform","the","conversion","for","an","already","created","model",".","*","We","'re","not","implementing",":","'insert","(",")","'",",","'__setitem__","(",")","'","and","'__delitem__","(",")","'",".","If","we","see","in","the","future","that","our","assumptions","break",",","we","'ll","add","the","necessary","APIs",".","For","all","the","reasons","mentioned","above",",","and","to","avoid","unnecessary","confusion","for","users",",","we","'re","keeping","this","class","internal","to","summary_graph","for","now",".","Args",":","name","(","string",")",":","The","base","name","to","be","used","when","registering","modules","added","to","the","list","parent_module","(","torch.nn.Module",")",":","The","module","to","which","the","modules","added","to","the","list","will","be","registered",".","NOTE",":","This","is","expected","to","be","the","module","containing","the","list",",","but","we","ca","n't","enforce","this",".","modules","(","iterable",",","optional",")",":","An","iterable","of","modules","to","initialize","the","list","with"]
code: def __init__(self, name, parent_module, modules=None):
      self.name = name
      if not isinstance(parent_module, nn.Module):
          raise TypeError(
              "parent_module must be an instance of torch.nn.Module"
          )
      self.parent_module = parent_module
      self._modules = []
      if modules is not None:
          self.extend(modules)
  
imports: from .None import distiller
  import re
  import numpy
  import collections
  import torch
  import torch.nn
  import torch.jit
  import logging
  from collections import OrderedDict, defaultdict
  from collections.abc import MutableSequence, Iterable
label_desc: Use image node_id 1 to create a new _DistillerModuleList object from inherited base classes: object with example: obj = _DistillerModuleList(name, parent_module, modules)