Skip to content

Commit 63009fc

Browse files
committed
Merge branch 'feat/moe-expert-profiling'
2 parents 7dfcaac + 1ebb828 commit 63009fc

4 files changed

Lines changed: 8 additions & 302 deletions

File tree

β€Žtools/moe-pruning/analyze_stats.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
analyze_stats.py -- Summarize expert_stats.json and model size projections.
44
Usage: python analyze_stats.py [stats_file] [--keep 0.5]
55
"""
6-
import json, sys, statistics, argparse
6+
import json, statistics, argparse
77

88
parser = argparse.ArgumentParser()
99
parser.add_argument("stats", nargs="?", default="expert_stats_reap.json")

β€Žtools/moe-pruning/gguf_prune.pyβ€Ž

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
--keep_n 32
3232
"""
3333

34+
from __future__ import annotations
35+
3436
import argparse
3537
import json
3638
import re
37-
import sys
3839
from pathlib import Path
3940

4041
import numpy as np
41-
from gguf import GGUFReader, GGUFWriter, GGMLQuantizationType, GGUFValueType
42+
from gguf import GGUFReader, GGUFWriter, GGUFValueType
4243

4344

4445
# ── Constants ─────────────────────────────────────────────────────────────────
@@ -187,7 +188,7 @@ def main():
187188
kept: dict[int, list[int]] = {}
188189
for tensor in reader.tensors:
189190
il, suffix = layer_and_suffix(tensor.name)
190-
if il is None or not is_expert_suffix(suffix):
191+
if il is None or suffix is None or not is_expert_suffix(suffix):
191192
continue
192193
if il in kept:
193194
continue # already computed for this layer
@@ -222,9 +223,10 @@ def main():
222223
n_pruned = 0
223224
for tensor in reader.tensors:
224225
il, suffix = layer_and_suffix(tensor.name)
225-
is_expert = il is not None and is_expert_suffix(suffix)
226+
is_expert = il is not None and suffix is not None and is_expert_suffix(suffix)
226227

227228
if is_expert:
229+
assert il is not None
228230
k = kept[il]
229231
data = slice_expert_axis(tensor.data, k)
230232
writer.add_tensor(

β€Žtools/moe-pruning/nemotron_reap.pyβ€Ž

Lines changed: 0 additions & 296 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
gguf
1+
gguf

0 commit comments

Comments
Β (0)