Helper function to be used with checkpoint() Adapted from torch.utils.checkpoint:checkpoint_sequential()
(start, end)
| 346 | self.micro_offset += 1 |
| 347 | |
| 348 | def exec_range_func(start, end): |
| 349 | ''' Helper function to be used with checkpoint() |
| 350 | Adapted from torch.utils.checkpoint:checkpoint_sequential() |
| 351 | ''' |
| 352 | local_micro_offset = self.micro_offset + 1 |
| 353 | |
| 354 | def exec_func(*inputs): |
| 355 | # Single tensor inputs need to be unwrapped |
| 356 | if len(inputs) == 1: |
| 357 | inputs = inputs[0] |
| 358 | for idx, layer in enumerate(self.forward_funcs[start:end]): |
| 359 | self.curr_layer = idx + self._local_start |
| 360 | if self.seed_layers: |
| 361 | new_seed = (self.base_seed * local_micro_offset) + self.curr_layer |
| 362 | if self.seed_fn: |
| 363 | self.seed_fn(new_seed) |
| 364 | else: |
| 365 | ds_utils.set_random_seed(new_seed) |
| 366 | |
| 367 | inputs = layer(inputs) |
| 368 | return inputs |
| 369 | |
| 370 | return exec_func |
| 371 | |
| 372 | if self.activation_checkpoint_interval == 0: |
| 373 | func = exec_range_func(0, len(self.forward_funcs)) |
nothing calls this directly
no outgoing calls
no test coverage detected