class_docstr: Custom Backpropagation function to allow (A) flusing memory in foward
  and (B) activation recomputation reversibly in backward for gradient calculation.
  
  Inspired by https://github.com/RobinBruegger/RevTorch/blob/master/revtorch/revtorch.py
class_docstr_tok: ["Custom","Backpropagation","function","to","allow","(","A",")","flusing","memory","in","foward","and","(","B",")","activation","recomputation","reversibly","in","backward","for","gradient","calculation",".","Inspired","by","https",":","\/\/github.com\/RobinBruegger\/RevTorch\/blob\/master\/revtorch\/revtorch.py"]
docstr: Reversible Forward pass. Any intermediate activations from `buffer_layers` are
  cached in ctx for forward pass. This is not necessary for standard usecases.
  Each reversible layer implements its own forward pass logic.
docstr_tok: ["Reversible","Forward","pass",".","Any","intermediate","activations","from","`","buffer_layers","`","are","cached","in","ctx","for","forward","pass",".","This","is","not","necessary","for","standard","usecases",".","Each","reversible","layer","implements","its","own","forward","pass","logic","."]
code: def forward(
      ctx,
      x,
      layers,
      buffer_layers,  # List of layer ids for int activation to buffer
  ):
      """
      Reversible Forward pass. Any intermediate activations from `buffer_layers` are
      cached in ctx for forward pass. This is not necessary for standard usecases.
      Each reversible layer implements its own forward pass logic.
      """
      buffer_layers.sort()
  
      X_1, X_2 = torch.chunk(x, 2, dim=-1)
  
      intermediate = []
  
      for layer in layers:
          X_1, X_2 = layer(X_1, X_2)
  
          if layer.layer_id in buffer_layers:
              intermediate.extend([X_1.detach(), X_2.detach()])
  
      if len(buffer_layers) == 0:
          all_tensors = [X_1.detach(), X_2.detach()]
      else:
          intermediate = [
              torch.LongTensor(buffer_layers),
              *intermediate,
          ]
          all_tensors = [X_1.detach(), X_2.detach(), *intermediate]
  
      ctx.save_for_backward(*all_tensors)
      ctx.layers = layers
  
      return torch.cat([X_1, X_2], dim=-1)
  
imports: import sys
  from functools import partial
  import torch
  from torch import nn
  from torch.autograd import Function
  from slowfast.models.attention import MultiScaleAttention, attention_pool
  from slowfast.models.common import Mlp, TwoStreamFusion, drop_path
  from slowfast.models.utils import round_width
label_desc: Use image node_id 1 for calling the RevBackProp obj's underlying member method code with example usage: obj.forward(ctx, x, layers, buffer_layers) and returns: torch