|
29 | 29 |
|
30 | 30 | # exist fallback operators in et namespace; |
31 | 31 | supported_fallback_kernels: Dict[str, Any] = { |
32 | | - "aoti_torch_mps_addmm_out": None, |
33 | 32 | "aoti_torch_mps_convolution": None, |
34 | 33 | "aoti_torch_mps_mm_out": None, |
35 | 34 | "at::_ops::_scaled_dot_product_attention_math_for_mps::call": None, |
@@ -108,34 +107,62 @@ def preprocess( |
108 | 107 | options: dict[str, typing.Any] = { |
109 | 108 | # Do not link against the full PyTorch/libtorch library |
110 | 109 | "aot_inductor.link_libtorch": False, |
111 | | - # Package model constants and other generated files directly in the shared object (.so) file |
112 | | - "aot_inductor.package_constants_in_so": True, |
| 110 | + # Separate weight constants from the .so file |
| 111 | + "aot_inductor.package": True, |
| 112 | + "aot_inductor.package_constants_in_so": False, |
| 113 | + # Store weight constants on disk in a binary blob |
| 114 | + "aot_inductor.package_constants_on_disk_format": "binary_blob", |
113 | 115 | # Enable maximum automatic tuning for optimal performance |
114 | 116 | "max_autotune": True, |
115 | 117 | # "aot_inductor.debug_compile": True, |
116 | 118 | # "aot_inductor.force_mmap_weights": False, |
117 | 119 | } |
118 | 120 |
|
119 | 121 | with collect_unsupported_fallback_kernels(): |
120 | | - so_path = torch._inductor.aot_compile(edge_program_module, tuple(user_input_placeholders), options=options) # type: ignore[arg-type] |
| 122 | + paths = torch._inductor.aot_compile(edge_program_module, tuple(user_input_placeholders), options=options) # type: ignore[arg-type] |
121 | 123 | if len(missing_fallback_kernels) > 0: |
122 | 124 | formatted_kernels = "\n - ".join(sorted(missing_fallback_kernels)) |
123 | 125 | raise RuntimeError( |
124 | 126 | f"Missing fallback kernels ({len(missing_fallback_kernels)} total):\n - {formatted_kernels}\n" |
125 | 127 | "Please add them to the AOTI backend." |
126 | 128 | ) |
127 | 129 |
|
| 130 | + # Extract the .so and .blob paths from the returned list |
| 131 | + so_path = None |
| 132 | + blob_path = None |
| 133 | + for path in paths: |
| 134 | + if path.endswith(".wrapper.so"): |
| 135 | + so_path = path |
| 136 | + elif path.endswith(".wrapper_weights.blob"): |
| 137 | + blob_path = path |
| 138 | + |
| 139 | + if so_path is None or blob_path is None: |
| 140 | + raise RuntimeError( |
| 141 | + f"Could not find required files in compiled paths, got {paths}" |
| 142 | + ) |
| 143 | + |
128 | 144 | # pyre-ignorep[6]: Incompatible parameter type |
129 | 145 | with open(so_path, "rb") as f: |
130 | 146 | so_data = f.read() |
131 | 147 |
|
132 | 148 | named_data_store = NamedDataStore() |
133 | 149 | method_name = MetalBackend.method_name_from_compile_specs(compile_specs) |
| 150 | + |
| 151 | + # Keep the so file in the NamedDataStore, so that it can be packaged into the .pte file. |
| 152 | + named_data_store.add_named_data(method_name + "_so_blob", so_data, 1, None) |
| 153 | + |
| 154 | + # Add weights blob to named data store |
| 155 | + with open(blob_path, "rb") as f: |
| 156 | + blob_data = f.read() |
| 157 | + |
134 | 158 | named_data_store.add_named_data( |
135 | | - method_name + "_so_blob", so_data, 1, "aoti_metal_blob" |
| 159 | + method_name + "_weights_blob", blob_data, 1, "aoti_metal_blob" |
136 | 160 | ) |
137 | 161 |
|
138 | | - # Clean up the generated so file; it has been packaged into the NamdeDataStore |
| 162 | + # Clean up the weights blob file |
| 163 | + os.remove(blob_path) |
| 164 | + |
| 165 | + # Clean up the generated so file; it has been packaged into the NamedDataStore |
139 | 166 | # pyre-ignorep[6]: Incompatible parameter type |
140 | 167 | os.remove(so_path) |
141 | 168 |
|
|
0 commit comments