// Copyright (c) ONNX Project Contributors // // SPDX-License-Identifier: Apache-2.0 // Adapter for all ops that remove consumed_inputs #pragma once #include #include #include #include "onnx/version_converter/adapters/adapter.h" namespace ONNX_NAMESPACE::version_conversion { class AxesAttributeToInput : public Adapter { public: explicit AxesAttributeToInput(const std::string& op_name, const OpSetID& initial, const OpSetID& target) : Adapter(op_name, initial, target) {} void attrToInput(const std::shared_ptr& graph, Node* node, const std::vector& axes) const { Tensor t; t.elem_type() = TensorProto_DataType_INT64; t.sizes() = std::vector{static_cast(axes.size())}; auto& data = t.int64s(); for (auto a : axes) { data.emplace_back(a); } Node* constant = graph->create(kConstant); constant->insertBefore(node); constant->t_(kvalue, t); node->addInput(constant->output()); } Node* adapt(std::shared_ptr graph, Node* node) const override { if (node->hasAttribute(kaxes)) { attrToInput(graph, node, node->is(kaxes)); node->removeAttribute(kaxes); } return node; } }; } // namespace ONNX_NAMESPACE::version_conversion