openxla / stablehlo

Backward compatible ML compute opset inspired by HLO/MHLO
Apache License 2.0
415 stars 113 forks source link

Create a public C++ API for StableHLO #30

Open joker-eph opened 2 years ago

joker-eph commented 2 years ago

At the moment, other than the ODS auto-generated builder, there is no API to create a StableHLO graph from C++. This means that a change in MLIR can change the C++ API.

Also there is no "graph" container defined yet.

GleasonK commented 2 years ago

Eugene and I are currently looking into compatibility guarantees in (#4). This includes API guarantees which should unblock this ticket along with its related tickets (#31, #32).

GleasonK commented 2 years ago

No progress on this issue in the past week. Same rationale as last week, stable APIs are lower priority than a stable serialization format. Will work with Eugene on prioritizing this issue and coming up with a rough timeline.

jpienaar commented 1 year ago

This and the Python API issue both came up this week in > 3 different venues.

lsy323 commented 1 year ago

Looks like there isn't C++ API that is similar to HLO builder API in xla_builder(https://github.com/openxla/xla/blob/main/xla/client/xla_builder.h). Having a similar C++ builder API should make the migration from HLO to StableHLO easier for frameworks currently emits HLO.

It seems StableHLO Python API similar to xla_builder is already there. StableHLO Python API seems like to be code-gen'ed, so I cannot find them in the source code. But here is an example usage in in JAX (https://github.com/google/jax/blob/34d5a6259f150064103fce241ff7d5b54e5ed8b0/jax/_src/prng.py#L1125)

cc @JackCaoG @miladm

janpfeifer commented 1 year ago

Also, this would be a nice path for an upgrade for those still using xla_builder.h. Notice that building a graph using xla_builder.h, there is a path to convert that to StableHLO (it used to work a few months back) -- so in a way xla_builder.h is already a StableHLO C++ API of sorts, but it's convoluted, and I'm not sure which ops and functionality are missing in xla_builder.h.