class_docstr: Copies tensors on specific streams.
class_docstr_tok: ["Copies","tensors","on","specific","streams","."]
code: def forward(
      ctx: Context,
      prev_stream: AbstractStream,
      next_stream: AbstractStream,
      *input,
  ) -> Tensors:
      ctx.prev_stream = prev_stream
      ctx.next_stream = next_stream
  
      output = []
      output_stream = current_stream(get_device(next_stream))
  
      with use_stream(prev_stream), use_stream(next_stream):
          for x in input:
              if torch.is_tensor(x):
                  y = x.to(get_device(next_stream), non_blocking=True)
                  output.append(y)
  
                  # 'prev_stream' is not where 'x' has been allocated.
                  record_stream(x, prev_stream)
                  # 'y' has been allocated on 'next_stream'.
                  # It might be used on the current stream captured as 'output_stream'.
                  record_stream(y, output_stream)
              else:
                  output.append(x)
  
      return tuple(output)
  
file_path: pytorch/torch/distributed/pipeline/sync/copy.py
imports: from collections import deque
  from typing import Deque, List, Optional, Tuple, Sequence
  import torch
  from torch import Tensor
  from .stream import AbstractStream, current_stream, get_device, record_stream, use_stream, wait_stream
label_desc: Use image node_id 1 for calling the Copy obj's underlying member method code with example usage: obj.forward(ctx, prev_stream, next_stream) and returns: tuple