Skip to content

[Operators] Add batch support for x86 CPU matrix multiplication + resolve rule#415

Closed
BolinSNLHM wants to merge 162 commits intohidet-org:mainfrom
BolinSNLHM:gpt2-benchmark
Closed

[Operators] Add batch support for x86 CPU matrix multiplication + resolve rule#415
BolinSNLHM wants to merge 162 commits intohidet-org:mainfrom
BolinSNLHM:gpt2-benchmark

Conversation

@BolinSNLHM
Copy link
Copy Markdown
Contributor

Preliminary performance testing results compared to PyTorch:
batchsize-16
batchsize-8
batchsize-4
batchsize-2
batchsize-1

Copy link
Copy Markdown
Member

@yaoyaoding yaoyaoding left a comment

Choose a reason for hiding this comment

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

Thanks @BolinSNLHM !

Glad to see that you extend it to batch version. But there are still something we can do to make it better. See the comments below.

inputs=[a, b],
outputs=[c],
attributes={'m_size': a_shape[-2], 'n_size': b_shape[-1], 'k_size': a_shape[-1]},
attributes={'batch_size': batch_size, 'm_size': m_size, 'n_size': n_size, 'k_size': k_size},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use this function https://github.com/hidet-org/hidet/blob/main/python/hidet/ir/compute/cops/matmul.py#L30 to add computation definition for matmul.

Like

c = cops.matmul(a, b, allow_1d=True)

Comment on lines +857 to +858
and (not is_constant(a.shape[0], b.shape[0]) or a.shape[0] == b.shape[0])
and (not is_constant(a.shape[2], b.shape[1]) or a.shape[2] == b.shape[1])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you require the shape of a and b constant?

Is it possible to support dynamic shape like https://github.com/hidet-org/hidet/blob/main/python/hidet/graph/ops/matmul/batch_matmul.py

# if not (len(a.shape) == len(b.shape) == 2 and a.shape[1] == b.shape[0]):
# raise ValueError('Matrix multiplication: incompatible sizes: {} and {}'.format(a.shape, b.shape))
if not (
len(a.shape) == len(b.shape) == 3
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use the same template to support matmul like:

  • [12, 1024, 1024] @ [1024, 1024]
  • [12, 1024, 1024] @ [1, 1024, 1024]
  • [1024, 1024] @ [4, 5, 1024, 1024]

You can have a look at https://github.com/hidet-org/hidet/blob/main/python/hidet/graph/ops/matmul/batch_matmul.py as a reference.

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.

2 participants