Args: preprocess_once_fn: A callable that takes no arguments and performs one-time preprocessing before backward (e.g., start timers). Will only be called once per backward pass. preprocess_per_tensor_fn:
(self, preprocess_once_fn, preprocess_per_tensor_fn=None)
| 1369 | """ |
| 1370 | |
| 1371 | def __init__(self, preprocess_once_fn, preprocess_per_tensor_fn=None): |
| 1372 | """ |
| 1373 | Args: |
| 1374 | preprocess_once_fn: A callable that takes no arguments and performs |
| 1375 | one-time preprocessing before backward (e.g., start timers). |
| 1376 | Will only be called once per backward pass. |
| 1377 | preprocess_per_tensor_fn: Optional callable that takes a tensor and returns |
| 1378 | a potentially modified tensor. Called for each output |
| 1379 | tensor during backward (e.g., gradient scaling). |
| 1380 | If None, no per-tensor processing is done. |
| 1381 | """ |
| 1382 | self.preprocess_once_fn = preprocess_once_fn |
| 1383 | self.preprocess_per_tensor_fn = preprocess_per_tensor_fn |
| 1384 | self.preprocess_done = False |
| 1385 | self.hook_handles = [] |
| 1386 | |
| 1387 | def _make_backward_hook(self, tensor): |
| 1388 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected