Skip to content

Disabling detensoring by default until #6948 can be completed. - #13658

Merged
benvanik merged 1 commit into
mainfrom
benvanik-disable-detensoring
May 17, 2023
Merged

benvanik merged 1 commit into
mainfrom
benvanik-disable-detensoring

Conversation

@benvanik

@benvanik benvanik commented May 17, 2023 •

Copy link
Copy Markdown
Collaborator

Detensoring is useful in small scale (a single while-loop with a tensor iterator like from JAX) but results in pathologically bad device<->host behavior in all other cases. Without improvements to dispatch region formation for small scalar workloads or a retensoring pass that eliminates the device<->host transfers we can't have it on by default.

This makes HLO while loops less efficient as they represent the loop iterator and condition as tensor operations that get performed on device even though the loop happens on the host. It makes everything else significantly better, though, and in the LLM modules under inspection in #13637 reduces the number of host<->device round trips from ~500-1000 (depending on model) to ~3 (all while loop math). We could investigate an HLO-level specialized detensoring of while loops until we can fix #6948.

WebGPU's SPIR-V -> WGSL lowering currently has issues with non-detensored comparisons (#12509) and those while.mlir tests have been disabled.

@benvanik benvanik added the performance ⚡ Performance/optimization related work across the compiler and runtime label May 17, 2023

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

May want to run benchmarks on this (if we have any there that are affected...)

@ScottTodd
ScottTodd requested a review from rsuderman May 17, 2023 17:06
@benvanik

Copy link
Copy Markdown
Collaborator Author

@ScottTodd I'm seeing some failures in SPIR-V -> WGSL that I suspect are existing but not hit because detensoring was preventing the comparison ops (both tosa and HLO) from reaching device code. I'll file an issue and disable those tests for now.

FAILED: tests/e2e/tosa_ops/check_webgpu_while.mlir_module.vmfb /work/build-debug/tests/e2e/tosa_ops/check_webgpu_while.mlir_module.vmfb 
cd /work/build-debug/tests/e2e/tosa_ops && /work/build-debug/tools/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=webgpu --iree-input-type=tosa --iree-codegen-gpu-native-math-precision=true /work/tests/e2e/tosa_ops/while.mlir -o check_webgpu_while.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-debug\" --iree-llvmcpu-embedded-linker-path=\"/work/build-debug/llvm-project/bin/lld\" --iree-llvmcpu-wasm-linker-path=\"/work/build-debug/llvm-project/bin/lld\"
Tint reported 1 error(s) for a SPIR-V program, see diagnostics:
error: function parameter of pointer type cannot be in 'storage' address space
/work/tests/e2e/tosa_ops/while.mlir:15:10: error: failed to compile SPIR-V to WGSL. Consider inspecting the shader program using -iree-hal-dump-executable-intermediates.
    %3 = "tosa.greater_equal"(%2, %arg0) : (tensor<i32>, tensor<i32>) -> tensor<i1>
         ^
/work/tests/e2e/tosa_ops/while.mlir:15:10: error: failed to serialize executable for target backend webgpu
    %3 = "tosa.greater_equal"(%2, %arg0) : (tensor<i32>, tensor<i32>) -> tensor<i1>
         ^
/work/tests/e2e/tosa_ops/while.mlir:15:10: error: failed to serialize executables
    %3 = "tosa.greater_equal"(%2, %arg0) : (tensor<i32>, tensor<i32>) -> tensor<i1>
FAILED: tests/e2e/xla_ops/check_webgpu_while.mlir_module.vmfb /work/build-debug/tests/e2e/xla_ops/check_webgpu_while.mlir_module.vmfb 
cd /work/build-debug/tests/e2e/xla_ops && /work/build-debug/tools/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=webgpu --iree-input-type=mhlo --iree-codegen-gpu-native-math-precision=true /work/tests/e2e/xla_ops/while.mlir -o check_webgpu_while.mlir_module.vmfb --iree-hal-executable-object-search-path=\"/work/build-debug\" --iree-llvmcpu-embedded-linker-path=\"/work/build-debug/llvm-project/bin/lld\" --iree-llvmcpu-wasm-linker-path=\"/work/build-debug/llvm-project/bin/lld\"
Tint reported 1 error(s) for a SPIR-V program, see diagnostics:
error: function parameter of pointer type cannot be in 'storage' address space
/work/tests/e2e/xla_ops/while.mlir:8:8: error: failed to compile SPIR-V to WGSL. Consider inspecting the shader program using -iree-hal-dump-executable-intermediates.
  %3 = "mhlo.compare"(%2, %bound) {comparison_direction = #mhlo<comparison_direction LT>} : (tensor<i32>, tensor<i32>) -> tensor<i1>
       ^
/work/tests/e2e/xla_ops/while.mlir:8:8: error: failed to serialize executable for target backend webgpu
  %3 = "mhlo.compare"(%2, %bound) {comparison_direction = #mhlo<comparison_direction LT>} : (tensor<i32>, tensor<i32>) -> tensor<i1>
       ^
/work/tests/e2e/xla_ops/while.mlir:8:8: error: failed to serialize executables
  %3 = "mhlo.compare"(%2, %bound) {comparison_direction = #mhlo<comparison_direction LT>} : (tensor<i32>, tensor<i32>) -> tensor<i1>
       ^

@rsuderman

Copy link
Copy Markdown
Collaborator

So there is a chance we should be ok due to the upstream mhlo detensoring code. A while back I made a pass that takes the majority of shape calculations and hoist them to non-dispatched computations. Optimistically we could try to handle this at the higher lever for now and hope the most important cases.

@ScottTodd

Copy link
Copy Markdown
Member

I'm seeing some failures in SPIR-V -> WGSL that I suspect are existing but not hit because detensoring was preventing the comparison ops (both tosa and HLO) from reaching device code. I'll file an issue and disable those tests for now.

Ahhh right. #12509 and #10906. You can either disable the tests or set the flag to true for them.

@benvanik

Copy link
Copy Markdown
Collaborator Author

@rsuderman that'd be great - stablehlo.while handling would also be really helpful - is it currently handling that?

@benvanik
benvanik force-pushed the benvanik-disable-detensoring branch from 3e77a8b to b3a630b Compare May 17, 2023 17:34
@pzread

pzread commented May 17, 2023

Copy link
Copy Markdown
Contributor

Checked the failure on build_e2e_test_artifacts, it's likely due to the #13649. This PR will need to rebase once the revert #13661 is merged. Or puts a benchmark label on PR might temporarily resolve the issue

@benvanik

Copy link
Copy Markdown
Collaborator Author

Thanks @pzread - I was really confused for a bit :) I'll rebase after the revert lands!

Detensoring is useful in small scale (a single while-loop with
a tensor<i64> iterator like from JAX) but results in pathologically
bad device<->host behavior in all other cases. Without improvements
to dispatch region formation for small scalar workloads or a retensoring
pass that eliminates the device<->host transfers we can't have it on
by default.
@benvanik
benvanik force-pushed the benvanik-disable-detensoring branch from b3a630b to a0330cb Compare May 17, 2023 19:15
@benvanik benvanik added benchmarks:cuda Run default CUDA benchmarks benchmarks:x86_64 Run default x86_64 benchmarks labels May 17, 2023
@github-actions

Copy link
Copy Markdown

Abbreviated Benchmark Summary

@ commit eee5e977f5e9fbdabe5b8684943335875677ebaa (vs. base f0636f4e93a3d113fd5d805528e7b5fdeb060455)

Improved Latencies 🎉

Benchmark Name Average Latency (ms) Median Latency (ms) Latency Standard Deviation (ms)
MiniLML12H384Uncased(stablehlo) [x86\_64-cascadelake-linux\_gnu-llvm\_cpu][experimental-flags,fuse-padding] local\_task(embedded\_elf)[8-thread,full-inference,default-flags] with zeros @ c2-standard-16[cpu] 22.612 (vs. 26.692, 15.29%↓) 22.223 0.786

No improved or regressed compilation metrics 🏖️

For more information:

Source Workflow Run

@benvanik
benvanik marked this pull request as ready for review May 17, 2023 22:50
@benvanik
benvanik requested a review from hanhanW as a code owner May 17, 2023 22:50
@benvanik
benvanik merged commit 9ba88a2 into main May 17, 2023
@benvanik
benvanik deleted the benvanik-disable-detensoring branch May 17, 2023 22:51
NatashaKnk pushed a commit to NatashaKnk/iree that referenced this pull request Jul 6, 2023
iree-org#13658)

Detensoring is useful in small scale (a single while-loop with a
tensor<i64> iterator like from JAX) but results in pathologically bad
device<->host behavior in all other cases. Without improvements to
dispatch region formation for small scalar workloads or a retensoring
pass that eliminates the device<->host transfers we can't have it on by
default.

This makes HLO while loops less efficient as they represent the loop
iterator and condition as tensor operations that get performed on device
even though the loop happens on the host. It makes everything else
significantly better, though, and in the LLM modules under inspection in
iree-org#13637 reduces the number of host<->device round trips from ~500-1000
(depending on model) to ~3 (all while loop math). We could investigate
an HLO-level specialized detensoring of while loops until we can fix
iree-org#6948.

WebGPU's SPIR-V -> WGSL lowering currently has issues with
non-detensored comparisons (iree-org#12509) and those `while.mlir` tests have
been disabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmarks:cuda Run default CUDA benchmarks benchmarks:x86_64 Run default x86_64 benchmarks performance ⚡ Performance/optimization related work across the compiler and runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add secondary dispatch region fusion/retensoring pass in flow dialect.

4 participants