Skip to content

Adding support for XLA Shardy#5

Merged
janpfeifer merged 32 commits intomainfrom
shardy
Nov 25, 2025
Merged

Adding support for XLA Shardy#5
janpfeifer merged 32 commits intomainfrom
shardy

Conversation

@janpfeifer
Copy link
Contributor

Added shardy types for DeviceMesh and ShardSpec.

janpfeifer and others added 30 commits November 18, 2025 09:41
This change introduces two main improvements to the `shardy` package:

1.  **`ShardSpec.ToStableHLO()` implementation:** A new method, `ToStableHLO()`, has been added to the `ShardSpec` struct. This method converts the sharding specification into the string format required by StableHLO, as detailed in the OpenXLA Shardy documentation. It correctly handles sharded, replicated, open, and sub-axis dimensions, and it ensures the output is deterministic by sorting the replicated axis names.

2.  **Enhanced `ShardSpec.Validate()`:** The `Validate()` method has been updated to include more robust checks for sharding specifications that use sub-axes. It now verifies that the `PreSize` and `Size` of a sub-axis are mathematically compatible with the total size of the corresponding mesh axis, preventing invalid sharding configurations.

A comprehensive suite of unit tests has been added in `shardspec_test.go` to validate both the new `ToStableHLO` method and the enhanced validation logic, ensuring the correctness and reliability of the implementation.
Added an alias in stablehlo in case end-users want to use it.
Added comments discouraging using other distributed (collective) mechanisms other than Shardy.
This change introduces the ability to add attributes to function inputs and outputs in the `stablehlo.Builder`. This is essential for generating StableHLO modules with XLA Shardy annotations.

Key changes:
- The `Value` struct now includes an `Attributes` map.
- `Function.Write` has been updated to serialize these attributes for both inputs and outputs.
- The attribute writing logic has been refactored into a reusable `writeAttributes` function.
- A new test case has been added to validate the generation of sharded StableHLO modules.
Improved test.
@janpfeifer janpfeifer merged commit 7d8ea06 into main Nov 25, 2025
1 check passed
@janpfeifer janpfeifer deleted the shardy branch November 25, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant