Graph is a PPQ Internal Represtation Data Structure. A computational graph is a directed graph where the nodes correspond to operations or variables. Variables can feed their value into operations, and operations can feed their output into other operations. This way, every node in t
| 229 | |
| 230 | |
| 231 | class BaseGraph(Serializable): |
| 232 | """Graph is a PPQ Internal Represtation Data Structure. |
| 233 | |
| 234 | A computational graph is a directed graph where the nodes correspond to operations or variables. |
| 235 | Variables can feed their value into operations, and operations can feed their output into other operations. |
| 236 | This way, every node in the graph defines a function of the variables. |
| 237 | |
| 238 | The values that are fed into the nodes and come out of the nodes are called tensors, |
| 239 | which is just a fancy word for a multi-dimensional array. |
| 240 | Hence, it subsumes scalars, vectors and matrices as well as tensors of a higher rank. |
| 241 | |
| 242 | The computational graph created by PPQ contains quantization info as well as operations and variables. |
| 243 | So to say it is a computational graph designed for quantization. |
| 244 | |
| 245 | All quantization related infos are stored within graph and its operations. |
| 246 | See ppq.IR.quantize for more information. |
| 247 | |
| 248 | Args: |
| 249 | Serializable ([type]): [description] |
| 250 | """ |
| 251 | def __init__(self, name: str, built_from: NetworkFramework = NetworkFramework.NATIVE) -> None: |
| 252 | super().__init__() |
| 253 | self._operations = {} |
| 254 | self._variables = {} |
| 255 | self._graph_inputs = {} |
| 256 | self._graph_outputs = {} |
| 257 | self._name = name |
| 258 | self._built_from = built_from |
| 259 | self._detail = {} |
| 260 | self._num_of_generated_var = 0 |
| 261 | self._num_of_generated_op = 0 |
| 262 | |
| 263 | |
| 264 | @ property |
| 265 | def operations(self) -> Dict[str, Operation]: |
| 266 | return self._operations |
| 267 | |
| 268 | @ property |
| 269 | def variables(self) -> Dict[str, Variable]: |
| 270 | return self._variables |
| 271 | |
| 272 | @ property |
| 273 | def inputs(self) -> Dict[str, Variable]: |
| 274 | return self._graph_inputs |
| 275 | |
| 276 | @ property |
| 277 | def outputs(self) -> Dict[str, Variable]: |
| 278 | return self._graph_outputs |
| 279 | |
| 280 | def parameters(self) -> List[torch.Tensor]: |
| 281 | parameters = [] |
| 282 | for var in self.variables.values(): |
| 283 | if var.is_parameter: |
| 284 | parameters.append(var.value) |
| 285 | return parameters |
| 286 | |
| 287 | def set_extension_attrib(self, attrib: str, value: Any): |
| 288 | self._detail[attrib] = value |
no outgoing calls
no test coverage detected