wepiqx commited on
Commit
e4df74e
·
verified ·
1 Parent(s): 794b73f

Upload scripts/auto_fuse.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/auto_fuse.py +18 -5
scripts/auto_fuse.py CHANGED
@@ -41,14 +41,17 @@ def load_imatrix(path):
41
  return read_imatrix(path)["tensors"]
42
 
43
 
44
- def rank_vote(ia, ib, ic=None, base="a"):
45
  """Best relative rank wins. Returns {block: donor} for non-base wins."""
46
  donors = {"a": ia, "b": ib}
47
  if ic is not None:
48
  donors["c"] = ic
 
 
49
  common = set(ia) & set(ib)
50
- if ic is not None:
51
- common &= set(ic)
 
52
  per = {k: defaultdict(list) for k in donors}
53
  for n in common:
54
  b = layer_of(n)
@@ -91,9 +94,11 @@ def main():
91
  ap.add_argument("--a", required=True)
92
  ap.add_argument("--b", required=True)
93
  ap.add_argument("--c", default=None)
 
94
  ap.add_argument("--ia", required=True, help="imatrix for A")
95
  ap.add_argument("--ib", required=True, help="imatrix for B")
96
  ap.add_argument("--ic", default=None, help="imatrix for C")
 
97
  ap.add_argument("--rule", choices=["rank-vote"], default="rank-vote")
98
  ap.add_argument("--patch", default=None,
99
  help="manual overrides, e.g. '31:c'")
@@ -103,9 +108,15 @@ def main():
103
 
104
  ia, ib = load_imatrix(args.ia), load_imatrix(args.ib)
105
  ic = load_imatrix(args.ic) if args.ic and args.c else None
106
- amap = rank_vote(ia, ib, ic)
 
 
 
 
 
 
107
  amap.update(parse_patch(args.patch))
108
- letters = {"a": "A", "b": "B", "c": "C"}
109
  desc = ", ".join(f"{b}:{letters[d]}" for b, d in sorted(amap.items()))
110
  print("auto map (%s): %s" % (args.rule, desc or "(all base)"))
111
  print(json.dumps({"rule": args.rule, "map": amap}))
@@ -118,6 +129,8 @@ def main():
118
  "--map", ",".join(f"{b}:{d}" for b, d in sorted(amap.items()))]
119
  if args.c:
120
  cmd += ["--c", args.c]
 
 
121
  print("exec:", " ".join(cmd), flush=True)
122
  rc = subprocess.call(cmd)
123
  if rc != 0:
 
41
  return read_imatrix(path)["tensors"]
42
 
43
 
44
+ def rank_vote(ia, ib, ic=None, idn=None, base="a"):
45
  """Best relative rank wins. Returns {block: donor} for non-base wins."""
46
  donors = {"a": ia, "b": ib}
47
  if ic is not None:
48
  donors["c"] = ic
49
+ if idn is not None:
50
+ donors["d"] = idn
51
  common = set(ia) & set(ib)
52
+ for extra in (ic, idn):
53
+ if extra is not None:
54
+ common &= set(extra)
55
  per = {k: defaultdict(list) for k in donors}
56
  for n in common:
57
  b = layer_of(n)
 
94
  ap.add_argument("--a", required=True)
95
  ap.add_argument("--b", required=True)
96
  ap.add_argument("--c", default=None)
97
+ ap.add_argument("--d", default=None, help="fourth donor BF16")
98
  ap.add_argument("--ia", required=True, help="imatrix for A")
99
  ap.add_argument("--ib", required=True, help="imatrix for B")
100
  ap.add_argument("--ic", default=None, help="imatrix for C")
101
+ ap.add_argument("--id", default=None, help="imatrix for D")
102
  ap.add_argument("--rule", choices=["rank-vote"], default="rank-vote")
103
  ap.add_argument("--patch", default=None,
104
  help="manual overrides, e.g. '31:c'")
 
108
 
109
  ia, ib = load_imatrix(args.ia), load_imatrix(args.ib)
110
  ic = load_imatrix(args.ic) if args.ic and args.c else None
111
+ idn = load_imatrix(args.id) if args.id and args.d else None
112
+ donors = {"a": ia, "b": ib}
113
+ if ic is not None:
114
+ donors["c"] = ic
115
+ if idn is not None:
116
+ donors["d"] = idn
117
+ amap = rank_vote(ia, ib, ic, idn)
118
  amap.update(parse_patch(args.patch))
119
+ letters = {"a": "A", "b": "B", "c": "C", "d": "D"}
120
  desc = ", ".join(f"{b}:{letters[d]}" for b, d in sorted(amap.items()))
121
  print("auto map (%s): %s" % (args.rule, desc or "(all base)"))
122
  print(json.dumps({"rule": args.rule, "map": amap}))
 
129
  "--map", ",".join(f"{b}:{d}" for b, d in sorted(amap.items()))]
130
  if args.c:
131
  cmd += ["--c", args.c]
132
+ if args.d:
133
+ cmd += ["--d", args.d]
134
  print("exec:", " ".join(cmd), flush=True)
135
  rc = subprocess.call(cmd)
136
  if rc != 0: