Commit e92bd91
Hoist torchbench run-contexts out of the timed loop
Summary:
The `torchbench` benchmark called `model.invoke()` once per timed
iteration. `BenchmarkModel.invoke()` wraps each call in `with
nested(*self.run_contexts)`, which rebuilds an `ExitStack` plus fresh
context-manager and closure objects (`enable_profiling_executor`, the
`pick_grad` lambda) on every call.
`perf` profiling of `pyhpc_equation_of_state` under the CinderX JIT showed this
per-iteration churn as `contextlib`/`nested`/`ExitStack` frames, and because the
short-lived functions are created and destroyed each iteration it also kept the
JIT busy with `scheduleJitCompile`/`funcDestroyed` cleanup in steady state,
overhead that only penalizes the JIT arm of the comparison.
This change adds `resolve_step()`, which returns the model's `eval`/`train` step
together with its `run_contexts`. `run()` now enters those contexts once in a
single `ExitStack` around warmup and the timed loop, and calls the step directly
per iteration. Staged-train keeps its own per-stage contexts, so it falls back
to `invoke()`. Entering grad mode once around many iterations also better
reflects a real serving loop.
Reviewed By: mpage
Differential Revision: D109523407
fbshipit-source-id: 2f6b61a9de2473793a539e717de320cc43c61b8d1 parent 0e54ec1 commit e92bd91
1 file changed
Lines changed: 58 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
79 | 113 | | |
80 | 114 | | |
81 | 115 | | |
82 | | - | |
| 116 | + | |
83 | 117 | | |
84 | 118 | | |
85 | 119 | | |
86 | 120 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
99 | 142 | | |
100 | 143 | | |
101 | 144 | | |
| |||
0 commit comments