(self: "TestMemoryPlanning")
| 282 | # parameterized.expand is not compatible with maketest. I'll just loop thru |
| 283 | # the test setups in the wrapper. |
| 284 | def wrapper(self: "TestMemoryPlanning") -> None: |
| 285 | nonlocal criteria |
| 286 | if not criteria: |
| 287 | criteria = [ |
| 288 | # naive algorithm does not reuse tensor storages |
| 289 | (naive, False), |
| 290 | # greedy algorithm should reuse tensor storages in the testing model |
| 291 | (greedy, True), |
| 292 | ] |
| 293 | |
| 294 | for algo, expect_reuse in criteria: |
| 295 | print( |
| 296 | f"algo {getattr(algo, '__name__', repr(algo))}, expect_reuse {expect_reuse}" |
| 297 | ) |
| 298 | eager_module = module_cls().eval() |
| 299 | # pyre-fixme[29]: `Union[nn.modules.module.Module, |
| 300 | # torch._tensor.Tensor]` is not a function. |
| 301 | inputs = eager_module.get_random_inputs() |
| 302 | graph_module = ( |
| 303 | to_edge(export(eager_module, inputs, strict=True)) |
| 304 | .exported_program() |
| 305 | .graph_module |
| 306 | ) |
| 307 | mem_algo = MemoryPlanningAlgorithmSuite(algo_list=[algo]) |
| 308 | graph_module = PassManager( |
| 309 | passes=[ |
| 310 | SpecPropPass(), |
| 311 | ToOutVarPass(), |
| 312 | MemoryPlanningPass( |
| 313 | mem_algo, |
| 314 | alloc_graph_input=alloc_graph_input, |
| 315 | alloc_graph_output=alloc_graph_output, |
| 316 | ), |
| 317 | ], |
| 318 | )(graph_module).graph_module |
| 319 | |
| 320 | self.verify_reuse( |
| 321 | graph_module, |
| 322 | expect_reuse, |
| 323 | alloc_graph_input, |
| 324 | alloc_graph_output, |
| 325 | alloc_mutable_buffer, |
| 326 | ) |
| 327 | self.verify_graph_input_output( |
| 328 | graph_module, |
| 329 | alloc_graph_input, |
| 330 | alloc_graph_output, |
| 331 | alloc_mutable_buffer, |
| 332 | ) |
| 333 | |
| 334 | self.verify_overlap_placeholders(has_unused_graph_input, graph_module) |
| 335 | |
| 336 | # print(f"Final code: {graph_module.code}") |
| 337 | # print(f"Final graph: {graph_module.graph}") |
| 338 | |
| 339 | if extra_check: |
| 340 | extra_check(self, graph_module) |
| 341 |
nothing calls this directly
no test coverage detected