Skip to content

Commit c42d348

Browse files
hawkinsptensorflower-gardener
authored andcommitted
Migrate StableHLO Python extension to nanobind.
I'm working towards moving the MLIR Python core code to use nanobind instead of pybind11: * llvm/llvm-project#117922, which was merged recently, allows downstream Python dialect extensions to be defined using either pybind11 or nanobind. * llvm/llvm-project#118583 is a PR in review that ports the Python core code to use nanobind instead of pybind11. This PR migrates StableHLO and related dialects to use nanobind rather than pybind11, with the goal of migrating JAX away from pybind11. PiperOrigin-RevId: 705197067
1 parent 552eb3e commit c42d348

File tree

4 files changed

+1725
-3
lines changed

4 files changed

+1725
-3
lines changed

tensorflow/compiler/mlir/stablehlo/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ tsl_pybind_extension(
3838
"//tensorflow/tools/pip_package:__subpackages__",
3939
],
4040
deps = [
41+
"//third_party/nanobind",
4142
"//third_party/python_runtime:headers",
4243
"@llvm-project//llvm:Support",
4344
"@llvm-project//mlir:CAPIIR",
4445
"@llvm-project//mlir:IR",
4546
"@llvm-project//mlir:MLIRBindingsPythonHeadersAndDeps",
46-
"@pybind11",
4747
"@stablehlo//:stablehlo_capi",
4848
],
4949
)

tensorflow/compiler/mlir/stablehlo/stablehlo.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#include "pybind11/pybind11.h" // from @pybind11
16+
#include "third_party/nanobind/include/nanobind/nanobind.h"
1717
#include "stablehlo/integrations/python/StablehloApi.h" // from @stablehlo
1818

1919
namespace mlir {
2020
namespace stablehlo {
2121

22-
PYBIND11_MODULE(stablehlo_extension, m) { mlir::stablehlo::AddPortableApi(m); }
22+
NB_MODULE(stablehlo_extension, m) { mlir::stablehlo::AddPortableApi(m); }
2323

2424
} // namespace stablehlo
2525
} // namespace mlir

0 commit comments

Comments
 (0)