Skip to content

Preserve dynamic expressions across MLIR XLA boundaries - #37

Draft
stevenvar wants to merge 16 commits into
for-serving-2.20from
steven.mlir-dynamic-expression-boundaries
Draft

Preserve dynamic expressions across MLIR XLA boundaries#37
stevenvar wants to merge 16 commits into
for-serving-2.20from
steven.mlir-dynamic-expression-boundaries

Conversation

@stevenvar

@stevenvar stevenvar commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

This PR allows MLIR-only TensorFlow kernels to remain in XLA clusters when their inputs carry dynamic shape expressions.

Before entering the MLIR bridge, TensorFlow shape inference records the logical output expressions. The XLA inputs and argument descriptions are then replaced with expression-free views that keep the same physical dimensions. MLIR therefore lowers an ordinary statically shaped region. When its results return to XLA, the recorded output expressions are restored at the boundary.

Why

The previous behavior rejected every MLIR-only kernel with a dynamic input expression. Passing the expressions through MLIR itself would require broad changes to MLIR and to individual HLO inference rules.

Keeping expressions at the boundary avoids that duplication. It also leaves standard XLA dynamic dimensions disabled and does not introduce SetDimensionSize.

Design notes

  • TensorFlow shape inference remains the source of truth for logical output expressions.
  • MLIR and the generated internal HLO only see the physical static dimensions.
  • Generic MLIR-to-HLO conversion and HLO shape inference are unchanged.
  • Inputs marked as compile-time constants keep their existing handling.
  • This is a draft because operations whose computation observes a dynamic dimension as a value still need careful validation.

Tests

  • Compiles the MLIR-only ReluGrad op with two [8<A>, 4] inputs.
  • Checks that the returned XLA shape is still [8<A>, 4].
  • Checks that the expression dimension is not converted to standard bounded dynamism.
  • Checks that the generated HLO contains no SetDimensionSize instruction.

@stevenvar
stevenvar force-pushed the steven.shared-dynamic-expression-representation branch from a59545d to 6825185 Compare August 5, 2026 14:06
@stevenvar
stevenvar force-pushed the steven.mlir-dynamic-expression-boundaries branch 4 times, most recently from 6bf1bcf to 2fba66f Compare August 5, 2026 15:23
@stevenvar stevenvar changed the title Support dynamic expressions through MLIR lowering Preserve dynamic expressions across MLIR XLA boundaries Aug 5, 2026
@stevenvar
stevenvar force-pushed the steven.mlir-dynamic-expression-boundaries branch 9 times, most recently from aca1965 to 6dfb7d6 Compare August 6, 2026 09:55
@stevenvar
stevenvar force-pushed the steven.shared-dynamic-expression-representation branch 2 times, most recently from b75efc6 to 91433d1 Compare August 10, 2026 11:38
@stevenvar
stevenvar force-pushed the steven.shared-dynamic-expression-representation branch from 91433d1 to a5c0f05 Compare August 13, 2026 15:34
@stevenvar
stevenvar force-pushed the steven.shared-dynamic-expression-representation branch 2 times, most recently from c105d71 to ec896b5 Compare August 13, 2026 16:09
@stevenvar
stevenvar force-pushed the steven.shared-dynamic-expression-representation branch from ec896b5 to 9fde631 Compare August 14, 2026 08:59
@stevenvar
stevenvar force-pushed the steven.mlir-dynamic-expression-boundaries branch from 6dfb7d6 to be7c1cf Compare August 14, 2026 10:57
@stevenvar
stevenvar changed the base branch from steven.shared-dynamic-expression-representation to for-serving-2.20 August 14, 2026 10:58
@stevenvar
stevenvar force-pushed the for-serving-2.20 branch 3 times, most recently from 0846466 to 635bc63 Compare August 17, 2026 09:25
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