MCPcopy Create free account
hub / github.com/pytorch/tutorials / aot_compile_load_model

Function aot_compile_load_model

recipes_source/regional_aot.py:187–215  ·  view source on GitHub ↗
(regional=False)

Source from the content-addressed store, hash-verified

185 return end - start
186
187def 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
217input = torch.randn(10, 10, device="cuda")
218full_model_compilation_latency = measure_compile_time(input, regional=False)

Callers 1

measure_compile_timeFunction · 0.85

Calls 1

ModelClass · 0.70

Tested by

no test coverage detected