Helper function to be used with checkpoint() Adapted from torch.utils.checkpoint:checkpoint_sequential()
(start, end)
| 306 | self.micro_offset += 1 |
| 307 | |
| 308 | def exec_range_func(start, end): |
| 309 | ''' Helper function to be used with checkpoint() |
| 310 | Adapted from torch.utils.checkpoint:checkpoint_sequential() |
| 311 | ''' |
| 312 | local_micro_offset = self.micro_offset + 1 |
| 313 | |
| 314 | def exec_func(*inputs): |
| 315 | # Single tensor inputs need to be unwrapped |
| 316 | if len(inputs) == 1: |
| 317 | inputs = inputs[0] |
| 318 | for idx, layer in enumerate(self.forward_funcs[start:end]): |
| 319 | self.curr_layer = idx + self._local_start |
| 320 | if self.seed_layers: |
| 321 | new_seed = (self.base_seed * local_micro_offset) + self.curr_layer |
| 322 | if self.seed_fn: |
| 323 | self.seed_fn(new_seed) |
| 324 | else: |
| 325 | ds_utils.set_random_seed(new_seed) |
| 326 | |
| 327 | inputs = layer(inputs) |
| 328 | return inputs |
| 329 | |
| 330 | return exec_func |
| 331 | |
| 332 | if self.activation_checkpoint_interval == 0: |
| 333 | func = exec_range_func(0, len(self.forward_funcs)) |
nothing calls this directly
no outgoing calls
no test coverage detected