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

[CUDA, DML] MatMul does not properly handle matrices with inner dim == 0 #21483

Open
yuslepukhin opened this issue Jul 24, 2024 · 4 comments
Open
Labels
core runtime issues related to core runtime ep:CUDA issues related to the CUDA execution provider ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot

Comments

@yuslepukhin
Copy link
Member

Describe the issue

MatMul is expected to produce a valid result when it is multiplying matrices with inner dimension equal to zero.
For example, operands of shapes {16,0} x {0, 16} should produce a zero filled matrix of shape {16, 16}.

This is properly supported in CPU EP, but it is confirmed not to work in CUDA and DML providers.

This feature is necessary to support current design of Lora Adapaters in GenAI, as well as for correctness.

To reproduce

CUDA complains about dimensions equal to zero.

Urgency

No response

Platform

Windows

OS Version

Windows 11

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.18.1

ONNX Runtime API

C++

Architecture

X64

Execution Provider

DirectML

Execution Provider Library Version

No response

@yuslepukhin yuslepukhin added ep:DML issues related to the DirectML execution provider core runtime issues related to core runtime ep:CUDA issues related to the CUDA execution provider labels Jul 24, 2024
@github-actions github-actions bot added the platform:windows issues related to the Windows platform label Jul 24, 2024
@fdwr
Copy link
Contributor

fdwr commented Jul 25, 2024

Yeah, that's illegal from the DirectML API validator point of view, multiplying nothing times nothing and expecting something 😉. One could argue the output (since no multiplication actually occurred) should be NaN's instead. Though, why is a model generator producing such a degenerate operation, rather than just outputting a ConstantOfShape or Expand? Is there more context near the pertinent graph region you can show (via Netron) of what operators come before and after?

@skottmckay
Copy link
Contributor

I too was very suprised that you could make magic up data from nothing, and that there was a default value to use which wasn't specified anywhere.

But the spec says "behaves like numpy.matmul" and numpy matul does indeed produce zeros.

@yuslepukhin
Copy link
Member Author

Eigen that powers our CPU EP implementation does the same as numpy.

yuslepukhin added a commit that referenced this issue Aug 13, 2024
### Description
This change addresses a case where we multiply two matrices, and their
inner dimension is 0.
numpy and Eigen which is being used in our CPU EP implementation
correctly handle this case
and output a [M, N] matrix filled with zeros.

### Motivation and Context
This is required to support GenAI empty input Lora implementation.

Addresses: #21483
Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core runtime issues related to core runtime ep:CUDA issues related to the CUDA execution provider ep:DML issues related to the DirectML execution provider platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants