Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testdata files for quantized stablohlo programs #2404

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

sdasgup3
Copy link
Member

@sdasgup3 sdasgup3 commented Jun 20, 2024

Add quantized tests for the following stablehlo operations

abs
cbrt
ceil
cosine
divide
exponential
exponential_minus_one
floor
log
log_plus_one
logistic
multiply
negate
sign
sine
sqrt
subtract
tanh

A few details

A few limitations

  1. Currently we are using the Stablehlo Quantizer to generate quantized program which currently supports quantization of f32 floating point programs only. In future this case be improved.
    • Corollary: If the input test files have non-f32 based pograms, then it will be preserved unquantized in the output file. That is why we can see some of the generated files have non-quantized programs as well.
  2. While scraping the input programs from https://github.com/openxla/stablehlo/tree/main/stablehlo/tests/interpret or https://github.com/openxla/stablehlo/tree/main/stablehlo/testdata we choose only those programs which tests single stablehlo operations. This what the testdata-generator tool currently supports, but in very near future we can expect the tool to work on input test files with mutiple operations being tested.

Keep an eye on more quantized tests to be populated!

@sdasgup3 sdasgup3 removed the request for review from abhigunj June 20, 2024 20:38
@sdasgup3 sdasgup3 merged commit 57d16b1 into openxla:main Jun 20, 2024
10 checks passed
sdasgup3 added a commit that referenced this pull request Jul 23, 2024
Check dialect is an auxiliary dialect used in StableHLO repository for
validation of StableHLO program evaluation. Currently there is no
cleaner way to parse a module containing check dialect operations or to
create them. One way to go around this is to textually modify the check
dialect ops to normalize them to generic MLIR text and allow
unregistered dialect to pars that text. However, this PR provodes a
cleaner way to process check dialect.

This PR prepares for open sourcing some of the utilities, leveraged in
#2404, for auto-generating
testdata formatted test files.
sdasgup3 added a commit that referenced this pull request Aug 20, 2024
This PR exposes some key APIs to auto-generate StableHLO test programs
in testdata format, which are leveraged in
#2404.


## Proposed API

```python
def testdata_generator(
    module: ir.Module, args: Sequence[np.ndarray] = []
) -> ir.Module:
```

-   `module`: The StableHLO module to generate test data for.

- `args`: (Optional) A sequence of NumPy arrays representing input
values for
the module. If not provided, the function will attempt to extract input
    values from the module itself.

## Example

```python
# Input (module_str)
module_str = """
module {
  func.func @main(%arg0: tensor<2xf32>, %arg1: tensor<2xf32>) -> tensor<2xf32> {
    %0 = stablehlo.add %arg0, %arg1 : tensor<2xf32>
    return %0 : tensor<2xf32>
  }
}
"""

# Input (args)
args = [
    np.array([1.0, 2.0], dtype=np.float32),
    np.array([3.0, 4.0], dtype=np.float32)
]

# Generate test data
module_output = testdata_generator(module, args)

# Output (module_output)
module_output_str = """
module {
  func.func @main() -> tensor<i1> {
    %cst = stablehlo.constant dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>
    %cst_0 = stablehlo.constant dense<[3.000000e+00, 4.000000e+00]> : tensor<2xf32>
    %cst_1 = stablehlo.constant dense<[4.000000e+00, 6.000000e+00]> : tensor<2xf32>
    %0 = stablehlo.add %cst, %cst_0 : tensor<2xf32>
    %1 = stablehlo.custom_call @check.eq(%cst_1, %0) : (tensor<2xf32>, tensor<2xf32>) -> tensor<i1>
    return %1 : tensor<i1>
  }
}
"""
```

Note to reviewer: The current PR is based on
#2445, so please review that
first.
abhigunj added a commit that referenced this pull request Aug 23, 2024
abhigunj added a commit that referenced this pull request Aug 23, 2024
abhigunj added a commit that referenced this pull request Aug 23, 2024
refer parent PR #2404

for 6 test files  zero_point of DotGeneralOp `rhs` is not 0.
abhigunj added a commit that referenced this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants