EnzymeAD / EnzymeAD/Enzyme-JAX

Batched AD crash for a simple MLP

Open
#1,469 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
MLIR
Stars
131
Forks
53
Avg merge
1d 10h
Merged PRs (30d)
193

Description

```mlir
module @reactant_batched... attributes {mhlo.num_partitions = 1 : i64, mhlo.num_replicas = 1 : i64} {
func.func private @neuralnetwork(%arg0: tensor<2x4xf32> {enzymexla.memory_effects = []}, %arg1: tensor<4xf32> {enzymexla.memory_effects = []}, %arg2: tensor<4x3xf32> {enzymexla.memory_effects = []}, %arg3: tensor<3xf32> {enzymexla.memory_effects = []}, %arg4: tensor<4x2xf32> {enzymexla.memory_effects = []}) -> (tensor<4x3xf32>, tensor<2x4xf32>, tensor<4xf32>, tensor<4x3xf32>, tensor<3xf32>, tensor<4x2xf32>) attributes {enzymexla.memory_effects = []} {
%0 = stablehlo.dot_general %arg0, %arg4, contracting_dims = [0] x [1], precision = [DEFAULT, DEFAULT] : (tensor<2x4xf32>, tensor<4x2xf32>) -> tensor<4x4xf32>
%1 = stablehlo.broadcast_in_dim %arg1, dims = [0] : (tensor<4xf32>) -> tensor<4x4xf32>
%2 = stablehlo.add %0, %1 : tensor<4x4xf32>
%3 = stablehlo.tanh %2 : tensor<4x4xf32>
%4 = stablehlo.broadcast_in_dim %arg3, dims = [0] : (tensor<3xf32>) -> tensor<3x4xf32>
%5 = stablehlo.dot_general %arg2, %3, contracting_dims = [0] x [0], precision = [DEFAULT, DEFAULT] : (tensor<4x3xf32>, tensor<4x4xf32>) -> tensor<3x4xf32>
%6 = stablehlo.add %5, %4 : tensor<3x4xf32>
%7 = stablehlo.transpose %6, dims = [1, 0] : (tensor<3x4xf32>) -> tensor<4x3xf32>
return %7, %arg0, %arg1, %arg2, %arg3, %arg4 : tensor<4x3xf32>, tensor<2x4xf32>, tensor<4xf32>, tensor<4x3xf32>, tensor<3xf32>, tensor<4x2xf32>
}
func.func @main(%arg0: tensor<2x4xf32> {enzymexla.memory_effects = ["read", "write", "allocate", "free"], tf.aliasing_output = 1 : i32}, %arg1: tensor<4xf32> {enzymexla.memory_effects = ["read", "write", "allocate", "free"], tf.aliasing_output = 2 : i32}, %arg2: tensor<4x3xf32> {enzymexla.memory_effects = ["read", "write", "allocate", "free"], tf.aliasing_output = 3 : i32}, %arg3: tensor<3xf32> {enzymexla.memory_effects = ["read", "write", "allocate", "free"], tf.aliasing_output = 4 : i32}, %arg4: tensor<4x2xf32> {enzymexla.memory_effects = ["read", "write", "allocate", "free"]}) -> (tensor<4x2x3xf32>, tensor<2x4xf32>, tensor<4xf32>, tensor<4x3xf32>, tensor<3xf32>) attributes {enzymexla.memory_effects = ["read", "write", "allocate", "free"]} {
%cst = stablehlo.constant dense<[[[1.000000e+00, 0.000000e+00], [1.000000e+00, 0.000000e+00], [1.000000e+00, 0.000000e+00], [1.000000e+00, 0.000000e+00]], [[0.000000e+00, 1.000000e+00], [0.000000e+00, 1.000000e+00], [0.000000e+00, 1.000000e+00], [0.000000e+00, 1.000000e+00]]]> : tensor<2x4x2xf32>
%0:5 = enzyme.fwddiff @neuralnetwork(%arg0, %arg1, %arg2, %arg3, %arg4, %cst) {activity = [#enzyme, #enzyme, #enzyme, #enzyme, #enzyme], ret_activity = [#enzyme, #enzyme, #enzyme, #enzyme, #enzyme, #enzyme], width = 2 : i64} : (tensor<2x4xf32>, tensor<4xf32>, tensor<4x3xf32>, tensor<3xf32>, tensor<4x2xf32>, tensor<2x4x2xf32>) -> (tensor<2x4x3xf32>, tensor<2x4xf32>, tensor<4xf32>, tensor<4x3xf32>, tensor<3xf32>)
%1 = stablehlo.slice %0#0 [1:2, 0:4, 0:3] : (tensor<2x4x3xf32>) -> tensor<1x4x3xf32>
%2 = stablehlo.transpose %1, dims = [2, 1, 0] : (tensor<1x4x3xf32>) -> tensor<3x4x1xf32>
%3 = stablehlo.slice %0#0 [0:1, 0:4, 0:3] : (tensor<2x4x3xf32>) -> tensor<1x4x3xf32>
%4 = stablehlo.transpose %3, dims = [2, 1, 0] : (tensor<1x4x3xf32>) -> tensor<3x4x1xf32>
%5 = stablehlo.reshape %4 : (tensor<3x4x1xf32>) -> tensor<3x1x4xf32>
%6 = stablehlo.reshape %2 : (tensor<3x4x1xf32>) -> tensor<3x1x4xf32>
%7 = stablehlo.concatenate %5, %6, dim = 1 : (tensor<3x1x4xf32>, tensor<3x1x4xf32>) -> tensor<3x2x4xf32>
%8 = stablehlo.transpose %7, dims = [2, 1, 0] : (tensor<3x2x4xf32>) -> tensor<4x2x3xf32>
return %8, %0#1, %0#2, %0#3, %0#4 : tensor<4x2x3xf32>, tensor<2x4xf32>, tensor<4xf32>, tensor<4x3xf32>, tensor<3xf32>
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Use the standalone MLIR module in the issue as the reproducer and determine which Enzyme-JAX automatic-differentiation pipeline stage crashes during the batched fwddiff call. Compare the batched MLP case with a non-batched case before tracing the responsible compiler subsystem. Done means the supplied reproducer completes without crashing and its derivative result is validated.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, machine-learning
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.