Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

[RFC] Common Benchmark Suite - #77

Merged
GMNGeoffrey merged 18 commits into
openxla:mainfrom
pzread:rfc-common-benchmark-suite
May 31, 2023
Merged

GMNGeoffrey merged 18 commits into
openxla:mainfrom
pzread:rfc-common-benchmark-suite

Conversation

@pzread

@pzread pzread commented May 11, 2023

Copy link
Copy Markdown
Contributor

This is the subsequent RFC of the high-level benchmarking strategy for OpenXLA #75 (in review).

It proposes to create a benchmark suite to fulfill the benchmarking requirements in the strategy.

The temporary links to the high-level strategy RFC will be updated once #75 is merged.

@pzread
pzread force-pushed the rfc-common-benchmark-suite branch 5 times, most recently from ab288ec to 9dea7b1 Compare May 11, 2023 01:40
@pzread
pzread marked this pull request as ready for review May 11, 2023 01:40
@pzread

pzread commented May 11, 2023 •

Copy link
Copy Markdown
Contributor Author

Will someone be able to help add suitable reviewers? 🙂 (maybe include @jpienaar @GMNGeoffrey @julianwa @mariewhite @reichlfl).

@pzread

pzread commented May 23, 2023 •

Copy link
Copy Markdown
Contributor Author

Kindly ping for visibility : ) Also tag @powderluv who might be interested

@joker-eph

Copy link
Copy Markdown
Contributor

Nice work, looking forward to this! :)

I just left a few nit comments mostly, thanks.

Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
classes only describe the compiler-agnostic parts of a benchmark, which include:

* Model class to define model metadata and the artifacts (e.g., exported
StableHLO of the model, input data, and expected output data).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it is implicit here but "expected output data" may come with a defined "numerical tolerance"? It'll be interesting to see how to express this: maybe it can be a python function that takes the result and the reference and perform any kind of comparison deemed suitable for this model, returning a pass/fail signal?

@pzread pzread May 25, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I think when we provide the expected output, it should also include the information about how to compare and the tolerance. The benchmark suite will provide the python function to take expected output, tolerance, and model output and return the comparison results.

