Исходный код СУБД 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
59
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <optional>
#include <string>
#include <string_view>
 
#include "core/common/inlined_containers.h"
#include "core/common/status.h"
#include "core/framework/tensor_shape.h"
 
namespace onnxruntime {
 
/// Input shape overrides supplied by the user for estimation.
using MaxShapeOverrideMap = InlinedHashMap<std::string, TensorShape>;
 
/// Fully concrete shapes inferred in a disposable shadow graph for workspace estimation.
/// Shapes are grouped by source Graph identity so equal NodeArg names in nested graphs
/// remain distinct. The executable graph is never modified. Inferred downstream shapes
/// are estimation hints and are not guaranteed upper bounds because operator shape
/// transformations are not necessarily monotonic.
class MaxShapeInferenceResult {
 public:
  /// graph_identity must be the address of the source Graph passed to InferMaxShapes.
  const TensorShape* GetShape(const void* graph_identity, const std::string& node_arg_name) const {
    const auto graph_it = graph_shapes_.find(graph_identity);
    if (graph_it == graph_shapes_.end()) return nullptr;
    const auto shape_it = graph_it->second.find(node_arg_name);
    return shape_it == graph_it->second.end() ? nullptr : &shape_it->second;
  }
 
  bool Empty() const noexcept { return graph_shapes_.empty(); }
 
 private:
  friend class MaxShapeInferenceBuilder;
  using ShapeMap = InlinedHashMap<std::string, TensorShape>;
  InlinedHashMap<const void*, ShapeMap> graph_shapes_;
};
 
/// Parses the session.max_shape_override config string into a name -> shape map.
///
/// Format: "name1:[d0,d1,...];name2:[d0,d1,...]"
/// Example: "input_ids:[8,4096];attention_mask:[8,4096]"
///
/// Rules:
/// - Names and dimensions are separated by semicolons.
/// - Each entry is "name:[dim0,dim1,...]".
/// - Dimensions must be positive integers.
/// - Whitespace around names, brackets, and commas is tolerated.
/// - Empty string returns an empty map (success).
///
/// @param config_value  The raw string from the session option.
/// @param out           Populated on success.
/// @return              OK on success, INVALID_ARGUMENT on parse failure.
Status ParseMaxShapeOverride(std::string_view config_value, MaxShapeOverrideMap& out);
 
}  // namespace onnxruntime