Skip to content

Commit c6c1583

Browse files
authored
Improve forward incompatibility error messaging (#2569)
Now failure to `--deserialize` a portable artifact will include: 1. The op that failed. 2. The version that the portable artifact was serialized for. 3. The current version of StableHLO. This should help debugging compat issues at a glance. Added a forward incompatible hypothetical feature `vhlo.constant_v99`, serialized for `StableHLO_v2.0.0`, which emulates a current version of StableHLO trying to parse a future operation that doesn't currently exist. ``` $ stablehlo-translate --deserialize file.mlirbc unregistered operation 'vhlo.constant_v99' found in dialect ('vhlo') that does not allow unknown operations note: in bytecode version 6 produced by: StableHLO_v2.0.0 failed to deserialize portable artifact using StableHLO_v1.7.5 ```
1 parent dd94939 commit c6c1583

16 files changed

+48
-2
lines changed

stablehlo/dialect/Serialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717

1818
#include "mlir/Bytecode/BytecodeWriter.h"
1919
#include "mlir/IR/BuiltinOps.h"
20+
#include "mlir/IR/Diagnostics.h"
21+
#include "mlir/IR/Location.h"
2022
#include "mlir/IR/MLIRContext.h"
2123
#include "mlir/IR/OwningOpRef.h"
2224
#include "mlir/Parser/Parser.h"
@@ -71,6 +73,9 @@ OwningOpRef<ModuleOp> deserializePortableArtifact(StringRef sourceStr,
7173
context->loadDialect<vhlo::VhloDialect>();
7274
auto module = parseSourceString<ModuleOp>(sourceStr, context);
7375
if (!module) {
76+
emitError(UnknownLoc::get(context))
77+
<< "failed to deserialize portable artifact using StableHLO_v"
78+
<< vhlo::Version::getCurrentVersion();
7479
return nullptr;
7580
}
7681

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: not stablehlo-translate --deserialize %s.bc --verify-diagnostics 2>&1 | FileCheck %s
2+
//
3+
// Note: This file is not valid to parse since VHLO doesn't support unknown
4+
// operations, but is kept around to help visualize the bytecode file in test.
5+
// The bytecode file should not break, as it is a portable artifact with full
6+
// backward compatibility.
7+
8+
// CHECK: error: unregistered operation 'vhlo.constant_v99' found in dialect ('vhlo') that does not allow unknown operations
9+
// CHECK: note: in bytecode version 6 produced by: StableHLO_v2.0.0
10+
// CHECK: error: failed to deserialize portable artifact using StableHLO_v{{.*}}
11+
vhlo.func_v1 @main() -> (!vhlo.tensor_v1<!vhlo.f32_v1>) {
12+
%0 = "vhlo.constant_v99"() <{value = #vhlo.tensor_v1<dense<1.000000e+00> : tensor<f32>>}> : () -> !vhlo.tensor_v1<!vhlo.f32_v1>
13+
"vhlo.return_v1"(%0) : (!vhlo.tensor_v1<!vhlo.f32_v1>) -> ()
14+
} {arg_attrs = #vhlo.array_v1<[]>, res_attrs = #vhlo.array_v1<[]>, sym_visibility = #vhlo.string_v1<"public">}
243 Bytes
Binary file not shown.

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.0_10_0.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=0.10.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v0.10.0}}
34
// expected-error @+1 {{failed to legalize operation 'vhlo.func_v1' that was explicitly marked illegal}}
45
func.func @type_fp8_E4M3B11FNUZ(%arg0: tensor<f8E4M3B11FNUZ>) -> tensor<f8E4M3B11FNUZ> {
56
%0 = stablehlo.add %arg0, %arg0 : tensor<f8E4M3B11FNUZ>

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.0_15_0.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=0.15.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v0.15.0}}
34
func.func @default_collective_broadcast(%arg0: tensor<16x8xf32>) -> tensor<16x8xf32> {
45
// expected-error @+1 {{failed to legalize operation 'vhlo.collective_broadcast_v1' that was explicitly marked illegal}}
56
%0 = "stablehlo.collective_broadcast"(%arg0) {

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.0_16_0.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=0.16.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v0.16.0}}
34
func.func @reduce_with_promotable_types(%arg0: tensor<4x4xf32>, %arg1 : tensor<f32>)
45
-> (tensor<4xf64>) {
56

@@ -17,6 +18,7 @@ func.func @reduce_with_promotable_types(%arg0: tensor<4x4xf32>, %arg1 : tensor<f
1718

1819
// -----
1920

21+
// expected-error @-3 {{failed to convert VHLO to v0.16.0}}
2022
func.func @all_reduce_with_promotable_types(%operand: tensor<f32>) -> tensor<f64> {
2123

2224
// expected-error @+1 {{failed to legalize operation 'vhlo.all_reduce_v2' that was explicitly marked illegal}}
@@ -34,6 +36,7 @@ func.func @all_reduce_with_promotable_types(%operand: tensor<f32>) -> tensor<f64
3436

3537
// -----
3638

39+
// expected-error @-3 {{failed to convert VHLO to v0.16.0}}
3740
func.func @reduce_scatter_with_promotable_types(%data: tensor<4x16xf32>) -> tensor<4x4xf64> {
3841

3942
// expected-error @+1 {{failed to legalize operation 'vhlo.reduce_scatter_v1' that was explicitly marked illegal}}
@@ -50,6 +53,7 @@ func.func @reduce_scatter_with_promotable_types(%data: tensor<4x16xf32>) -> tens
5053

5154
// -----
5255

56+
// expected-error @-3 {{failed to convert VHLO to v0.16.0}}
5357
func.func @reduce_window_with_promotable_types(%arg0: tensor<4x2xf32>,
5458
%arg1: tensor<4x2xf32>, %init0: tensor<f32>, %init1: tensor<f32>) ->
5559
(tensor<2x2xf64>, tensor<2x2xf32>) {
@@ -72,6 +76,7 @@ func.func @reduce_window_with_promotable_types(%arg0: tensor<4x2xf32>,
7276

7377
// -----
7478

79+
// expected-error @-3 {{failed to convert VHLO to v0.16.0}}
7580
func.func @scatter_with_promotable_types(%input_tensor: tensor<200x100x300xf32>,
7681
%scatter_indices: tensor<10x2xi32>, %updates: tensor<10x300xf32>) ->
7782
tensor<200x100x300xf64> {
@@ -97,6 +102,7 @@ func.func @scatter_with_promotable_types(%input_tensor: tensor<200x100x300xf32>,
97102

98103
// -----
99104

105+
// expected-error @-3 {{failed to convert VHLO to v0.16.0}}
100106
func.func @select_and_scatter_with_promotable_types(
101107
%arg0: tensor<10x24x24x64xf32>,
102108
%arg1: tensor<10x12x12x64xf32>) -> () {

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.0_17_0.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=0.17.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v0.17.0}}
34
// expected-error @+1 {{failed to legalize operation 'vhlo.func_v1' that was explicitly marked illegal}}
45
func.func @type_per_axis_quantization(%arg0: tensor<2x!quant.uniform<i8:f32:0, {34.0:16, 34.0:16}>>) -> tensor<2x!quant.uniform<i8:f32:0, {34.0:16, 34.0:16}>> {
56
%0 = stablehlo.add %arg0, %arg0 : tensor<2x!quant.uniform<i8:f32:0, {34.0:16, 34.0:16}>>

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.0_18_0.mlir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=0.18.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v0.18.0}}
34
func.func @composite(%arg0: tensor<f32>) -> tensor<f32> {
45
// expected-error @+1 {{failed to legalize operation 'vhlo.composite_v1' that was explicitly marked illegal}}
56
%0 = "stablehlo.composite"(%arg0) {

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.0_9_0.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=0.9.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v0.9.0}}
34
// expected-error @+1 {{failed to legalize operation 'vhlo.func_v1' that was explicitly marked illegal}}
45
func.func @type_fp8_E5M2FNUZ(%arg0: tensor<f8E5M2FNUZ>) -> tensor<f8E5M2FNUZ> {
56
%0 = stablehlo.add %arg0, %arg0 : tensor<f8E5M2FNUZ>
@@ -8,6 +9,7 @@ func.func @type_fp8_E5M2FNUZ(%arg0: tensor<f8E5M2FNUZ>) -> tensor<f8E5M2FNUZ> {
89

910
// -----
1011

12+
// expected-error @-3 {{failed to convert VHLO to v0.9.0}}
1113
// expected-error @+1 {{failed to legalize operation 'vhlo.func_v1' that was explicitly marked illegal}}
1214
func.func @type_fp8_E4M3FNUZ(%arg0: tensor<f8E4M3FNUZ>) -> tensor<f8E4M3FNUZ> {
1315
%0 = stablehlo.add %arg0, %arg0 : tensor<f8E4M3FNUZ>

stablehlo/tests/vhlo/vhlo_to_version_downgrade_invalid.1_1_0.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: stablehlo-opt --stablehlo-legalize-to-vhlo --vhlo-to-version='target=1.1.0' --verify-diagnostics --split-input-file %s
22

3+
// expected-error @-3 {{failed to convert VHLO to v1.1.0}}
34
// expected-error @+1 {{failed to legalize operation 'vhlo.func_v1' that was explicitly marked illegal}}
45
func.func @type_i2(%arg0: tensor<i2>) -> tensor<i2> {
56
%0 = stablehlo.add %arg0, %arg0 : tensor<i2>
@@ -8,6 +9,7 @@ func.func @type_i2(%arg0: tensor<i2>) -> tensor<i2> {
89

910
// -----
1011

12+
// expected-error @-3 {{failed to convert VHLO to v1.1.0}}
1113
// expected-error @+1 {{failed to legalize operation 'vhlo.func_v1' that was explicitly marked illegal}}
1214
func.func @type_ui2(%arg0: tensor<ui2>) -> tensor<ui2> {
1315
%0 = stablehlo.add %arg0, %arg0 : tensor<ui2>

0 commit comments

Comments
 (0)