Исходный код СУБД 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.
 
#include "core/framework/kernel_pilot_moe_expert_selection.h"
 
#include <algorithm>
 
namespace onnxruntime {
 
KernelPilotMoeExpertSelection::KernelPilotMoeExpertSelection() = default;
 
Status KernelPilotMoeExpertSelection::BeginInvocation(size_t expert_count) {
  ORT_RETURN_IF(expert_count == 0, "MoE expert selection requires a positive expert count.");
  expert_count_ = expert_count;
  // Unlike clear(), erasing preserves InlinedVector's allocated storage.
  selected_experts_.erase(selected_experts_.begin(), selected_experts_.end());
  selected_experts_.reserve(expert_count);
  invocation_pending_ = true;
  return Status::OK();
}
 
bool KernelPilotMoeExpertSelection::IsInitialized() const noexcept {
  return expert_count_ != 0;
}
 
size_t KernelPilotMoeExpertSelection::ExpertCount() const noexcept {
  return expert_count_;
}
 
Status KernelPilotMoeExpertSelection::Collect(gsl::span<const int> expert_ids) {
  ORT_RETURN_IF_NOT(IsInitialized(), "MoE expert selection was not initialized.");
  for (int expert : expert_ids) {
    ORT_RETURN_IF(expert < 0 || static_cast<size_t>(expert) >= expert_count_,
                  "MoE expert index out of range: ", expert);
  }
  for (int expert : expert_ids) {
    if (std::find(selected_experts_.begin(), selected_experts_.end(), expert) == selected_experts_.end()) {
      selected_experts_.push_back(expert);
    }
  }
  return Status::OK();
}
 
Status KernelPilotMoeExpertSelection::GetSelectedExperts(gsl::span<const int>& expert_ids) const {
  ORT_RETURN_IF_NOT(IsInitialized(), "MoE expert selection was not initialized.");
  expert_ids = selected_experts_;
  return Status::OK();
}
 
bool KernelPilotMoeExpertSelection::HasPendingInvocation() const noexcept {
  return invocation_pending_;
}
 
void KernelPilotMoeExpertSelection::FinishInvocation() noexcept {
  invocation_pending_ = false;
}
 
}  // namespace onnxruntime