-
Notifications
You must be signed in to change notification settings - Fork 224
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
[MHA] Integrate ck mha fp8 solver into miopen #3014
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor suggestions
@@ -7,5 +7,5 @@ nlohmann/json@v3.11.2 -DJSON_MultipleHeaders=ON -DJSON_BuildTests=Off | |||
ROCm/FunctionalPlus@v0.2.18-p0 | |||
ROCm/eigen@3.4.0 | |||
ROCm/frugally-deep@9683d557eb672ee2304f80f6682c51242d748a50 | |||
ROCm/composable_kernel@15baccf2ecad4fb3498b8acb6bbf58fb5359c7a5 -DCMAKE_BUILD_TYPE=Release -DINSTANCES_ONLY=ON | |||
ROCm/composable_kernel@1dd9875c9ac783cabc8a536e0802b58d43b6b107 -DCMAKE_BUILD_TYPE=Release -DINSTANCES_ONLY=ON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I also recommend picking CK commit hashes from its amd-develop
branch.
const auto& fptr = GetDescsForward(); | ||
if(fptr.oDesc.GetType() == miopenFloat8) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto& fptr = GetDescsForward(); | |
if(fptr.oDesc.GetType() == miopenFloat8) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
return GetDescsForward().oDesc.GetType() == miopenFloat8; |
But I'm not sure that it has to be here at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following convolution's problem description pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then my suggestion matches this pattern perfectly.
const std::string name = context.GetStream().GetDeviceName(); | ||
if(!(name == "gfx940" || name == "gfx941" || name == "gfx942")) | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StartsWith(handle.GetDeviceName(), "gfx103")
const std::string name = context.GetStream().GetDeviceName(); | |
if(!(name == "gfx940" || name == "gfx941" || name == "gfx942")) | |
return false; | |
if(!StartsWith(handle.GetDeviceName(), "gfx94")) | |
return false; |
if(!problem.IsFFp8()) // forward mha fp8 | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably all the tensors should be explicitly checked.
::miopen::mha::MhaInputDescsForward mha_des = problem.GetDescsForward(); | ||
const auto& lens = mha_des.qDesc.GetLengths(); | ||
auto [N, H, S, D] = std::tie(lens[0], lens[1], lens[2], lens[3]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
::miopen::mha::MhaInputDescsForward mha_des = problem.GetDescsForward(); | |
const auto& lens = mha_des.qDesc.GetLengths(); | |
auto [N, H, S, D] = std::tie(lens[0], lens[1], lens[2], lens[3]); | |
auto [N, H, S, D] = miopen::tien<4>(problem.GetDescsForward().qDesc.GetLengths()); |
if(D <= 256 && S % 128 == 0 && D % 64 == 0) | ||
return true; | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(D <= 256 && S % 128 == 0 && D % 64 == 0) | |
return true; | |
return false; | |
return (D <= 256 && S % 128 == 0 && D % 64 == 0); |
auto [n, h, s, d, drop] = GetParam(); | ||
Handle& handle = get_handle(); | ||
|
||
if((drop > 0.0f) && (s % handle.GetWavefrontWidth() != 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, CK does not support dropout at all.
InitTensor(miopenTensorMhaV, std::move(v.mTensor)); | ||
|
||
float s_scale = test::cpu::GetF8Scaling(1.0); | ||
// clang-tidy complains about the same expression on both sides of "/": 1.f / 1.f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// clang-tidy complains about the same expression on both sides of "/": 1.f / 1.f |
float amaxO_ref; | ||
|
||
bool is_ck_solver = false; | ||
float ck_fp8_solver_threshold = 0.015; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too high threshold, MIOpen fp8 algorithm fits into 0.0002
which is 75 times smaller.
Could you double-check that the values are similar, because rms error is not sensible to permutations and some significant outliers.
class Test_Fwd_Mha_F32 : public Test_Fwd_Mha<float> | ||
{ | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, CK does not support FP32.
else | ||
{ | ||
// ck solver | ||
ScaleMult(atten_heads_fp32, GetF8Scaling(aMax_O), multi_head_attention_fp8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aMax_O
must not be used here, it's an output parameter and will be passed as scale_o
into the next iteration.
@bghimireamd do you wish to follow up with this PR? |
Current fp8 V2 implementation is very limited. We will place close this PR since CK now implementing fp8 v3. We will have new PR for the new CK fp8 v3 integration. |
CK's fp8 col major solver integration into MIOpen