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

[Packing Refactor] Move all Blockwise Packing to pack_weights_and_bias #7544

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mcr229
Copy link
Contributor

@mcr229 mcr229 commented Dec 2, 2024

Packing in the fully-connected operator level APIs has become quite messy because of the separate packing signatures for pack_gemm_goi and pack_gemm_goi_bl. To clean this up, we move the packing(and scale + bias initialization) into a new pack_weights_and_bias function.

One change from this is that we have to add the block_size argument to the signature of xnn_pack_weights_and_biases_fn. This is largely unused for most packing functions. Another change to make this cleaner requires including the microparams-init.h header in the reference/packing.cc file.

See:
src/operators/fully-connected-nc.c

for the cleaning up of the packing.

/*extra_bytes_n=*/nr * extra_bytes_n,
/*params*/(const struct xnn_qs8_qc4w_packing_params *)params);
} else {
xnn_pack_qs8_qb4w_gemm_goi_w(
Copy link
Contributor

Choose a reason for hiding this comment

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

can these use gemm-config to set the packw microkernels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean using something like:

gemm_config->packw_gemm_goi(

I was contemplating this but i was looking at config-types.h:

// TODO(b/346765736): Replace all uses of packing functions with this.
xnn_pack_weights_and_biases_fn pack_weights_and_biases;
xnn_packed_stride_weights_and_biases_fn packed_stride_weights_and_biases;
// Deprecated. Use pack_weights_and_biases instead.
xnn_packw_gemm_gio_ukernel_fn pack_gemm_gio;
// Deprecated. Use pack_weights_and_biases instead.
xnn_packw_gemm_goi_ukernel_fn pack_gemm_goi;
// TODO(b/346765736): Use pack_weights_and_biases instead.
xnn_packw_gemm_goi_bl_ukernel_fn pack_gemm_goi_bl;

and there seem to be active tasks to instead move all of these into pack_weights_and_biases instead. So I went ahead and helped towards this by removing packw_gemm_goi_bl from the config types. Not sure what the intended direction for this is though. Perhaps @alankelly can chime in.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the correct way of calling packing functions. Thanks for the clean up, this is much better

Copy link
Contributor Author

@mcr229 mcr229 Dec 3, 2024

Choose a reason for hiding this comment

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

i was discussing with @fbarchard and I think we might want to keep the

xnn_packw_gemm_goi_bl_ukernel_fn pack_gemm_goi_bl; 

in the config-types so that we can specify the non reference packing ukernels in gemm-config, and the pack_weights_and_biases will pull the actual packing ukernel from the gemm-config. So in a sense pack_weights_and_biases will be the wrapper around packw_gemm_goi_ukernel, and will also fill in scales, biases at the same time.

Was wondering if you had any thoughts on that

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 not sure where those deprecated comments came from but my main concern is that the pack_weights_and_biases is hard coded to the reference packing functions, preventing them from being removed in favor of scalar microkernels.

If we can make them call the configured microkernels, performance would be improved.

Secondary concern is that GIO packing is a transpose compared to GOI. Unless there is a usecase, the GIO packing functions will likely be less optimized scalar kernels.

I've noticed packing signature mismatches. I think this occurred when params were changed in packing.cc but the packw microkernels were not updated to the same signature.
They should match. Whatever signature packing.cc has, the packw should be idential, and the function pointers, tests and benchmarks should be able to use the microkernels.

@mcr229
Copy link
Contributor Author

mcr229 commented Dec 9, 2024

hi @alankelly I added back

xnn_packw_gemm_goi_bl_ukernel_fn pack_gemm_goi_bl; 

As I think it might be useful in the future, would appreciate another look Thanks!

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

Successfully merging this pull request may close these issues.

3 participants