-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[GPU] Add dropout support for Ref Matmul #4494
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
Changes from all commits
084c070
af10e01
c0b4899
6834f87
85b04f7
d04c1ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,8 +88,13 @@ __kernel void ref_matmul(__global SRC_DATA_T *A, __global WEI_DATA_T *B, | |
| long c_stride_m, long c_stride_n | ||
| #if WITH_DROPOUT | ||
| , | ||
| __global uchar *dropout_mask_buf, __global uint *dropout_seed_buf, | ||
| __global float *dropout_p_buf | ||
| __global uchar *dropout_mask_buf, | ||
| #if USE_HOST_SCALARS | ||
| long dropout_seed, long dropout_offset, float dropout_p | ||
| #else | ||
| __global SEED_DATA_T *dropout_seed_buf, | ||
| __global long *dropout_offset_buf, __global float *dropout_p_buf | ||
| #endif | ||
| #endif | ||
| #if WITH_SROUND | ||
| , | ||
|
|
@@ -117,10 +122,13 @@ __kernel void ref_matmul(__global SRC_DATA_T *A, __global WEI_DATA_T *B, | |
| #endif | ||
|
|
||
| #if WITH_DROPOUT | ||
| uint dropout_seed = dropout_seed_buf[0]; | ||
| uint dropout_threshold = get_dropout_threshold(dropout_p_buf[0]); | ||
| float dropout_inv_q | ||
| = (dropout_p_buf[0] != 1.f) ? 1.f / (1.f - dropout_p_buf[0]) : 0.f; | ||
| #if !USE_HOST_SCALARS | ||
| SEED_DATA_T dropout_seed = dropout_seed_buf[0]; | ||
| long dropout_offset = USE_OFFSET ? dropout_offset_buf[0] : 0; | ||
| float dropout_p = dropout_p_buf[0]; | ||
| #endif | ||
| uint dropout_threshold = get_dropout_threshold(dropout_p); | ||
| float dropout_inv_q = (dropout_p != 1.f) ? 1.f / (1.f - dropout_p) : 0.f; | ||
| #endif | ||
| #if WITH_SROUND | ||
| uint sround_seed = sround_seed_buf[0]; | ||
|
|
@@ -286,11 +294,18 @@ __kernel void ref_matmul(__global SRC_DATA_T *A, __global WEI_DATA_T *B, | |
| float po_acc = convert_float(temp); | ||
|
|
||
| #if WITH_DROPOUT | ||
| uint res = philox_4x32(dst_off, dropout_seed); | ||
| #if USE_OFFSET | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should check if SEED_DATA_T is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! the offset will already be set to zero if use_offset = 0, but this condition is misleading.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/uxlfoundation/oneDNN/blob/main/src/cpu/primitive_attr_postops.cpp#L304 - based on this condition use_offset is the precursor between the two philox functions used. Will stick with what I have by adding explicit conversion to seed for philox without offset. Changing condition will mean I will have to add another similar function to cater for s64 philox without seed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively you could have two versions of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We strictly like to keep the code between cpu/gpu same. Additionally if I do add another philox function, it will be just repeating the same code with lesser lines. |
||
| uint res = philox_4x32_s64( | ||
| dst_off, (ulong)dropout_seed, (ulong)dropout_offset); | ||
| #else | ||
| uint res = philox_4x32((uint)dst_off, (uint)dropout_seed); | ||
| #endif | ||
| uchar dropout = res > dropout_threshold; | ||
| po_acc = (dropout) ? po_acc * dropout_inv_q : 0; | ||
| #if HAS_OUTPUT_MASK | ||
| dropout_mask_buf[dst_off] = dropout; | ||
| #endif | ||
| #endif | ||
|
|
||
| #if WITH_SROUND | ||
| po_acc = stochastic_round_fwd(po_acc, dst_off, sround_seed); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| --attr-fpmath=,bf16 | ||
| --check-ref-impl=false | ||
|
|
||
| --attr-dropout=0.5:12345678,0.75:12345678:undef,0.25:843921:any:1238976:true | ||
| --attr-dropout=0.5:12345678,0.75:12345678:undef,0.25:843921:any:1238976:true,0.75:111786:any:121716:false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we able to specify s32/s64 seed type from benchdnn? it might be worth verifying both if theyre still supported.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So benchdnn only supports s64 as a standard. We are keeping s32 for older test-pathways. I checked the s32 datatype here by making the change here: https://github.com/uxlfoundation/oneDNN/blob/main/tests/benchdnn/dnn_types.cpp#L1449-L1454 |
||
|
|
||
| --stag=ab --dtag=ab | ||
| --batch=shapes_2d | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.