File indexing completed on 2025-04-03 08:57:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <memory>
0012 #include <vector>
0013
0014 #include "onnx/version_converter/adapters/adapter.h"
0015
0016 namespace ONNX_NAMESPACE {
0017 namespace version_conversion {
0018
0019 class Gemm_6_7 final : public Adapter {
0020 public:
0021 explicit Gemm_6_7() : Adapter("Gemm", OpSetID(6), OpSetID(7)) {}
0022
0023 void adapt_gemm_6_7(std::shared_ptr<Graph>, Node* node) const {
0024 const ArrayRef<Value*>& inputs = node->inputs();
0025 assertInputsAvailable(inputs, name().c_str(), 3);
0026 const auto& A_shape = inputs[0]->sizes();
0027 const auto& B_shape = inputs[1]->sizes();
0028
0029 const auto& C_shape = inputs[2]->sizes();
0030
0031 std::vector<Dimension> MN;
0032 if (node->hasAttribute(ktransA) && node->i(ktransA) == 1) {
0033 MN.emplace_back(A_shape[1]);
0034 } else {
0035 MN.emplace_back(A_shape[0]);
0036 }
0037 if (node->hasAttribute(ktransB) && node->i(ktransB) == 1) {
0038 MN.emplace_back(B_shape[0]);
0039 } else {
0040 MN.emplace_back(B_shape[1]);
0041 }
0042 ONNX_ASSERTM(
0043 check_numpy_unibroadcastable_and_require_broadcast(MN, C_shape) != -1,
0044 "Gemm being converted from 6 to 7 does not have "
0045 "broadcastable inputs.");
0046 if (node->hasAttribute(kbroadcast))
0047 node->removeAttribute(kbroadcast);
0048 }
0049
0050 Node* adapt(std::shared_ptr<Graph> graph, Node* node) const override {
0051 adapt_gemm_6_7(graph, node);
0052 return node;
0053 }
0054 };
0055
0056 }
0057 }