torch/csrc/jit/passes/to_batch.cpp
// clone prim::ListConstruct to new graph
clone prim::ListConstruct to new graph
clone prim :: ListConstruct to new graph
void ToBatch::visitListConstruct(Node* n, Block* block, Block* res_block){
  auto res_graph = res_block->owningGraph();
  if(n->inputs()[0]->type() == DynamicType::get()){  
    std::vector<Value*> inputs;
    for(Value* input: n->inputs()) {
      auto res = batch_map.at(input);
      inputs.insert(inputs.end(), res.begin(), res.end());
    }
    batch_map[n->output()] = inputs;
  }
  else {  
    for(Value* input : n->inputs()) {
      if(rn_env.find(input) == rn_env.end()){
        rn_env[input] = batch_map.at(input)[0];
      }
    }
    auto* r_node = res_graph->createClone(n, rn_fn);
    r_node->setStage(n->stage());
    res_block->appendNode(r_node);
    auto to_tensor_node = res_graph->create(Symbol::fromQualString("aten::_list_to_tensor"));
    to_tensor_node->setStage(n->stage());
    to_tensor_node->addInput(r_node->output());
    res_block->appendNode(to_tensor_node);
    rn_env[n->output()] = to_tensor_node->output();
  }
}
void ToBatch :: visitListConstruct ( Node * n , Block * block , Block * res_block ) { auto res_graph = res_block -> owningGraph ( ) ; if ( n -> inputs ( ) [ 0 ] -> type ( ) == DynamicType :: get ( ) ) { std :: vector < Value * > inputs ; for ( Value * input : n -> inputs ( ) ) { auto res = batch_map . at ( input ) ; inputs . insert ( inputs . end ( ) , res . begin ( ) , res . end ( ) ) ; } batch_map [ n -> output ( ) ] = inputs ; } else { for ( Value * input : n -> inputs ( ) ) { if ( rn_env . find ( input ) == rn_env . end ( ) ) { rn_env [ input ] = batch_map . at ( input ) [ 0 ] ; } } auto * r_node = res_graph -> createClone ( n , rn_fn ) ; r_node -> setStage ( n -> stage ( ) ) ; res_block -> appendNode ( r_node ) ; auto to_tensor_node = res_graph -> create ( Symbol :: fromQualString ( " " ) ) ; to_tensor_node -> setStage ( n -> stage ( ) ) ; to_tensor_node -> addInput ( r_node -> output ( ) ) ; res_block -> appendNode ( to_tensor_node ) ; rn_env [ n -> output ( ) ] = to_tensor_node -> output ( ) ; } }
clone prim::ListConstruct to new graph
clone prim :: ListConstruct to new graph
// TensorList: expand directly // ScalarList: transform to tensor, then transform back // transform int[] to tensor