class_docstr: Change the shape of the tensor from N-D to 3D
class_docstr_tok: ["Change","the","shape","of","the","tensor","from","N-D","to","3D"]
code: def apply(self, shape_mapping: Dict[str, List[int]]):
      mapping_copy = shape_mapping.copy()
      self.batch_dims_before_view = list(mapping_copy["input"][:-2])
  
      # get shapes
      input_shape = shape_mapping["input"]
      other_shape = shape_mapping["other"]
  
      # view to 3d tensor
      assert len(input_shape) >= 3 and len(other_shape) >= 3
      input_shape = [
          reduce(operator.mul, input_shape[:-2])
      ] + input_shape[-2:]
      other_shape = [
          reduce(operator.mul, other_shape[:-2])
      ] + other_shape[-2:]
      output_shape = input_shape[:2] + other_shape[2:]
      mapping_copy["input"] = input_shape
      mapping_copy["other"] = other_shape
      mapping_copy["output"] = output_shape
      return mapping_copy
  
imports: import operator
  from abc import ABC, abstractmethod
  from copy import deepcopy
  from enum import Enum
  from functools import reduce
  from typing import Dict, List, Union
  import torch
  from colossalai.auto_parallel.tensor_shard.utils.broadcast import BroadcastType, get_broadcast_dim_info, get_broadcast_shape
  from colossalai.tensor.sharding_spec import ShardingSpecException
  from ..sharding_strategy import OperationData, OperationDataType, ShardingStrategy
  from ..utils import recover_sharding_spec_for_broadcast_shape
  from .node_handler import MetaInfoNodeHandler
  from .registry import operator_registry
  from .strategy import BatchedMatMulStrategyGenerator, DotProductStrategyGenerator, LinearProjectionStrategyGenerator, MatVecStrategyGenerator, StrategyGenerator
label_desc: Use image node_id 2 for calling the Viewer obj's underlying member method code with example usage: obj.apply(shape_mapping) and returns: mapping_copy