Skip to content

Add directory for microbenchmarking - #5260

Merged
asaadaldien merged 5 commits into
mainfrom
ataei-micro_benchmarks_dir
Apr 1, 2021
Merged

asaadaldien merged 5 commits into
mainfrom
ataei-micro_benchmarks_dir

Conversation

@asaadaldien

Copy link
Copy Markdown
Contributor

This needs definitely requires more iteration for documentation, improve scripts...etc
but for now IMO we can start with something simple for reproducibility and iterate ?

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This would be good to have if you as me, but other people have a more informed opinion.

Only question though is could we just start from the linalg. operation? There are definitely advantages to using mhlo. Some ops might be lowered to a sequence of operations, but even then since we dont want anything mhlo in our core repo, starting from Linalg might be better.

MLIR_FILE_PATH=${1}
ARGS=${@:2}

adb shell 'mkdir /data/local/tmp'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we are checking this in, it needs more documentation.

@benvanik benvanik Mar 31, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah, this would probably be better as a gist - otherwise it becomes yet another thing to support. (github deleted the rest of the comment): or a big scare tag that says "only runs on ahmeds machine, ask ahmed for help" would at least set expectations :)

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 remembered that I dropped comments about scripts somewhere, but it seems gone...

We have something similar in build_tools/mako/ which is mainly for mako benchmarks. We probably can reuse some of codes from there.

https://github.com/google/iree/blob/main/build_tools/mako/compile_android_modules.py
https://github.com/google/iree/blob/main/build_tools/mako/benchmark_modules_on_android.py

They are configured in https://github.com/google/iree/blob/main/build_tools/mako/configuration.py
I think we can add MICROBENCHMARKS, I'm happy to help on that once this gets check-in.

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: "microbenchmark" is canonically one word so you can remove the underscore in the name (https://en.wiktionary.org/wiki/microbenchmark)

Only question though is could we just start from the linalg. operation?

Agreed that linalg would be nice - soon we'll be removing HLO from IREE (relegating it only to the tensorflow importer) and as such none of these tests would be usable without doing a tensorflow importer build. That may be fine for these uses but then we may want to put these under microbenchmarks/mhlo/ so it's easy to exclude when someone is not building tf. If MHLO was the source of truth we could also have a script to run over the mhlo/ dir and generate a linalg dir, but I'm not sure how useful that is. We'll be having a lot of things coming from tosa too, and having a mix of linalg, mhlo, and tosa for microbenchmarking will be really hard to juggle as you'd need builds of all the different tools. That may still be worth it, though, if what you want to test includes the tosa/mhlo->linalg conversion - but if you think it's mostly just testing linalg then we should bake that out. I defer to you all and just don't want any surprises when I eventually remove the HLO passes from iree-opt/iree-translate :)

MLIR_FILE_PATH=${1}
ARGS=${@:2}

adb shell 'mkdir /data/local/tmp'

@benvanik benvanik Mar 31, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah, this would probably be better as a gist - otherwise it becomes yet another thing to support. (github deleted the rest of the comment): or a big scare tag that says "only runs on ahmeds machine, ask ahmed for help" would at least set expectations :)


adb shell 'mkdir /data/local/tmp'
MLIR_FILE_NAME=$(basename $MLIR_FILE_PATH)
TARGET_VM_FILE=/tmp/$MLIR_FILE_NAME.fbvm

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

vmfb :)

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.

The plan Is this should work on any linux-machine with local android phone attached =),
I don't mind deleting but was to make it easy to reproduce the same numbers I have:

had for this is users need to are:

  1. Build an android release build
  2. Define IREE_RELEASE_DIR and run the script.

@asaadaldien

Copy link
Copy Markdown
Contributor Author

This would be good to have if you as me, but other people have a more informed opinion.

This has been my workflow for awhile iterating on performance on CPU.

Only question though is could we just start from the linalg. operation? There are definitely advantages to using mhlo. Some ops might be lowered to a sequence of operations, but even then since we dont want anything mhlo in our core repo, starting from Linalg might be better.

IMO having both are good for but specifically at this level (performance of an op or a sequence of ops (e.g fused conv-batchnorm) it easier to start with tosa or mhlo as it gets complicated adding all init_tensor, fill and constructing (or copy-paste) linalg.generics

@asaadaldien
asaadaldien force-pushed the ataei-micro_benchmarks_dir branch from a288836 to c9ec138 Compare March 31, 2021 00:23
@asaadaldien asaadaldien changed the title Add directory for micro-benchmarking Add directory for microbenchmarking Mar 31, 2021
@hanhanW

hanhanW commented Mar 31, 2021

Copy link
Copy Markdown
Contributor

I think it depends on what we want to benchmark. Starting from Linalg could hide something like linalg.fill, or padding stuff. But yes, starting from Linalg is probably better because this is microbenchmark.

@hanhanW hanhanW 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.

I think it is meaningless if we only put files here. At least, we should translate them to IREE modules? And maybe use lit tests to check output?

I can help on connecting these to benchmarking infrastructure after we land it.

@asaadaldien

asaadaldien commented Mar 31, 2021 •

Copy link
Copy Markdown
Contributor Author

tarting from Linalg is probably better because this is microbenchmark.

Its very important to not drop fill, init_tensor, reshapes which is why doing something like matmul or various types of conv easy to be added here at the front end side (HLO or TOSA) is easier otherwise it will get hard to reason about the performance of the op.

@asaadaldien

Copy link
Copy Markdown
Contributor Author

I think it is meaningless if we only put files here. At least, we should translate them to IREE modules? And maybe use lit tests to check output?

I can help on connecting these to benchmarking infrastructure after we land it.

Good ideas will be good to add rules to translate these and report the results on mako dashboard.
To separate concerns we shouldn't worry about correctness here as its covered in tests (if not then we add a test)

@asaadaldien
asaadaldien requested a review from hanhanW March 31, 2021 16:47
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

I have no opinions here. If this is deemed good to land, I'd be happy to use it.

@MaheshRavishankar
MaheshRavishankar removed their request for review March 31, 2021 16:56
@MaheshRavishankar
MaheshRavishankar dismissed their stale review March 31, 2021 16:57

Removing my blocked

@antiagainst antiagainst left a comment

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.

Its very important to not drop fill, init_tensor, reshapes which is why doing something like matmul or various types of conv easy to be added here at the front end side (HLO or TOSA) is easier otherwise it will get hard to reason about the performance of the op.

+1. Even if we convert to linalg ops, we should keep them as they are part of the original op. Otherwise we might measure something that is different. For example, right now the fill and copy generated from the original padded convolution op can be a large portion of the cost. Removing them would not reflect the current status.

@@ -0,0 +1,74 @@
// Convolution ops sampled from MobileVision V1 (mobilenet_v1_100_224)

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.

Convolution ops might largely be the same but still do we care v1 that much with v2 and even newer models? I'd assume later models are more prevalently used.

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.

This is just an FYI the following are sampled from specific model (a peace extra information that is sometimes useful)

@@ -0,0 +1,74 @@
// Convolution ops sampled from MobileVision V1 (mobilenet_v1_100_224)
// https://github.com/google/iree/blob/main/integrations/tensorflow/e2e/slim_vision_models/slim_vision_model_test.py#L34

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.

It might worth to explain the naming scheme and also add some comment above each conv to mention the key points to measure (like padding, stride, etc.) cause the mhlo op can be very verbose. :)

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 it worths to attach padding/stride informations in the function name, it can be showed on Mako benchmarks.

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.

+1 on explain the naming scheme

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.

The naming convention will get very long and they kind of implicit looking at the output size :)

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

+1. Even if we convert to linalg ops, we should keep them as they are part of the original op. Otherwise we might measure something that is different. For example, right now the fill and copy generated from the original padded convolution op can be a large portion of the cost. Removing them would not reflect the current status.

I never said we should have a single linalg operation. You could have a sequence of Linalg operations (Which is more important). The goal is to eventually rid the IREE code base of MHLO ops.
How MHLO lowers to IREE or how TOSA lowers to IREE is immaterial. What we care about is that given a sequence of Linalg ops, whats the performance we get.

Comment thread iree/test/microbenchmarks/mhlo_dot.mlir Outdated
%rhs = iree.unfoldable_constant dense<1.0> : tensor<384x32xf32>
%0 = "mhlo.dot"(%lhs, %rhs) : (tensor<384x384xf32>, tensor<384x32xf32>) -> tensor<384x32xf32>
return %0 : tensor<384x32xf32>
} No newline at end of file

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.

Add a new line

@@ -0,0 +1,74 @@
// Convolution ops sampled from MobileVision V1 (mobilenet_v1_100_224)
// https://github.com/google/iree/blob/main/integrations/tensorflow/e2e/slim_vision_models/slim_vision_model_test.py#L34

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.

+1 on explain the naming scheme

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

The more I think about it, the more I dont like having operations lowered from mhlo for testing. I am not going to block this, but this will need to be deprecated/modified when we strip mhlo out of the core repo.
FYI @benvanik

This needs definitely requires more iteration for documentation, improve scripts...etc
but for now IMO we can start with something simple for reproducibility  and iterate ?
This needs definitely requires more iteration for documentation, improve scripts...etc
but for now IMO we can start with something simple for reproducibility  and iterate ?
@asaadaldien
asaadaldien force-pushed the ataei-micro_benchmarks_dir branch from a49ce9b to a3c9a7f Compare April 1, 2021 16:21
@asaadaldien
asaadaldien requested a review from antiagainst April 1, 2021 18:09
@asaadaldien
asaadaldien requested a review from hanhanW April 1, 2021 18:09

@hanhanW hanhanW 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 good to me. I'm not sure if others have more comment, but I approve for unblock merging it.

// The following ops are sampled from mobile_bert
// https://github.com/google/iree/blob/main/integrations/tensorflow/e2e/mobile_bert_squad_test.py

func @dot_general_4_x384x32x384() -> tensor<4x384x384xf32> attributes { iree.module.export } {

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.

Is the underline intended?

Suggested change
func @dot_general_4_x384x32x384() -> tensor<4x384x384xf32> attributes { iree.module.export } {
func @dot_general_4x384x32x384() -> tensor<4x384x384xf32> attributes { iree.module.export } {

@asaadaldien

Copy link
Copy Markdown
Contributor Author

@hanhanW In addition to mako tracking these for regression. IMO it will be very cool is to have a manual gitHub action users can trigger to run microbenchmarks on head vs this PR commit and post the textual as a comment on the PR. similar to what I usually do but not on my device/machine and more globally reproducible :)

@hanhanW

hanhanW commented Apr 1, 2021

Copy link
Copy Markdown
Contributor

@hanhanW In addition to mako tracking these for regression. IMO it will be very cool is to have a manual gitHub action users can trigger to run microbenchmarks on head vs this PR commit and post the textual as a comment on the PR. similar to what I usually do but not on my device/machine and more globally reproducible :)

Yes, we actually can do it on model benchmarks today. I usually do it manually through BuildKite. E.g., I'm now working on adding new metrics for linalg on tensors path, and I manually triggered a run based on current branch: https://buildkite.com/iree/iree-android-benchmark/builds/2195

We can probably integrate the action into label stuff (like kokoro:force_rerun). I think @GMNGeoffrey knows more about it.

@asaadaldien
asaadaldien force-pushed the ataei-micro_benchmarks_dir branch from a3c9a7f to a6f7f12 Compare April 1, 2021 19:13
@asaadaldien
asaadaldien merged commit e0ee3f3 into main Apr 1, 2021
@asaadaldien
asaadaldien deleted the ataei-micro_benchmarks_dir branch April 1, 2021 19:34
This was referenced Apr 5, 2021
copybara-service Bot pushed a commit that referenced this pull request Apr 6, 2021
* 6bd5658 Merge google -> main (#5319)
* 2e5257d Merge branch 'main' into google-to-main
* 6936ee7 Patch VMLA performance by reserving vector size before pushing to it. (#5316)
* f2f0041 NFC: Cleanup ConcretizeTileAmongstWorkgroupsPass. (#5297)
* f96726a Add tests to run few other (smaller) models with Linalg on tensors path. (#5306)
* fd64070 Revert "Add wasm-micro-runtime submodule and get building with CMake." (#5312)
* ce0285f Continue pruning abseil usage: switch from absl::InlinedVector to std::vector...
* 71e24b6 Removing hal.buffer.fill and hal.buffer.copy. (#5307)
* 3c611d3 Add Mako benchmark config template file. (#5200)
* 4d1a394 Fix RFFT bugs in VMLA. (#5308)
* 0d55c95 Add configure_bazel.py step to TensorFlow getting started doc.
* 1386d2c Switch simple_embedding_test to include drivers explicitly. (#5304)
* 402550b Add StripAsserts pass and handle tf.Identity ops on tensor lists. (#5294)
* fbdb4ef Add new metrics to MobileNetV2 benchmarks. (#5301)
* 99c8eac Implementing Vulkan dispatch tracing. (#5287)
* 2681dff Insert clones prior to mutation and not where it originates. (#5292)
* aeafd9e Fix CUDA HAL bug and enable more execution tests (#5296)
* 2801780 [CUDA Codegen] Enable tiling and vectorization for MatMulOp (#5293)
* c61fefe Extend AffineMin canonicalization to support scf.parallel (#5289)
* e0ee3f3 Add directory for microbenchmarking (#5260)
* b8da32c Set wasm-export-name attributes on exported functions again. (#5286)
* e2a2f81 Canonicalize affine min before applying tile-and-vecotrize passes (#5285)
* 23861f7 [CUDA codegen] add vectorization infrastructure (#5278)
* 6f443c4 Drop deps on Abseil's core_headers, synchronization, macros. (#5275)
* e5b9e8a Actually run MobileNet with fake weights to check correctness (#5284)
* e56db9a Remove dead code in LinalgToSPIRV (#5281)
* 8863aa1 [NFC] Fix typos in variable names. (#5279)
* 9cd93ba Turn vectorization on by default for linalg on tensors path (#5280)
* 894dac6 Merge google -> main #5276
* b738162 Changing HAL dialect syntax to express all types. (#5239)
* 1ba4e88 Merge branch 'main' into google-to-main
* 531c73e Fix yml syntax (#5274)
* 494fe32 Bumping the tracy version to 0.7.7 (WIP). (#5272)
* 3616323 Disable Vulkan float16 tests on Pixel4 (#5273)
* ade7ff1 Disable running BERT on Vulkan (see Issue #5268) (#5269)
* 25ddc10 Add tracing to allocations made from VMA. (#5271)
* df454f4 Changing iree_vm_list_resize to grow by 2x. (#5270)
* bd9a113 Adding command buffer queue affinity. (#5265)
* de834ae Make status matcher print the message when it fails. (#5266)
* 10f5eaf Add f16 e2e tests for vulkan (#5257)
* 1bdc3a4 Actually make MobileBERT run in the test. (#5264)
* 2e05313 Add support for module almost_eq check for f16 type (#5261)

COPYBARA_INTEGRATE_REVIEW=#5321 from NatashaKnk:main-to-google 6bd5658
PiperOrigin-RevId: 366926967
GMNGeoffrey pushed a commit that referenced this pull request Apr 6, 2021
* 6bd5658 Merge google -> main (#5319)
* 2e5257d Merge branch 'main' into google-to-main
* 6936ee7 Patch VMLA performance by reserving vector size before pushing to it. (#5316)
* f2f0041 NFC: Cleanup ConcretizeTileAmongstWorkgroupsPass. (#5297)
* f96726a Add tests to run few other (smaller) models with Linalg on tensors path. (#5306)
* fd64070 Revert "Add wasm-micro-runtime submodule and get building with CMake." (#5312)
* ce0285f Continue pruning abseil usage: switch from absl::InlinedVector to std::vector...
* 71e24b6 Removing hal.buffer.fill and hal.buffer.copy. (#5307)
* 3c611d3 Add Mako benchmark config template file. (#5200)
* 4d1a394 Fix RFFT bugs in VMLA. (#5308)
* 0d55c95 Add configure_bazel.py step to TensorFlow getting started doc.
* 1386d2c Switch simple_embedding_test to include drivers explicitly. (#5304)
* 402550b Add StripAsserts pass and handle tf.Identity ops on tensor lists. (#5294)
* fbdb4ef Add new metrics to MobileNetV2 benchmarks. (#5301)
* 99c8eac Implementing Vulkan dispatch tracing. (#5287)
* 2681dff Insert clones prior to mutation and not where it originates. (#5292)
* aeafd9e Fix CUDA HAL bug and enable more execution tests (#5296)
* 2801780 [CUDA Codegen] Enable tiling and vectorization for MatMulOp (#5293)
* c61fefe Extend AffineMin canonicalization to support scf.parallel (#5289)
* e0ee3f3 Add directory for microbenchmarking (#5260)
* b8da32c Set wasm-export-name attributes on exported functions again. (#5286)
* e2a2f81 Canonicalize affine min before applying tile-and-vecotrize passes (#5285)
* 23861f7 [CUDA codegen] add vectorization infrastructure (#5278)
* 6f443c4 Drop deps on Abseil's core_headers, synchronization, macros. (#5275)
* e5b9e8a Actually run MobileNet with fake weights to check correctness (#5284)
* e56db9a Remove dead code in LinalgToSPIRV (#5281)
* 8863aa1 [NFC] Fix typos in variable names. (#5279)
* 9cd93ba Turn vectorization on by default for linalg on tensors path (#5280)
* 894dac6 Merge google -> main #5276
* b738162 Changing HAL dialect syntax to express all types. (#5239)
* 1ba4e88 Merge branch 'main' into google-to-main
* 531c73e Fix yml syntax (#5274)
* 494fe32 Bumping the tracy version to 0.7.7 (WIP). (#5272)
* 3616323 Disable Vulkan float16 tests on Pixel4 (#5273)
* ade7ff1 Disable running BERT on Vulkan (see Issue #5268) (#5269)
* 25ddc10 Add tracing to allocations made from VMA. (#5271)
* df454f4 Changing iree_vm_list_resize to grow by 2x. (#5270)
* bd9a113 Adding command buffer queue affinity. (#5265)
* de834ae Make status matcher print the message when it fails. (#5266)
* 10f5eaf Add f16 e2e tests for vulkan (#5257)
* 1bdc3a4 Actually make MobileBERT run in the test. (#5264)
* 2e05313 Add support for module almost_eq check for f16 type (#5261)

PiperOrigin-RevId: 366926967
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.

5 participants