I updated the text here and in the code example to demonstrate how it works.

Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
* Model class to define model metadata and the artifacts (e.g., exported
StableHLO of the model, input data, and expected output data).
* Device class to define device specifications to run benchmarks (e.g., GCP VM
models).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we restricting this iteration to single device models? Single node? Otherwise what kind of topology are we thinking of?
(caveat: I'm not sure how to do multi-node without a framework, so a model defined with a "stable HLO export" may not be able to express this?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we focus on the single device models in the initial iteration in our benchmark strategy RFC (We mentioned that for GPU benchmarks but not for CPU. I posted a question for clarification there). I can see the DeviceSpec in the example below can be extended to describe a multi-node topology, but it's a little bit hard to design before knowing what kinds of multi-node benchmarks we want.

The model artifact will also include its framework's implementation (which is described in the example). Updated the text here to clarify.

Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
# E.g., c2-standard-16
device_model: str
# E.g., linux-x86_64
device_architecture: str

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With accelerators, the concept of "architecture" is a bit blurry to me: is this only about the host? Is it important to be able to select the right precompiled image of the framework to deploy? (otherwise I'd think that pip or cmake or the local system would "do the right thing" anyway)

@pzread pzread May 24, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, there is confusion here. There should be host_environment and accelerator_architecture to describe the architecture of the accelerator and the host machine connects to the accelerator.

In some cases we want to pre-compile the runtime, tools, and models on separate build machines in workflow and deploy them to the benchmark machines (described by DeviceSpec). For example, cross-compiling and running benchmarks on mobile phones. So build machines need to know the benchmark environments from the benchmark definitions. It also makes sense to run ML compilers on cheaper build machines instead of compiling models on the expensive benchmark machines when possible.

From IREE's experience, to compile the runtime and model, the build machines need to know two things about the benchmark machine: the host environment to run the runtime and the accelerator architecture to optimize for.

I made some changes to include fields to describe both host and accelerator on a benchmark machine.

# E.g., linux-x86_64
device_architecture: str

class InferenceBenchmark:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why an "inference" benchmarks is specific here: what in the metadata would be different for a training benchmark?

@pzread pzread May 24, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually haven't designed training benchmarks yet but my guess is that there will be training parameters and stopping criteria (by reading the MLPerf traning)

In general I think it's a good idea to keep different types of benchmarks separated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd kind of like us to avoid baking too much ML stuff into the benchmarking that isn't really the key differentiator. I know we are building things for ML, but I find that sometimes the ML-isms obscure things. So in this case I think the salient point is that it's a single call into a model with a single expected response. It doesn't seem to, for instance, support benchmarking a series of calls into the model. Should it? I think a more descriptive name might fall out of this like SingleCallBenchmark

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave the specifics of how the benchmark is called to the implementation. Workloads are so diverse that I don't think the metadata should be imposing how it should execute.

The simplest inference workload is single-shot. However, many inference workloads need multiple calls to eventually get the answer e.g. any model that incorporates time like audio and video processing. Some workloads use multiple models and multiple calls e.g. Stable Diffusion uses 3 models and calls one of the models multiple times. Training workloads would be more complex with many config options.

I'm in favor of making this class more generic like BenchmarkDefinition or BenchmarkInstance. The infra is just concerned about feeding the input data in, checking the outputs are correct, and running it on the specified hardware. Everything else is a black box. We may even want a higher abstraction to a Model like a Workload that could have one or more Models or Microbenchmarks, or be completely up to the implementer (for shiny new things).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my naive thought, as we accept the Python module in Model, the multiple-model workload can be represented as a single model composed of multiple models with Python code to describe the data flow between those underlying models. I guess we can rename Model to Workload to give it a more general semantic.

IMO it's something we haven't done before and we should add some those models to the benchmark suite as early as possible to clear out any design issue.

@pzread
pzread force-pushed the rfc-common-benchmark-suite branch from 03b1b3f to 0a1618a Compare May 24, 2023 23:09

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of comments, but overall this LG. Nice work on this :-)

[OpenXLA Benchmarking Strategy](https://github.com/openxla/community/pull/75)
outlines a benchmark suite for comparative and regression benchmarking for the
OpenXLA and third-party compilers that the OpenXLA community is interested in.
It is part of the **OOBI** (OpenXLA OSS Benchmarking Infrastructure).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think someone mentioned this elsewhere, but our naming here makes less sense in an OSS context. Like of course it's OSS, it's an OSS project :-) Added to that, OSS is an initialism already, so having it within the OOBI initialism is a bit weird. So as much as I like these little guys:

oobi_hand_puppets

I think we should probably go with just "OBI"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have internal OpenXLA benchmarking infrastructure, so I believe we needed to make that distinction. OOBI and OIBI :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally we need to make that distinction, but from the perspective of the OSS OpenXLA project it doesn't make much sense

Comment thread rfcs/20230510-common-benchmark-suite.md Resolved
Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
# For the exported model, it's the URL to fetch the model.
# For the model implementation with framework, it's the file path to import
# the Python model module with `importlib.import_module`. This prevents
# pulling in unnecessary dependencies from those modules.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for thinking about dependency bloat from the beginning. I was worried that we'd end up importing the world for everything.

Comment thread rfcs/20230510-common-benchmark-suite.md Resolved
Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
class Model:
"""Model to benchmark."""
name: str
# For the exported model, it's the URL to fetch the model.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should specify that this needs to be a stable URL, and should almost certainly be a mirror we control. I'm also slightly tempted to include an artifact digest as well to enforce that a bit, though I suspect some people will get annoyed about that. We could just use content-adressable storage for the models, but I know people also get grumpy about opaque names for things :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Briefly mentioned in the comments. Totally agree to include digest in the definitions for verification.

Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
hlo_remote_path = common_benchmark.model.source_artifacts[
ModelFormat.HLO_DUMP
]
hlo_path = download_file(hlo_remote_path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So say I wanted to make it so my benchmarks use local files and make fetching over the network an out-of-band process (as we discussed recently). Where would that tie in? Is that just a different implementation of this bit? I think I see how this would work because I know something about our current benchmarking, but just from reading this, I'd think we were deeply coupling benchmarks to network access and be somewhat alarmed. Assuming my alarm is unwarranted and you're imagining some kind of config export thingy, can you maybe just add a note of how this sort of thing would be possible without network access deep in the stack?

IMO storing hashes would actually help with this. You could tell the model or input definition "hey I know you want to get this at this URL, but here's a file with the same hash. Use this instead" (except I wouldn't want implicit network access that you then override, so I don't think it should work quite like that).

@pzread pzread May 30, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Add a few words to explain how it can be done before the benchmark loop.

I'm trying to give a concise example here so that's why I put all the steps in this function to demo the full workflow.

Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
Comment on lines +164 to +165
input_data: List[ModelTestData]
expected_output: List[ModelTestData]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would framework-level benchmarks have input and output data here or in the Python source? I actually wonder whether framework benchmarks should be a separate category here? I'm unsure though

@pzread pzread May 30, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with @mariecwhite. In the current use cases, framework-level benchmarks also use numpy tensors as the input/otput (they might convert numpy into framework's tensors in the model scripts). But they might use different data layouts (e.g. NCHW vs. NHWC). Their derived models usually use the same data layout as the source model. Currently TENSFORFLOW_NUMPY, PYTORCH_NUMPY, JAX_NUMPY should be enough, non-numpy formats can be added in the future, if we have other kinds of framework implementations.

I think each model derivation (TF/PyTorch framework implementation, exported StableHLO models...) should describe what kinds of data format they accept/output. In ModelTestData we provide the preprocessed data for each format. More kinds of the data format can also be included in the future, but we likely want to stick to only supporting the data formats of the "source framework model implementations", to avoid exploding the supported formats.

For special cases (e.g. exported models with special data layout transform), they can transform the test data from the source model layout during benchmarking (and they should know how to transform as we provide the data format in the benchmark definition). We can also add the preprocessed data to the ModelTestData, but only when necessary (e.g. We decide to widely support that model format).

Comment on lines +219 to +339
class IreeInferenceBenchmark:
"""Describes an IREE inference benchmark."""
# Reference to the base benchmark.
base_benchmark: benchmark_framework.InferenceBenchmark
module_generation_config: IreeModuleGenerationConfig
# IREE runtime driver.
runtime_driver: str
extra_runtime_flags: List[str] = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, so we're using composition rather than inheritance here? Do we expect the IreeInferenceBenchmark (IREEInferenceBenchmark?) to satisfy some interface?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a one-to-many relation (IREE might have multiple benchamrks with different IREE settings on a single common InferenceBenchmark), composition should do a better job than inheritance here (we will need to populate all fields in InferenceBenchmark again if we use inheritance).

For the benchmark interface to satisfy, we might have something like that. But I try not to overwhelm the RFC with too many details.

Comment thread rfcs/20230510-common-benchmark-suite.md Outdated
Comment on lines +269 to +270
ML frameworks, the extra `requirements.txt` will be stored with the benchmark
definitions and pin the package versions. It is not necessary to install it if

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of the benchmark definition if it's for a source file?

@pzread pzread May 30, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can track the changes on requirements.txt together with the model implementation code.

Assume we have a way to track the version of framework model implementation (the hash source codes or the git commit hash of the code directory), as requirements.txt stays with the code, any changes on it will also be reflected in that version.

Comment on lines +305 to +419
This will give a simple start and it won't be hard to spin out the comparative
benchmark workflow into a separate repository if needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SGTM

@stellaraccident
stellaraccident self-requested a review May 26, 2023 03:08

@stellaraccident stellaraccident left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it has support. I propose landing and noting any ongoing comments or future followups in a section at the bottom, if applicable.

@pzread
pzread force-pushed the rfc-common-benchmark-suite branch from d4b5ae2 to ed0192d Compare May 30, 2023 19:14
@pzread
pzread force-pushed the rfc-common-benchmark-suite branch from f7bf87b to 174abdc Compare May 30, 2023 22:38
@pzread

pzread commented May 31, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for all the reviews and I think we don't have a major objection to this idea 🙂 I added a section in the bottom to list the remaining open questions and will track them in the new benchmark repository.

@pzread

pzread commented May 31, 2023 •

Copy link
Copy Markdown
Contributor Author

Hi @theadactyl Would you be able to help merge this RFC and create the repository openxla-benchmark as the next step?

@GMNGeoffrey

Copy link
Copy Markdown
Contributor

I can merge. Will look into the new repo

@GMNGeoffrey
GMNGeoffrey merged commit 6dc26f0 into openxla:main May 31, 2023
@jpienaar jpienaar mentioned this pull request Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants