Skip to content

[flow] enable reduction+broadcast+elementwise by default - #9789

Merged
okkwon merged 2 commits into
iree-org:mainfrom
okkwon:enable-reduction-fuse-by-default
Aug 3, 2022
Merged

okkwon merged 2 commits into
iree-org:mainfrom
okkwon:enable-reduction-fuse-by-default

Conversation

@okkwon

@okkwon okkwon commented Jul 14, 2022

Copy link
Copy Markdown
Member

No description provided.

@iree-github-actions-bot

iree-github-actions-bot commented Jul 14, 2022 •

Copy link
Copy Markdown
Contributor

Abbreviated Linux Benchmark Summary

@ commit 12134e80070cc48df7a9d73bc5526eabe84d11bd (vs. base d35b332814389f86618219516157f936e1830399)

Regressed Latencies 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV2 [fp32,imagenet] (TFLite) 1-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 14 (vs. 13, 7.69%↑) 14 0
MobileNetV2 [fp32,imagenet] (TFLite) full-inference,default-flags with IREE-Dylib-Sync @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 14 (vs. 13, 7.69%↑) 14 0
MobileSSD [fp32] (TFLite) 4-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 17 (vs. 16, 6.25%↑) 17 0

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MiniLML12H384Uncased [int32] (TF) 4-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 105 (vs. 114, 7.89%↓) 105 1
MiniLML12H384Uncased [int32] (TF) 1-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 370 (vs. 396, 6.57%↓) 370 2
MiniLML12H384Uncased [int32] (TF) 8-thread,full-inference,default-flags with IREE-Dylib @ GCP-c2-standard-16 (CPU-x86\_64-CascadeLake) 63 (vs. 67, 5.97%↓) 63 1

Regressed Compilation Times 🚩

Benchmark Name Compilation Time (ms)
MiniLML12H384Uncased [int32] (TF) CPU-x86\_64-CascadeLake full-inference,default-flags 11738 (vs. 6345, 85.00%↑)
MiniLML12H384Uncased [int32] (TF) CPU-x86\_64-CascadeLake 4-thread,full-inference,default-flags 11738 (vs. 6345, 85.00%↑)
MiniLML12H384Uncased [int32] (TF) CPU-x86\_64-CascadeLake 8-thread,full-inference,default-flags 11738 (vs. 6345, 85.00%↑)

[Top 3 out of 32 results showed]

Regressed Total Dispatch Sizes 🚩

Benchmark Name Total Dispatch Size (bytes)
MiniLML12H384Uncased [int32] (TF) CPU-x86\_64-CascadeLake full-inference,default-flags 190304 (vs. 67952, 180.06%↑)
MiniLML12H384Uncased [int32] (TF) CPU-x86\_64-CascadeLake 4-thread,full-inference,default-flags 190304 (vs. 67952, 180.06%↑)
MiniLML12H384Uncased [int32] (TF) CPU-x86\_64-CascadeLake 8-thread,full-inference,default-flags 190304 (vs. 67952, 180.06%↑)

[Top 3 out of 4 results showed]

For more information:

@iree-github-actions-bot

iree-github-actions-bot commented Jul 14, 2022 •

Copy link
Copy Markdown
Contributor

Abbreviated Benchmark Summary

@ commit 12134e80070cc48df7a9d73bc5526eabe84d11bd (vs. base d35b332814389f86618219516157f936e1830399)

Regressed Latencies 🚩

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileNetV3Small [fp32,imagenet] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 11 (vs. 10, 10.00%↑) 11 0
MobileSSD [fp32] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 61 (vs. 58, 5.17%↑) 61 0

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MobileBertSquad [int8] (TFLite) 4-thread,big-core,full-inference,experimental-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 198 (vs. 228, 13.16%↓) 198 0
MobileNetV3Small [fp32,imagenet] (TFLite) 1-thread,big-core,full-inference,default-flags with IREE-Dylib @ Pixel-4 (CPU-ARMv8.2-A) 11 (vs. 12, 8.33%↓) 11 0
MobileNetV3Small [fp32,imagenet] (TFLite) big-core,full-inference,default-flags with IREE-Dylib-Sync @ Pixel-4 (CPU-ARMv8.2-A) 12 (vs. 13, 7.69%↓) 12 0

[Top 3 out of 5 results showed]

No improved or regressed compilation metrics 🏖️

For more information:

@okkwon

okkwon commented Jul 14, 2022

Copy link
Copy Markdown
Member Author

I still get the same failure for CUDA: check_cuda_cuda_bert_encoder_unrolled_fake_weights. @ThomasRaoux Please take a look.

I also found new failure for vulkan, related to dynamic dims. (This is new. Looking into it.)

@benvanik

Copy link
Copy Markdown
Collaborator

Are these regressions real? (first I've really seen of this report so I'm not sure how much to trust it yet, but it looks awesome!)
image

@okkwon okkwon self-assigned this Jul 14, 2022
@okkwon okkwon added this to the IREE + NOD Model Coverage milestone Jul 14, 2022
@okkwon

okkwon commented Jul 14, 2022

Copy link
Copy Markdown
Member Author

@pzread what is the total dispatch size? Do we have "number of dispatches", which is static information from the compiler?

@okkwon

okkwon commented Jul 14, 2022 •

Copy link
Copy Markdown
Member Author

I was able to reproduce the vulkan failure and created an issue: #9802

@benvanik

Copy link
Copy Markdown
Collaborator

It's final machine code binary size - so this PR likely triggers some nasty unrolling that massively bloats the binaries (and thus also takes much longer to compile). I don't think it's the PR's fault, but we can't land it until we figure out how to not regress. Maybe @dcaballe's recent changes to LLVM unrolling will help?

@benvanik

Copy link
Copy Markdown
Collaborator

(massive kudos to @pzread - we've had regressions like this in the past we haven't noticed until it was too late!)

@okkwon

okkwon commented Jul 15, 2022

Copy link
Copy Markdown
Member Author

Cool. Yes, we should investigate and confirm that. The nasty unrolling might have improved the perf.

@benvanik

Copy link
Copy Markdown
Collaborator

It looks like the reported latencies are within the noise so I think it's mostly a wash but looking at some traces would be useful. Our (previous?) reliance on the LLVM autovectorizer/unrolling could trigger these pathologically bad cases - at some point you unroll so much your inner loop doesn't fit in I$ and you get slower! The fusion this PR does should reduce code size (as we have fewer dispatches with the per-dispatch overhead in the binary) so I think it'll be a good change regardless of performance impact if we can reel in whatever is causing the explosion and reap the binary size improvements.

@okkwon

okkwon commented Jul 15, 2022

Copy link
Copy Markdown
Member Author

The improvement in the latency is real. @hanhanW also measured. I am wondering if the improvement is coming from the unrolling or not, since the CPU side may have less impact from the lower number of dispatches.

@benvanik

Copy link
Copy Markdown
Collaborator

Is it an improvement not tracked in the benchmarks? (I'm going off of the posts above, which show as many regressions as improvements of the same 1-10% magnitude)

@dcaballe

Copy link
Copy Markdown
Contributor

Maybe @dcaballe's recent changes to LLVM unrolling will help?

We disabled LLVM vectorizers by default (#9642). If a loop is not vectorized in MLIR and it's not in LLVM, it might be more aggressively unrolled. You could try enabling the vectorizers again and see what happens.

LLVM unrolling is still enabled by default since disabling it leads to significant regressions. You can try disabling it and see what happens (#9658).

(massive kudos to @pzread - we've had regressions like this in the past we haven't noticed until it was too late!)

+1! I'm super excited about this new feature!

@hanhanW

hanhanW commented Jul 15, 2022

Copy link
Copy Markdown
Contributor

The regression about compilation time and binary sizes could be real. I image that the total number of dispatches are less, but the kind of dispatches are more. E.g.,, we could only have matmul_1 + elem_1 case w/o the flag on. But have new matmul_1 + elem_2 w/ the flag on. In the context, the compilation time and binary sizes could get increased because we have more heavy dispatches to compile.

@hanhanW

hanhanW commented Jul 15, 2022

Copy link
Copy Markdown
Contributor

Is it an improvement not tracked in the benchmarks? (I'm going off of the posts above, which show as many regressions as improvements of the same 1-10% magnitude)

It's tracked in the benchmarks. See

image

@okkwon
okkwon force-pushed the enable-reduction-fuse-by-default branch from 12134e8 to 43d5932 Compare July 28, 2022 16:37
@okkwon
okkwon force-pushed the enable-reduction-fuse-by-default branch from 43d5932 to 5d07e7e Compare July 28, 2022 17:03
@okkwon

okkwon commented Jul 28, 2022

Copy link
Copy Markdown
Member Author

The dynamic shape case is disabled for now since Vulkan needs more work to support it. (#9802)

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Could we add some execution tests for the corner cases we identified in e2e/regression? That would make me feel more confident as I'm not convinced all the backends have a robust handling of such dispatch regions. What do you think?

@okkwon

okkwon commented Jul 28, 2022 •

Copy link
Copy Markdown
Member Author

Sounds good. I will do the e2e work as a separate issue, since I need to iterate over the whole benchmark suite and extract the portions (softmax and normalizations).

@okkwon
okkwon marked this pull request as ready for review July 28, 2022 17:39
@okkwon

okkwon commented Jul 28, 2022

Copy link
Copy Markdown
Member Author

Created #9938 for adding e2e tests.

@okkwon
okkwon requested a review from ThomasRaoux July 28, 2022 17:42
@okkwon
okkwon merged commit 07cdff6 into iree-org:main Aug 3, 2022
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Sorry, I didnt comment on this for a while. But wasnt sure if the increase in compilation time and dispatch sizes are justified. Would be good to triage the cause of those two.

@okkwon

okkwon commented Aug 3, 2022

Copy link
Copy Markdown
Member Author

Oh. Good point. I will revert the flag again until we get some good understanding about them.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Eh, its in, so unless someone else objects, I dont think it needs to be reverted. But would be good to triage to know if it should be reverted.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

My guess is that the problem is that the broadcasted dimension is not being tiled and end up being vectorized and fully unrolled which generates a large amount of code.
We should fix it (assuming this is the problem) rather sooner than later but if it doesn't break anything it probably doesn't require a revert.

@pzread

pzread commented Aug 3, 2022 •

Copy link
Copy Markdown
Contributor

Not sure why, but the dispatch size on the merge run looks fine: 65088 -> 65904 bytes
https://perf.iree.dev/serie?IREE?MiniLML12H384Uncased%20%5Bint32%5D%20(TF)%20CPU-x86_64-CascadeLake%20full-inference%2Cdefault-flags%20%5Bcompilation%3Amodule%3Acomponent-size%3Atotal-dispatch-size%5D

Manually checked both binaries from the previous problematic run and the latest run, the numbers in the reports are correct. So I guess some changes fixed the issue in the past few weeks?

@okkwon

okkwon commented Aug 3, 2022

Copy link
Copy Markdown
Member Author

@okkwon

okkwon commented Aug 3, 2022

Copy link
Copy Markdown
Member Author

Not much to triage here based on the latest perf run. I won't revert the change. I am going to add more small e2e tests which might help identify the issue later.

@pzread

pzread commented Aug 5, 2022 •

Copy link
Copy Markdown
Contributor

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

huh, I dont think it is expected. Maybe it needed some upstream fixes w.r.t CUDA handling reductions that might be needed

@okkwon

okkwon commented Aug 5, 2022

Copy link
Copy Markdown
Member Author

@ThomasRaoux do you have an idea? I believe the CUDA path was tested with the option on.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Yes I had tested the model from Nod. Is it the same one? Something must have changed. @pzread how can we get the mlir for this?

@pzread

pzread commented Aug 5, 2022 •

Copy link
Copy Markdown
Contributor

All artifacts can be found here: https://buildkite.com/iree/iree-benchmark-linux/builds/963

Imported MLIR is in this tgz: https://buildkite.com/organizations/iree/pipelines/iree-benchmark-linux/builds/963/jobs/018264b4-09e0-4154-82f4-d60090c9b882/artifacts/018264d2-3d46-456b-bb0d-6e8dc209939f (build-targets/linux-x86_64/benchmark_suites/TF/minilm-l12-h384-uncased-tf-model.mlir, it's correct that the path has x86_64)

Compiled CUDA vmfb module is in this tgz: https://buildkite.com/organizations/iree/pipelines/iree-benchmark-linux/builds/963/jobs/018264b4-09e0-4154-82f4-d60090c9b882/artifacts/018264d2-3d45-430e-aa8a-a80df1e97aa2

This benchmark is not imported/run with SHARK, but directly imported from MiniLM TF SavedModel, so there might be some differences.

@pzread

pzread commented Aug 5, 2022 •

Copy link
Copy Markdown
Contributor

Here is the command that the benchmark ran with:

taskset 0xFF /var/lib/buildkite-agent/builds/gcp-buildkite-bench-cuda-a100-1/iree/iree-benchmark-linux/build-targets/linux-cuda/tools/iree-benchmark-module --module_file=../../vmfb/minilm-l12-h384-uncased-tf-model.mlir-0876e46c6fb410aee345a41906f446a6.vmfb --entry_function=predict --function_input=1x512xi32 --function_input=1x512xi32 --function_input=1x512xi32  --device=cuda://0 --time_unit=ns

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Thanks @pzread! I'm looking at it.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

I see the problem, one transformation is somehow missing. I'll send a patch to fix it

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Should be fixed by:
#10010

@ThomasRaoux

Copy link
Copy Markdown
Contributor

Looks like the big increase went down but the perf are still slower than before the change. It looks like the integrate may also have caused some perf problem. I'll try to debug it on monday

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

It does look like integrate caused a regression (which is interesting since this integrate was literally no changes to IREE itself, first time I have seen that :P ). Looking through the list of LLVM commits https://github.com/iree-org/iree-llvm-fork/compare/8ae4b985e710fb51a4e01df1cba4df6e64ac1bb3...58526b2d2be932e893218857cc47a16fb05cf1c0 nothing stands out.

@ThomasRaoux

Copy link
Copy Markdown
Contributor

I compared the vmfb binary before and after the second regression and they are identical so this seems like an environment issue. I had seen that on gcp before. I restarted the VM used for benchmarking and in the latest run we are faster than before Okwan’s change so we do the expected speed up.

So everything should be solved at this point.

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.

8 participants