Skip to content

Support symbolic -1 output dimensions in reshape #249

@jacobhinkle

Description

@jacobhinkle

As of #24 and #215 there is support for scheduling and running Fusions containing reshape ops whose output shape is a list of Scalars. These scalars are typically the extents of the corresponding reshaped dimensions. If -1 is passed, it should be replaced by an integer that preserves the number of elements in the input. Currently, we are able to handle dynamic values of -1 during concretization, but scheduling fails while getting heuristics.

  std::unique_ptr<Fusion> fusion_ptr = std::make_unique<Fusion>();
  Fusion& fusion = *fusion_ptr.get();
  FusionGuard fg(&fusion);

  TensorView* tv0 = makeSymbolicTensor(4);
  fusion.addInput(tv0);

  auto tv1 = add(tv0, tv0);
  auto tv2 = reshape(tv1, {tv1->axis(0)->extent(), tv1->axis(2)->extent(), IrBuilder::create<Int>(-1)});
  auto tv3 = add(tv2, tv2);
  fusion.addOutput(tv3);

  FusionExecutorCache fusion_executor_cache(std::move(fusion_ptr));


  auto options = at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
  at::Tensor at_x = at::randn({2,3,4,5}, options);

  auto outputs = fusion_executor_cache.runFusionWithInputs({at_x});
//C++ exception with description "extent_int >= 0 INTERNAL ASSERT FAILED at 
// "/opt/pytorch/nvfuser/csrc/scheduler/registry.cpp":807, please report a bug to PyTorch. 
// Unexpected size of axis: -1                                                                                                  
// Exception raised from getTensorIndexType at
// /opt/pytorch/nvfuser/csrc/scheduler/registry.cpp:807

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions