Upload classifier.py with huggingface_hub
Browse files- classifier.py +18 -2
classifier.py
CHANGED
|
@@ -635,7 +635,8 @@ def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
|
| 635 |
relief_thr: float = -0.5,
|
| 636 |
allowed_tiers: list | None = None,
|
| 637 |
legacy_1d: bool = False,
|
| 638 |
-
ceiling: str | None = None
|
|
|
|
| 639 |
"""relief: {sweep_unit_tag: Q5->Q4 damage}. Groups with damage below
|
| 640 |
relief_thr get ceiling Q4 (their measured sweet spot): the queue never
|
| 641 |
upgrades them above Q4, and the saved budget flows to other groups.
|
|
@@ -698,6 +699,18 @@ def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
|
| 698 |
} if not free_pins else set()
|
| 699 |
non_mtp_names -= router_names
|
| 700 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
tensor_importance = {}
|
| 702 |
for name in non_mtp_names:
|
| 703 |
raw_imp = importance_table.get(name, {}).get("importance_mean", 0.0)
|
|
@@ -710,6 +723,8 @@ def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
|
| 710 |
assignments[n] = EMBD_DEPLOY_TIER
|
| 711 |
for n in router_names:
|
| 712 |
assignments[n] = "F16"
|
|
|
|
|
|
|
| 713 |
group_registry = build_groups(tied_groups, non_mtp_names, ne_map, padded_ne_map,
|
| 714 |
f32_map=f32_map)
|
| 715 |
|
|
@@ -728,7 +743,8 @@ def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
|
| 728 |
mtp_cost = sum(_size_mib(MTP_DEPLOY_TIER, ne_map.get(n, 0), f32_map.get(n, False)) for n in mtp_names)
|
| 729 |
embd_cost = sum(_size_mib(EMBD_DEPLOY_TIER, ne_map.get(n, 0), f32_map.get(n, False)) for n in embd_names)
|
| 730 |
router_cost = sum(_size_mib("F16", ne_map.get(n, 0), f32_map.get(n, False)) for n in router_names)
|
| 731 |
-
|
|
|
|
| 732 |
|
| 733 |
current_size = sum(
|
| 734 |
_size_mib(assignments[n],
|
|
|
|
| 635 |
relief_thr: float = -0.5,
|
| 636 |
allowed_tiers: list | None = None,
|
| 637 |
legacy_1d: bool = False,
|
| 638 |
+
ceiling: str | None = None,
|
| 639 |
+
pin_small: float = 0.0) -> Tuple[dict, dict]:
|
| 640 |
"""relief: {sweep_unit_tag: Q5->Q4 damage}. Groups with damage below
|
| 641 |
relief_thr get ceiling Q4 (their measured sweet spot): the queue never
|
| 642 |
upgrades them above Q4, and the saved budget flows to other groups.
|
|
|
|
| 699 |
} if not free_pins else set()
|
| 700 |
non_mtp_names -= router_names
|
| 701 |
|
| 702 |
+
# --pin-small: tensors under pin_small MiB (F16 weight) join the F16 pin,
|
| 703 |
+
# outside the budget. Rationale: sub-MiB tensors cost nothing to protect
|
| 704 |
+
# and carry control-plane roles (k/v heads, gates). 1D tensors land F32
|
| 705 |
+
# by the binary's law regardless; the preflight says so loudly.
|
| 706 |
+
small_names = set()
|
| 707 |
+
if pin_small > 0 and not free_pins:
|
| 708 |
+
small_names = {
|
| 709 |
+
n for n in non_mtp_names
|
| 710 |
+
if ne_map.get(n, 0) * 2.0 / (1024 * 1024) < pin_small
|
| 711 |
+
}
|
| 712 |
+
non_mtp_names -= small_names
|
| 713 |
+
|
| 714 |
tensor_importance = {}
|
| 715 |
for name in non_mtp_names:
|
| 716 |
raw_imp = importance_table.get(name, {}).get("importance_mean", 0.0)
|
|
|
|
| 723 |
assignments[n] = EMBD_DEPLOY_TIER
|
| 724 |
for n in router_names:
|
| 725 |
assignments[n] = "F16"
|
| 726 |
+
for n in small_names:
|
| 727 |
+
assignments[n] = "F16"
|
| 728 |
group_registry = build_groups(tied_groups, non_mtp_names, ne_map, padded_ne_map,
|
| 729 |
f32_map=f32_map)
|
| 730 |
|
|
|
|
| 743 |
mtp_cost = sum(_size_mib(MTP_DEPLOY_TIER, ne_map.get(n, 0), f32_map.get(n, False)) for n in mtp_names)
|
| 744 |
embd_cost = sum(_size_mib(EMBD_DEPLOY_TIER, ne_map.get(n, 0), f32_map.get(n, False)) for n in embd_names)
|
| 745 |
router_cost = sum(_size_mib("F16", ne_map.get(n, 0), f32_map.get(n, False)) for n in router_names)
|
| 746 |
+
small_cost = sum(_size_mib("F16", ne_map.get(n, 0), f32_map.get(n, False)) for n in small_names)
|
| 747 |
+
effective_target = target_size_mib - mtp_cost - embd_cost - router_cost - small_cost
|
| 748 |
|
| 749 |
current_size = sum(
|
| 750 |
_size_mib(assignments[n],
|