Commit cb7f45f
remove unnecessary sync point in AveragedModel update (pytorch#158017)
Summary:
The test `bool(self.n_averaged == 0)` is a CPU/GPU synchronization point that is called for each update.
This test is only meant to know whether the AveragedModel copy has been initialized or not.
This diff introduces a CPU-based variable for that purpose.
When loading from checkpoint we also make sure the parameter is refreshed.
After this fix, each `update_parameter` call is reduced to 6ms from 333ms (98% reduction).
Test Plan:
contbuild & OSS CI
Test plan from GitHub:
CI
Rollback Plan:
Differential Revision: D78074709
Pull Request resolved: pytorch#158017
Approved by: https://github.com/janeyx991 parent 5937861 commit cb7f45f
2 files changed
+78
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
| |||
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
153 | 190 | | |
154 | 191 | | |
155 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
119 | 141 | | |
120 | 142 | | |
121 | 143 | | |
| |||
215 | 237 | | |
216 | 238 | | |
217 | 239 | | |
218 | | - | |
| 240 | + | |
219 | 241 | | |
220 | 242 | | |
221 | 243 | | |
| |||
234 | 256 | | |
235 | 257 | | |
236 | 258 | | |
237 | | - | |
238 | | - | |
239 | | - | |
| 259 | + | |
240 | 260 | | |
241 | 261 | | |
242 | 262 | | |
| 263 | + | |
243 | 264 | | |
244 | 265 | | |
245 | 266 | | |
246 | 267 | | |
247 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
248 | 278 | | |
249 | 279 | | |
250 | 280 | | |
| |||
280 | 310 | | |
281 | 311 | | |
282 | 312 | | |
283 | | - | |
| 313 | + | |
284 | 314 | | |
285 | 315 | | |
286 | 316 | | |
287 | 317 | | |
288 | 318 | | |
289 | 319 | | |
290 | | - | |
291 | | - | |
292 | | - | |
| 320 | + | |
293 | 321 | | |
294 | 322 | | |
295 | | - | |
296 | 323 | | |
297 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
298 | 327 | | |
299 | 328 | | |
300 | 329 | | |
301 | 330 | | |
302 | | - | |
303 | 331 | | |
304 | | - | |
| 332 | + | |
305 | 333 | | |
306 | 334 | | |
307 | 335 | | |
| |||
0 commit comments