Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include "core/optimizer/graph_transformer.h"
#include "core/framework/ort_value.h"
#include <memory>
#include "core/framework/execution_provider.h"
 
namespace onnxruntime {
 
/**
@class ConstantFolding
 
Transformer that traverses the graph top-down and performs constant folding, i.e.,
it statically computes parts of the graph that rely only on constant initializers.
*/
class ConstantFolding : public GraphTransformer {
 public:
  /*! Constant folding will not be applied to nodes that have one of initializers from excluded_initializers as input.
      For pre-training, the trainable weights are those initializers to be excluded.
      \param execution_provider Execution provider instance to execute constant folding.
  */
  ConstantFolding(const IExecutionProvider& execution_provider,
                  bool skip_dequantize_linear,
                  const ConfigOptions& config_options,
                  const InlinedHashSet<std::string_view>& compatible_execution_providers = {},
                  const InlinedHashSet<std::string>& excluded_initializers = {}) noexcept;
 
 protected:
  /**
   * Same as the constructor above but with a name provided by derived class.
   */
  ConstantFolding(const std::string& name,
                  const IExecutionProvider& execution_provider,
                  bool skip_dequantize_linear,
                  const ConfigOptions& config_options,
                  const InlinedHashSet<std::string_view>& compatible_execution_providers = {},
                  const InlinedHashSet<std::string>& excluded_initializers = {}) noexcept;
  /**
   * Derived class can implement this virtual function to limit the nodes that can be constant folded.
   */
  virtual bool AllowConstantFolding(const Node& node) const {
    ORT_UNUSED_PARAMETER(node);
    return true;
  }
 
 private:
  Status ApplyImpl(Graph& graph, bool& modified, int graph_level, const logging::Logger& logger) const override;
 
  bool skip_dequantize_linear_;
  const ConfigOptions& config_options_;
  const InlinedHashSet<std::string> excluded_initializers_;
  const IExecutionProvider& execution_provider_;
};
 
}  // namespace onnxruntime