Upload classifier.py with huggingface_hub
Browse files- classifier.py +11 -8
classifier.py
CHANGED
|
@@ -178,12 +178,13 @@ def build_groups(tied_groups: List[List[str]], non_mtp_names: Set[str],
|
|
| 178 |
|
| 179 |
|
| 180 |
def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
| 181 |
-
target_size_mib: float, allow_q3: bool = False
|
|
|
|
| 182 |
if target_size_mib <= 0:
|
| 183 |
raise ValueError("target_size_mib must be positive")
|
| 184 |
|
| 185 |
features = model.get("features", {})
|
| 186 |
-
has_mtp = features.get("has_mtp", False)
|
| 187 |
n_layers = features.get("n_layers", 31)
|
| 188 |
is_qat = features.get("is_qat", False)
|
| 189 |
model_tensors = model.get("tensors", {})
|
|
@@ -210,17 +211,18 @@ def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
|
| 210 |
|
| 211 |
# Pinned output/token_embd: fixed tier, excluded from budget and upgrades
|
| 212 |
# (llama.cpp writes them at the output/token types unconditionally).
|
|
|
|
| 213 |
embd_names = {
|
| 214 |
n for n in non_mtp_names
|
| 215 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in EMBD_PIN_TYPES
|
| 216 |
-
}
|
| 217 |
non_mtp_names -= embd_names
|
| 218 |
|
| 219 |
# Pinned MoE routers: always F16, outside the budget.
|
| 220 |
router_names = {
|
| 221 |
n for n in non_mtp_names
|
| 222 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in ROUTER_PIN_TYPES
|
| 223 |
-
}
|
| 224 |
non_mtp_names -= router_names
|
| 225 |
|
| 226 |
tensor_importance = {}
|
|
@@ -327,13 +329,14 @@ def _push_downgrade(group_id: int,
|
|
| 327 |
|
| 328 |
|
| 329 |
def optimal_classify_topdown(importance_table: dict, tied_groups: list, model: dict,
|
| 330 |
-
target_size_mib: float, allow_q3: bool = False
|
|
|
|
| 331 |
"""Top-down classification: start at F16, downgrade to fit."""
|
| 332 |
if target_size_mib <= 0:
|
| 333 |
raise ValueError("target_size_mib must be positive")
|
| 334 |
|
| 335 |
features = model.get("features", {})
|
| 336 |
-
has_mtp = features.get("has_mtp", False)
|
| 337 |
n_layers = features.get("n_layers", 31)
|
| 338 |
is_qat = features.get("is_qat", False)
|
| 339 |
model_tensors = model.get("tensors", {})
|
|
@@ -360,7 +363,7 @@ def optimal_classify_topdown(importance_table: dict, tied_groups: list, model: d
|
|
| 360 |
embd_names = {
|
| 361 |
n for n in rest
|
| 362 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in EMBD_PIN_TYPES
|
| 363 |
-
}
|
| 364 |
# No pinning here: literally every other tensor (norms, 1D, biases —
|
| 365 |
# anything) starts at F16 and fights for budget — except MoE routers,
|
| 366 |
# which stay F16 outside the budget. Note the estimate assumes the binary
|
|
@@ -370,7 +373,7 @@ def optimal_classify_topdown(importance_table: dict, tied_groups: list, model: d
|
|
| 370 |
router_names = {
|
| 371 |
n for n in flex_names
|
| 372 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in ROUTER_PIN_TYPES
|
| 373 |
-
}
|
| 374 |
flex_names -= router_names
|
| 375 |
|
| 376 |
tensor_importance = {}
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
def optimal_classify(importance_table: dict, tied_groups: list, model: dict,
|
| 181 |
+
target_size_mib: float, allow_q3: bool = False,
|
| 182 |
+
free_pins: bool = False) -> Tuple[dict, dict]:
|
| 183 |
if target_size_mib <= 0:
|
| 184 |
raise ValueError("target_size_mib must be positive")
|
| 185 |
|
| 186 |
features = model.get("features", {})
|
| 187 |
+
has_mtp = features.get("has_mtp", False) and not free_pins
|
| 188 |
n_layers = features.get("n_layers", 31)
|
| 189 |
is_qat = features.get("is_qat", False)
|
| 190 |
model_tensors = model.get("tensors", {})
|
|
|
|
| 211 |
|
| 212 |
# Pinned output/token_embd: fixed tier, excluded from budget and upgrades
|
| 213 |
# (llama.cpp writes them at the output/token types unconditionally).
|
| 214 |
+
# --free-pins: experiment — they join the normal pool instead.
|
| 215 |
embd_names = {
|
| 216 |
n for n in non_mtp_names
|
| 217 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in EMBD_PIN_TYPES
|
| 218 |
+
} if not free_pins else set()
|
| 219 |
non_mtp_names -= embd_names
|
| 220 |
|
| 221 |
# Pinned MoE routers: always F16, outside the budget.
|
| 222 |
router_names = {
|
| 223 |
n for n in non_mtp_names
|
| 224 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in ROUTER_PIN_TYPES
|
| 225 |
+
} if not free_pins else set()
|
| 226 |
non_mtp_names -= router_names
|
| 227 |
|
| 228 |
tensor_importance = {}
|
|
|
|
| 329 |
|
| 330 |
|
| 331 |
def optimal_classify_topdown(importance_table: dict, tied_groups: list, model: dict,
|
| 332 |
+
target_size_mib: float, allow_q3: bool = False,
|
| 333 |
+
free_pins: bool = False) -> Tuple[dict, dict]:
|
| 334 |
"""Top-down classification: start at F16, downgrade to fit."""
|
| 335 |
if target_size_mib <= 0:
|
| 336 |
raise ValueError("target_size_mib must be positive")
|
| 337 |
|
| 338 |
features = model.get("features", {})
|
| 339 |
+
has_mtp = features.get("has_mtp", False) and not free_pins
|
| 340 |
n_layers = features.get("n_layers", 31)
|
| 341 |
is_qat = features.get("is_qat", False)
|
| 342 |
model_tensors = model.get("tensors", {})
|
|
|
|
| 363 |
embd_names = {
|
| 364 |
n for n in rest
|
| 365 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in EMBD_PIN_TYPES
|
| 366 |
+
} if not free_pins else set()
|
| 367 |
# No pinning here: literally every other tensor (norms, 1D, biases —
|
| 368 |
# anything) starts at F16 and fights for budget — except MoE routers,
|
| 369 |
# which stay F16 outside the budget. Note the estimate assumes the binary
|
|
|
|
| 373 |
router_names = {
|
| 374 |
n for n in flex_names
|
| 375 |
if importance_table.get(n, {}).get("type", get_tensor_type(n)) in ROUTER_PIN_TYPES
|
| 376 |
+
} if not free_pins else set()
|
| 377 |
flex_names -= router_names
|
| 378 |
|
| 379 |
tensor_importance = {}
|