forked from Luce-Org/lucebox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmoe_hybrid_routing_stats.h
More file actions
53 lines (39 loc) · 1.62 KB
/
Copy pathmoe_hybrid_routing_stats.h
File metadata and controls
53 lines (39 loc) · 1.62 KB
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
// Common MoE routing statistics for expert placement decisions.
#pragma once
#include "moe_hybrid_types.h"
#include "ggml.h"
#include "ggml-backend.h"
#include <cstdint>
#include <string>
#include <vector>
namespace dflash::common {
struct MoeHybridRoutingStats {
int n_layer = 0;
int n_expert = 0;
int n_expert_used = 0;
// Flattened [n_layer][n_expert] activation counts.
std::vector<uint64_t> counts;
std::vector<uint64_t> layer_totals;
bool init(int n_layer, int n_expert, int n_expert_used);
bool init(const MoeHybridConfig & cfg);
bool matches(int n_layer, int n_expert, int n_expert_used) const;
bool matches(const MoeHybridConfig & cfg) const;
bool empty() const;
uint64_t count(int layer_idx, int expert_idx) const;
bool observe(int layer_idx, const int32_t * expert_ids, int n_ids);
bool observe_selected_tensor(ggml_backend_t backend,
int layer_idx,
ggml_tensor * selected,
std::string * err = nullptr);
std::vector<int> ranked_experts(int layer_idx) const;
std::vector<int> hot_experts(int layer_idx, int hot_count) const;
// Print StreamMoE-style frequency analysis to stderr.
void print_freq_analysis() const;
bool save_csv(const std::string & path, std::string * err = nullptr) const;
static bool load_csv(const std::string & path,
MoeHybridRoutingStats & out,
std::string * err = nullptr);
private:
size_t index_of(int layer_idx, int expert_idx) const;
};
} // namespace dflash::common