class_docstr: Generates a pair of :class:`Checkpoint` and :class:`Recompute`.
class_docstr_tok: ["Generates","a","pair","of",":","class",":","`","Checkpoint","`","and",":","class",":","`","Recompute","`","."]
docstr: Returns a batch applied by :class:`Checkpoint`.
docstr_tok: ["Returns","a","batch","applied","by",":","class",":","`","Checkpoint","`","."]
code: def checkpoint(self) -> Batch:
      """Returns a batch applied by :class:`Checkpoint`."""
      input_atomic = self.batch.atomic
      input = tuple(self.batch)
  
      # Use a phony which requires grad to ensure that Checkpoint can be
      # tracked by the autograd engine even when none of the input tensors
      # require grad.
      phony = get_phony(self.batch[0].device, requires_grad=True)
  
      output = Checkpoint.apply(
          phony,
          self.recomputed,
          self.rng_states,
          self.function,
          input_atomic,
          *input,
      )
  
      # Gradients are only supported for float Tensors.
      if isinstance(output, tuple):
          output = tuple(
              [
                  x if x.is_floating_point() else x.detach()
                  for x in output
              ]
          )
  
      return Batch(output, self.batch.index)
  
imports: from collections import deque
  from contextlib import contextmanager
  import threading
  from typing import TYPE_CHECKING, Deque, Generator, List, Optional, Tuple, Union
  import torch
  from torch import ByteTensor, Tensor
  import torch.autograd
  from .dependency import fork, join
  from .microbatch import Batch
  from .phony import get_phony
label_desc: Use image node_id 2 for calling the Checkpointing obj's underlying member method code with example usage: obj.checkpoint() and returns: Batch