Serialize quantized weights.
(
node: torch.fx.Node,
tosa_graph: Any,
edge_program: ExportedProgram,
tosa_spec: TosaSpecification,
)
| 162 | |
| 163 | |
| 164 | def process_inputs_to_buffers( |
| 165 | node: torch.fx.Node, |
| 166 | tosa_graph: Any, |
| 167 | edge_program: ExportedProgram, |
| 168 | tosa_spec: TosaSpecification, |
| 169 | ): |
| 170 | """Serialize quantized weights.""" |
| 171 | try: |
| 172 | tosa_arg = TosaArg(node, tosa_spec) |
| 173 | except ValueError as e: |
| 174 | raise ValueError( |
| 175 | f"Failed processing buffer placeholder: {node.name}. " |
| 176 | "Is the original torch function supported?" |
| 177 | ) from e |
| 178 | buffer_data = get_buffer(edge_program, node) |
| 179 | |
| 180 | if not isinstance(buffer_data, torch.Tensor): |
| 181 | raise TypeError( |
| 182 | f"Expected buffer '{node.name}' to be a torch.Tensor, got " |
| 183 | f"{type(buffer_data).__name__}" |
| 184 | ) |
| 185 | buffer_values = _tensor_to_numpy(buffer_data) |
| 186 | buffer_values = _prepare_const_values_for_tosa_dtype(buffer_values, tosa_arg.dtype) |
| 187 | |
| 188 | tosa_graph.addConst( |
| 189 | normalize_symint(buffer_values.shape), |
| 190 | tosa_arg.dtype, |
| 191 | buffer_values, |
| 192 | name=tosa_arg.name, |
| 193 | ) |
| 194 | |
| 195 | |
| 196 | def process_inputs_to_lifted_tensor_constants( |
no test coverage detected