(serialized_graph)
| 19884 | throw new python.Error(`Unsupported graph node ${output.type}.`); |
| 19885 | } |
| 19886 | deserialize_graph(serialized_graph) { |
| 19887 | for (const [name, tensor_value] of serialized_graph.tensor_values) { |
| 19888 | const meta_val = this.deserialize_tensor_meta(tensor_value.meta || tensor_value, this.fake_tensor_mode); |
| 19889 | this.serialized_name_to_meta.set(name, meta_val); |
| 19890 | } |
| 19891 | for (const [name, sym_int_value] of serialized_graph.sym_int_values) { |
| 19892 | this.serialized_name_to_meta.set(name, this.deserialize_sym_int(sym_int_value)); |
| 19893 | } |
| 19894 | for (const [name, sym_bool_value] of serialized_graph.sym_bool_values) { |
| 19895 | this.serialized_name_to_meta.set(name, this.deserialize_sym_bool(sym_bool_value)); |
| 19896 | } |
| 19897 | for (const [name, script_obj_meta] of serialized_graph.custom_obj_values) { |
| 19898 | this.serialized_name_to_meta.set(name, this.deserialize_script_obj_meta(script_obj_meta)); |
| 19899 | } |
| 19900 | for (let i = 0; i < serialized_graph.inputs.length; i++) { |
| 19901 | const input = serialized_graph.inputs[i]; |
| 19902 | if (input.type === 'as_tensor' || input.type === 'as_sym_int' || input.type === 'as_custom_obj') { |
| 19903 | const node_name = input.value.name; |
| 19904 | const placeholder_node = this.graph.placeholder(node_name); |
| 19905 | placeholder_node.name = node_name; |
| 19906 | this.sync_fx_node(node_name, placeholder_node); |
| 19907 | } else if (input.type === 'as_int' || input.type === 'as_float' || input.type === 'as_bool' || input.type === 'as_none' || input.type === 'as_string') { |
| 19908 | const node_name = this.signature.input_specs[i].arg.name; |
| 19909 | const placeholder_node = this.graph.placeholder(node_name); |
| 19910 | placeholder_node.meta.set('val', this.deserialize_input(input)); |
| 19911 | } else { |
| 19912 | throw new python.Error(`Invalid input ${input.type}.`); |
| 19913 | } |
| 19914 | } |
| 19915 | for (const serialized_node of serialized_graph.nodes) { |
| 19916 | const target = this.deserialize_operator(serialized_node.target); |
| 19917 | this.deserialize_node(serialized_node, target); |
| 19918 | } |
| 19919 | let outputs = []; |
| 19920 | for (const output of serialized_graph.outputs) { |
| 19921 | outputs.push(this.deserialize_graph_output(output)); |
| 19922 | } |
| 19923 | if (serialized_graph.is_single_tensor_return) { |
| 19924 | [outputs] = outputs; |
| 19925 | } else { |
| 19926 | outputs = new builtins.tuple(outputs); |
| 19927 | } |
| 19928 | const output_node = this.graph.output(outputs); |
| 19929 | if (serialized_graph.is_single_tensor_return) { |
| 19930 | output_node.meta.set('val', output_node.args[0].meta.get('val')); |
| 19931 | } else { |
| 19932 | output_node.meta.set('val', new builtins.tuple(Array.from(output_node.args[0]).map((arg) => |
| 19933 | arg instanceof torch.fx.Node ? arg.meta.get('val') : arg |
| 19934 | ))); |
| 19935 | } |
| 19936 | return self.graph; |
| 19937 | } |
| 19938 | deserialize_operator(serialized_target) { |
| 19939 | let module = null; |
| 19940 | let serialized_target_names = null; |
no test coverage detected