Skip to content

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

Closed as not planned

Description

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

Activity

  1. added
    ep:DMLissues related to the DirectML execution provider
    core runtimeissues related to core runtime
    ep:CUDAissues related to the CUDA execution provider
    on Jul 24, 2024
  2. fdwr commented on Jul 25, 2024

    @fdwr
    Contributor

    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?

  3. skottmckay commented on Jul 26, 2024

    @skottmckay
    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.

  4. yuslepukhin commented on Jul 26, 2024

    @yuslepukhin
    ContributorAuthor

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

  5. github-actions commented on Aug 26, 2024

    @github-actions
    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.

  6. added
    staleissues that have not been addressed in a while; categorized by a bot
    on Aug 26, 2024
  7. snnn commented on Jun 7, 2025

    @snnn
    Contributor

    This issue has been automatically closed as 'not planned' because it has been marked as 'stale' for more than 30 days without activity. If you believe this is still an issue, please feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core runtimeissues related to core runtimeep:CUDAissues related to the CUDA execution providerep:DMLissues related to the DirectML execution providerplatform:windowsissues related to the Windows platformstaleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions