MCPcopy Create free account
hub / github.com/pytorch/executorch / _ProgramState

Class _ProgramState

exir/emit/_emitter.py:103–134  ·  view source on GitHub ↗

State shared between all methods of a program and the graph module it represents. Initialized once within emit_program and then shared across each entry point as they are emitted.

Source from the content-addressed store, hash-verified

101
102@dataclass
103class _ProgramState:
104 """State shared between all methods of a program and the graph module it represents.
105
106 Initialized once within emit_program and then shared across each entry point as they are
107 emitted.
108 """
109
110 # Parallel list of specs and the buffers that backed them, have to add + 1 to any index in here
111 # as index 0 in the constant_buffer is reserved.
112 allocated_specs: List[TensorSpec] = field(default_factory=list)
113 # Weights in any arbitrary graph_module only need to compare against weights from previously
114 # emitted graph modules, not any weights emitted from itself. This should speed up the lookup,
115 # from O(N) to O(1)
116 cached_spec_hash_values: Dict[str, int] = field(default_factory=dict)
117 cached_spec_mutable_hash_values: Dict[str, int] = field(default_factory=dict)
118 # The 0 index is reserved to be pointed to by non-constant tensors, so add an empty placeholder.
119 constant_buffer: List[Buffer] = field(default_factory=lambda: [Buffer(storage=b"")])
120 # The 0 index is reserved to be pointed to by non-constant tensors, so add an empty placeholder.
121 mutable_buffer: List[Buffer] = field(default_factory=lambda: [Buffer(storage=b"")])
122 # Delegate data stored directly in the flatbuffer. Pointed to by BackendDelegateDataReference,
123 # and should be copied to Program.backend_delegate_data.
124 backend_delegate_data: List[BackendDelegateInlineData] = field(default_factory=list)
125 # Delegate cache that is used across all entry points. Key is the hash of the delegated payload.
126 backend_delegate_data_cache: Dict[str, int] = field(default_factory=dict)
127
128 # Constants are optionally stored in external files.
129 # Aggregate unique external constants into one buffer.
130 external_constant_buffer: List[bytes] = field(default_factory=list)
131 external_constant_hash: Dict[str, int] = field(default_factory=dict)
132 # Each constant_tag groups a set of constants together.
133 # {constant_tag: {fqn: index into external_constant_buffer}}
134 external_constant_map: Dict[str, Dict[str, int]] = field(default_factory=dict)
135
136
137@dataclass

Callers 1

emit_programFunction · 0.90

Calls 1

BufferClass · 0.90

Tested by

no test coverage detected