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

graph: backend: kernels: sdp verbose enhancement #2273

Merged
merged 1 commit into from
Dec 26, 2024
Merged

Conversation

rongzha1
Copy link
Contributor

[Graph API] Code quality improvement: enhancement for SDP

@rongzha1 rongzha1 requested a review from a team as a code owner December 16, 2024 08:43
@rongzha1 rongzha1 added the component:graph-api Codeowner: @oneapi-src/onednn-graph label Dec 16, 2024
@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

Copy link
Contributor

@TaoLv TaoLv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please share some verbose examples for these checks.

@rongzha1
Copy link
Contributor Author

Please share some verbose examples for these checks.

for dispatch:

onednn_verbose,v1,graph,create:dispatch,compile,dispatch to sdp_decomp_kernel,src/graph/backend/dnnl/kernels/sdp.hpp:79
onednn_verbose,v1,graph,create:dispatch,compile,dispatch to larger_partition_kernel,src/graph/backend/dnnl/kernels/sdp.hpp:86

for check:

onednn_verbose,v1,graph,create:check,sdp_decomp,Not support select between mm1 and scale,src/graph/backend/dnnl/kernels/sdp_decomp_config.cpp:460
onednn_verbose,v1,graph,create:check,sdp_decomp,Failed to record input offset,src/graph/backend/dnnl/kernels/sdp_decomp_config.cpp:33
onednn_verbose,v1,graph,create:check,sdp_decomp,sdp_decomp_kernel_t: initial check failed,src/graph/backend/dnnl/kernels/sdp_decomp.cpp:56

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

1 similar comment
@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

Copy link
Contributor

@gyhintel gyhintel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add some check on L68, L81, L438, L58, L127, L245, L278 ?

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@rongzha1
Copy link
Contributor Author

Thanks for your comments. L68, L81, L438 fixed, L58, L127, L245, L278 keep them to align primitive style.
Could you review it again ? @gyhintel

}
if (ret != status::success)
VDISPATCH_GRAPH_SDP("fail to dispatch to sdp kernel");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking to simplify the checks. Is it possible to do the check only before return?

if (ret == status::success)
    VDISPATCH_GRAPH_SDP("sdpa is dispatched to (%s)", kernel->str());
else
    VDISPATCH_GRAPH_SDP("sdpa is failed to dispatch");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. changed as suggested

auto op_status = record_input_offset(sg, inputs);
if (op_status != status::success) return false;
VCHECK_SDP_DECOMP(record_input_offset(sg, inputs) == status::success, false,
"Failed to record input offset");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific consideration to wrap the record_input_offset() function into the macro? I feel the below style is easier to read and to step into the function when debug.

auto op_status = record_input_offset(sg, inputs);
VCHECK_SDP_DECOMP(op_status == status::success, false,
            "Failed to record input offset");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the same style as primitive. Since check with msg is already added in record_input_offset
will change it to

CHECK_BOOL(record_input_offset(sg, inputs));

image

image

}
VCHECK_SDP_DECOMP(
batch_size == wei1_user_dims[0] && batch_size == wei2_user_dims[0],
false, "Batch size mismatch");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also print the values of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added in print


// Check scale size
if (graph_inport[2] != -1) {
auto scale_sz = ltw(inputs[graph_inport[2]]).nelems();
if (scale_sz != 1) return false;
VCHECK_SDP_DECOMP(scale_sz == 1, false,
"Scale size in sdp should be 1, but got %d", scale_sz);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to clarify that this is a limitation of the decomp kernel, not sdp.

Suggested change
"Scale size in sdp should be 1, but got %d", scale_sz);
"sdp_decomp_kernel_t only supports single scale value, but got %d", scale_sz);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i see you already have kernel name in the macro, but seems still need to refine. This is a duplication in your example:

onednn_verbose,v1,graph,create:check,sdp_decomp,sdp_decomp_kernel_t: initial check failed,src/graph/backend/dnnl/kernels/sdp_decomp.cpp:56

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has removed the duplicated info. thanks for your advice.

#else
return true;
VCHECK_SDP_DECOMP(batch_size * num_head_q > RATIO * nthr, false,
"Batch size * num_head_q should be larger than %d * nthr", RATIO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a kernel limitation. I'm not sure if the message clarifies that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more info.

@@ -19,6 +19,10 @@

#include "common/compiler_workarounds.hpp"

#define VCHECK_SDP_PRIMITIVE(cond, status, msg, ...) \
VCONDCHECK(graph, create, check, sdp_primitive, (cond), status, msg, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
VCONDCHECK(graph, create, check, sdp_primitive, (cond), status, msg, \
VCONDCHECK(graph, create, check, sdp_primitive_kernel_t, (cond), status, msg, \

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks

}

VCONDCHECK(graph, create, dispatch, sdp, status == status::success, status,
"could not create primitive, falling back\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"could not create primitive, falling back\n");
"could not create sdpa primitive, falling back\n");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thanks

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@rongzha1
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_graph

@TaoLv TaoLv merged commit 68f22a4 into main Dec 26, 2024
13 checks passed
@TaoLv TaoLv deleted the rzhang/verbose_sdp branch December 26, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:graph-api Codeowner: @oneapi-src/onednn-graph
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants