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

[AMP] Vulkan Support for Mixed Precision Pass #8295

Closed
AndrewZhaoLuo opened this issue Jun 21, 2021 · 6 comments
Closed

[AMP] Vulkan Support for Mixed Precision Pass #8295

AndrewZhaoLuo opened this issue Jun 21, 2021 · 6 comments

Comments

@AndrewZhaoLuo
Copy link
Contributor

Solve issues and make modifications to support Vulkan for mixed precision pass here: #8069

Current initial issues as described by @Lunderberg

On the vulkan side, it's something similar with the validation checks failing an alignment rule.

Check failed: res == SPV_SUCCESS (-10 vs. 0) : index=27 error:Structure id 12 decorated as Block for variable in StorageBuffer storage class must follow standard storage buffer layout rules: member 0 contains an array with stride 6 not satisfying alignment to 8
%_struct_12 = OpTypeStruct %_runtimearr_v3half

This issue is completed when unit tests can pass for Vulkan target.

@AndrewZhaoLuo
Copy link
Contributor Author

cc @Lunderberg

@AndrewZhaoLuo AndrewZhaoLuo changed the title Vulkan Support for Mixed Precision Pass [AMP] Vulkan Support for Mixed Precision Pass Jun 25, 2021
@masahi
Copy link
Member

masahi commented Jul 22, 2021

I can confirm that TF2 ssd mobilenet v2 can be converted to fp16 and runs on vulkan (AMD) and opencl (Intel Ice lake), if I disable vectorization on fp16 at https://github.com/apache/tvm/blob/main/python/tvm/topi/cuda/injective.py#L54-L55 (cc @Lunderberg).

But the output from fp16 is a bit off compared to fp32 (on both vk and ocl). Also on other models I got type mismatch float32 vs float16 error at Relay level.

fp32
Mean Squared Error of output 0 and shape (1, 100, 4) is 9.562732618023824e-15
Mean Squared Error of output 1 and shape (1, 100) is 0.0
Mean Squared Error of output 2 and shape (1, 100) is 4.539840725570343e-13
Mean Squared Error of output 3 and shape (1,) is 0.0
Mean Squared Error of output 4 and shape (1, 12804, 4) is 3.1784283863710294e-13
Mean Squared Error of output 5 and shape (1, 12804, 91) is 2.194374375133825

fp16
Mean Squared Error of output 0 and shape (1, 100, 4) is 0.01756046526134014
Mean Squared Error of output 1 and shape (1, 100) is 8.5600004196167
Mean Squared Error of output 2 and shape (1, 100) is 5.59057809823571e-07
Mean Squared Error of output 3 and shape (1,) is 0.0
Mean Squared Error of output 4 and shape (1, 12804, 4) is 5.098227120470256e-07
Mean Squared Error of output 5 and shape (1, 12804, 91) is 2.664001463870136e-09

@Lunderberg
Copy link
Contributor

I ran into a few issues with vectorization when I was running ResNet50 with float16. If you apply PR #8528 , is it still necessary to disable the vectorization?

@Lunderberg
Copy link
Contributor

Regarding the numerical accuracy, I had a few maybe-similar issues when putting together the unittests in #8529. There's a decent number of schedules that perform poorly if the accumulator dtype is float16. I had a short discussion with @AndrewZhaoLuo last week on how best to implement float32 accumulation in the mixed precision pass, but haven't looked into it much yet.

@masahi
Copy link
Member

masahi commented Jul 22, 2021

With #8528, I get this error:

  1: tvm::codegen::CodeGenSPIRV::VisitStmt_(tvm::tir::StoreNode const*)
  0: tvm::codegen::CodeGenSPIRV::StorageInfo::CheckContentType(tvm::runtime::DataType, int)
  File "/home/masa/projects/dev/tvm/src/target/spirv/codegen_spirv.h", line 160
TVMError: 
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------

  Check failed: type == expected_type (int32 vs. float32) : Attempted to access buffer T_reshape as element type int32 using an index of size 1 when the element type is float32

@masahi
Copy link
Member

masahi commented Aug 20, 2021

Vulkan support for fp16 is fully functional, thanks @Lunderberg

@masahi masahi closed this as completed Aug 20, 2021
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

No branches or pull requests

3 participants