(regional=False)
| 185 | return end - start |
| 186 | |
| 187 | def aot_compile_load_model(regional=False) -> torch.nn.Module: |
| 188 | input = torch.randn(10, 10, device="cuda") |
| 189 | model = Model().cuda() |
| 190 | |
| 191 | inductor_configs = {} |
| 192 | if regional: |
| 193 | inductor_configs = {"aot_inductor.package_constants_in_so": False} |
| 194 | |
| 195 | # Reset the compiler caches to ensure no reuse between different runs |
| 196 | torch.compiler.reset() |
| 197 | with torch._inductor.utils.fresh_inductor_cache(): |
| 198 | path = torch._inductor.aoti_compile_and_package( |
| 199 | torch.export.export( |
| 200 | model.layers[0] if regional else model, |
| 201 | args=(input,) |
| 202 | ), |
| 203 | inductor_configs=inductor_configs, |
| 204 | ) |
| 205 | |
| 206 | if regional: |
| 207 | for layer in model.layers: |
| 208 | compiled_layer = torch._inductor.aoti_load_package(path) |
| 209 | compiled_layer.load_constants( |
| 210 | layer.state_dict(), check_full_update=True, user_managed=True |
| 211 | ) |
| 212 | layer.forward = compiled_layer |
| 213 | else: |
| 214 | model = torch._inductor.aoti_load_package(path) |
| 215 | return model |
| 216 | |
| 217 | input = torch.randn(10, 10, device="cuda") |
| 218 | full_model_compilation_latency = measure_compile_time(input, regional=False) |
no test coverage detected