stablehlo

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

StableHLO Builder

** UNDER CONSTRUCTION **: Don't use this yet!

This package is a replacement for XlaBuilder, with the following advantages:

  • XlaBuilder has become a second-class citizen so to say, within OpenXLA. And things are moving torwards the "MLIR builder" (MLIR is the generic ML Intermediary Language, of which StableHLO is an specialization/extension). So we will eventually need a newer "builder" for Gopjrt.
  • Since PJRT takes StableHLO in plain text format, we can write this entirely in Go, not requiring any extra C/C++ library build.
    • PJRT itself is a C library, but with a relatively small API surface, and for which there are prebuilt distributions available (for Jax). So we can get away without having to manage Bazel issues.
    • The goal is to eventually not require a C compiler to compile gopjrt, and instead use ebitengine/purego do dynamically load PJRT.
    • There are PJRT for different platforms. If we don't need to compile XlaBuilder for them, it makes more plausible to support them.

The disadvantages:

  • XlaBuilder provided "shape inference". So if I say Add(a, b) the XlaBuilder would tell how to broadcast a and b, and the resulting shape. When we build the StableHLO we have to re-implement this shape inference, not only for the Gopjrt users, but also because the StableHLO language requires the inputs and outputs shapes to be specified in every statement.
  • This means more maintenance: any updates in the language specification or new ops need to have their shape inference updated accordingly.

The shapeinference sub-package

The same code is also used by GoMLX SimpleGo engine (github.com/gomlx/gomlx/backends/simplego), but we didn't want to create a dependency in either direction: users of Gopjrt may not be interested in GoMLX, and users of GoMLX that don't use the XLA backend wouldn't want a dependency to Gopjrt.

So the package github.com/gomlx/gopjrt/stablehlo/shapeinference is a copy of github.com/gomlx/gomlx/backends/shapeinference, with the later being the source of truth. We'll keep both in sync, but if you need to change, please send a PR for that in GoMLX.

Documentation

Overview

Package stablehlo helps build a StableHLO program (text format) to then be JIT-compiled and executed by PJRT (github.com/gomlx/gopjrt/pjrt).

Among its features:

- Translates an API to rendered (human-readable) StableHLO text. - Shape inference: it calculates the output shapes for operations. - Written purely in Go, no C/C++ external dependencies.

It was written as a replacement for `gopjrt/xlabuilder` and attempts to keep a similar or identical interface.

See StableHLO documentation and specifications in https://openxla.org/stablehlo/spec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is used to construct a StableHLO program. See New.

func New

func New(name string) *Builder

New creates a new Builder object holding a computation graph in construction.

Add operations (ops) one by one, until you defined the desired graph, and then call the method Build, which returns a Computation. A pjrt.Client can use a Computation as input to JIT-compile and execute efficiently.

func (*Builder) Build

func (b *Builder) Build(outputs ...*Op) (*Computation, error)

Build builds the Computation with the requested operations (the outputOp and all its dependencies) or returns a non-ok status.

Note that all ops that have been enqueued will be moved to the computation being returned and will no longer be valid.

type Computation

type Computation struct {
	Name      string
	StableHLO string
}

Computation holds a rendered computation graph, that can be fed to PJRT. It is created with Builder.Build.

type Op

type Op struct {
	// contains filtered or unexported fields
}

Op holds an operation definition with all its inputs, and the result name and shape.

Directories

Path Synopsis
Package optypes defines OpType and lists the supported operations.
Package optypes defines OpType and lists the supported operations.
Package shapeinference calculates the shape resulting from operations, and validates its inputs.
Package shapeinference calculates the shape resulting from operations, and validates its inputs.
Package shapes defines Shape and DType and associated tools.
Package shapes defines Shape and DType and associated tools.
Package types is mostly a top level directory for GoMLX important types.
Package types is mostly a top level directory for GoMLX important types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL