GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — S4oP/pruning_config.py at main · PARCO-LAB/S4oP Expand file tree/ Copy pathpruning_config.pyMore file actions 463 lines (446 loc) · 15.8 KB / Copy pathpruning_config.pyFile metadata and controls463 lines (446 loc) · 15.8 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 # Configurazione del pruning: # - livelli (perc) e seed, comuni a tutti i metodi; # - "finetune": fine-tuning di base per modello e dataset; # - una sezione per ogni metodo di pruning, con le sue modifiche al # fine-tuning e i suoi parametri. # Gli script leggono il fine-tuning con finetune_params(<metodo>, model, dataset), # in fondo al file, non direttamente dalle tabelle. PRUNING_CONFIG = { # Livelli di pruning e seed, comuni a tutti i metodi (stessi livelli = # risultati confrontabili) "perc": [0.1, 0.3, 0.5, 0.7, 0.9], "seeds": [7, 42, 123, 2024], # Fine-tuning di base per modello e dataset: il budget di UN livello di # S4oP (un seed). finetune_epochs, lr, weight_decay, early_stopping # (patience in epoche; None = senza early stopping). I metodi qui sotto # partono da questi valori e cambiano quelli che servono. "finetune": { "s4": { "listops": { "finetune_epochs": 6, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "pathfinder": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 6 }, "imdb": { "finetune_epochs": 3, "lr": 1e-5, "weight_decay": 1e-5, "early_stopping": 1 }, "ecg": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 6 }, "image": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "retrieval": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "enhancer": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "promoter": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "histone": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "dnase": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, }, "s4d": { "listops": { "finetune_epochs": 5, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "pathfinder": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 6 }, "imdb": { "finetune_epochs": 4, "lr": 1e-5, "weight_decay": 1e-5, "early_stopping": 1 }, "ecg": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 6 }, "image": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "retrieval": { "finetune_epochs": 4, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "enhancer": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "promoter": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "histone": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "dnase": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, }, "mamba": { "listops": { "finetune_epochs": 5, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "pathfinder": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 6 }, "imdb": { "finetune_epochs": 4, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "ecg": { "finetune_epochs": 6, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "image": { "finetune_epochs": 5, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "retrieval": { "finetune_epochs": 6, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "enhancer": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "promoter": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "histone": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "dnase": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, }, "mamba2": { "listops": { "finetune_epochs": 5, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "pathfinder": { "finetune_epochs": 20, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 6 }, "imdb": { "finetune_epochs": 4, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "ecg": { "finetune_epochs": 6, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "image": { "finetune_epochs": 5, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "retrieval": { "finetune_epochs": 6, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 2 }, "enhancer": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "promoter": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "histone": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, "dnase": { "finetune_epochs": 2, "lr": 1e-4, "weight_decay": 1e-5, "early_stopping": 1 }, }, }, # ------------------------------------------------------------------ # Metodi di pruning. In ogni sezione: # "finetune" modifiche al fine-tuning di base per tutti i # modelli e dataset ({} = quello di base) # "finetune_overrides" (opzionale) modifiche solo per alcuni casi, es. # {"s4": {"imdb": {"lr": 1e-4}}}; vincono su "finetune" # "grow_with_level" True: al livello i di perc (0 = il primo) epoche e # patience sono (i+1) volte quelle risultanti # "high_from", "finetune_high" (opzionali) dalla frazione potata high_from # in su si applicano anche le modifiche di # finetune_high (prima di finetune_overrides) # Al posto di un numero, finetune_epochs puo' essere una regola # {"of": <riferimento>, "factor": f} -> f * epoche del riferimento # (arrotondato), dove il riferimento e': # "train" le epoche del training del modello base (MODELS_CONFIG) # <nome metodo> le epoche di quel metodo per lo stesso modello/dataset # (con grow_with_level, quelle del livello di riferimento) # ------------------------------------------------------------------ # Cosa fa un'unita' spenta (canale S4/S4D/Mamba, testa Mamba2) in s4op # ("pruned_mode"; s4op_importance usa sempre "zero"): # "bypass" lascia passare l'ingresso (S4oP originale); le proiezioni # restano complete # "zero" da' uscita 0 e viene tolta fisicamente, comprese le sue # righe/colonne di proiezione: meno parametri e meno latenza # Vale solo per i modelli potati da qui in poi. Il valore viene salvato nei # checkpoint (chiave "pruned_mode"), e quando un checkpoint viene ricaricato # (test, latenza, ripresa) si usa il modo scritto li', non questo. # Non si puo' riprendere in una cartella con checkpoint dell'altro modo. # s4op.py: greedy incrementale; ogni livello parte dal migliore del # precedente, un fine-tuning per seed "s4op": { "pruned_mode": "bypass", "finetune": {}, }, # s4op_importance.py: pruning graduale durante il fine-tuning (rampa con # schedule cubico) con le unita' meno importanti tolte a ogni passo # (importanza = Taylor al primo ordine, ricalcolata prima di ogni passo). # Ogni livello riparte dal modello denso. Unita' tolte sempre in # pruned_mode "zero" (l'importanza stima l'effetto di un'unita' che da' # uscita 0). "s4op_importance": { # Recupero: budget di un livello di S4oP; da high_from di unita' tolte in # su (compreso) epoche triplicate, perche' togliere tante unita' fa # crollare il modello e serve piu' recupero. La soglia e' sulla frazione # di unita' tolte, non sulla posizione del livello. "finetune": {}, "high_from": 0.7, "finetune_high": {"finetune_epochs": {"of": "s4op", "factor": 3}}, # Un solo seed; con piu' seed si tiene il migliore in validazione (come S4oP). "seeds": [42], # Ranking globale su tutte le unita' di tutti i layer: lo schedule decide # solo quante unita' togliere in tutto. Unita' minime per layer: con 0 un # layer si potrebbe svuotare del tutto. "min_keep": 1, # Rampa: inizio e fine in frazione delle iterazioni di fine-tuning, e # numero di passi di pruning a intervalli regolari. prune_end_iters (se # non None) fissa la fine in iterazioni al posto di prune_end. One-shot # (il vecchio sparse2struct.py dal denso): n_updates 1, prune_end_iters 16. "prune_start": 0.0, "prune_end": 0.5, "prune_end_iters": None, "n_updates": 20, }, # unstructured_pruning.py: pruning dei pesi con schedule cubico; ogni # livello riparte dal modello base "unstructured": { "grow_with_level": True, "finetune": {}, }, } FINETUNE_KEYS = ("finetune_epochs", "lr", "weight_decay", "early_stopping") def finetune_params(method, model, dataset, level=0, ref_level=None, frac=None): """ Fine-tuning del metodo `method` per model/dataset: dizionario con finetune_epochs, lr, weight_decay, early_stopping. level livello di perc (0 = il primo), per i metodi con grow_with_level ref_level livello a cui leggere il riferimento di una regola {"of": metodo} (default: level) frac frazione potata del livello, per i metodi con high_from (s4op_importance: frazione di unita' tolte) """ sec = PRUNING_CONFIG[method] p = dict(PRUNING_CONFIG["finetune"][model][dataset]) p.update(sec.get("finetune", {})) if frac is not None and "high_from" in sec and frac >= sec["high_from"] - 1e-9: p.update(sec.get("finetune_high", {})) p.update(sec.get("finetune_overrides", {}).get(model, {}).get(dataset, {})) unknown = set(p) - set(FINETUNE_KEYS) assert not unknown, f"{method}: chiavi di fine-tuning sconosciute {sorted(unknown)}" epochs = p["finetune_epochs"] if isinstance(epochs, dict): ref_name = epochs["of"] if ref_name == "train": from models_config import MODELS_CONFIG ref = MODELS_CONFIG[model][dataset]["epochs"] else: assert ref_name != method, f"{method}: la regola delle epoche si riferisce a se stessa" ref = finetune_params(ref_name, model, dataset, level=level if ref_level is None else ref_level)["finetune_epochs"] p["finetune_epochs"] = max(1, int(epochs["factor"] * ref + 0.5)) if sec.get("grow_with_level"): p["finetune_epochs"] *= level + 1 if p["early_stopping"] is not None: p["early_stopping"] *= level + 1 return p # PERCENTUALI UNSTRUCTURED # Mamba # "imdb": [0.020765, 0.062193, 0.103722, 0.145252, 0.186680], # "listops": [0.099710, 0.299293, 0.498876, 0.698458, 0.898041], # "ecg": [0.099660, 0.299306, 0.498626, 0.697947, 0.897592], # "image": [0.099777, 0.299492, 0.499208, 0.698924, 0.898639], # "retrieval": [0.090178, 0.270829, 0.451185, 0.631542, 0.812192], # Mamba2 # "imdb": [0.017177, 0.050209, 0.084563, 0.118917, 0.151949], # "listops": [0.091170, 0.275910, 0.460649, 0.645389, 0.830128], # "ecg": [0.091117, 0.278147, 0.460381, 0.642615, 0.829644], # "image": [0.091241, 0.276124, 0.461007, 0.645891, 0.830774], # "retrieval": [0.081156, 0.247740, 0.410052, 0.572364, 0.738948], # S4 # "imdb": [0.003267, 0.009675, 0.016083, 0.022491, 0.028899], # "listops": [0.049490, 0.147826, 0.246805, 0.345784, 0.444121], # "ecg": [0.049160, 0.148445, 0.246766, 0.345087, 0.444372], # "pathfinder": [0.033391, 0.099957, 0.166523, 0.233089, 0.299655], # "image": [0.020018, 0.060119, 0.100155, 0.140191, 0.180292], # "retrieval": [0.026186, 0.078387, 0.130589, 0.182790, 0.234992], # S4D # "imdb": [0.002273, 0.006805, 0.011337, 0.015869, 0.020401], # "listops": [0.032907, 0.099044, 0.165180, 0.231317, 0.297453], # "ecg": [0.032803, 0.099051, 0.164656, 0.230262, 0.296510], # "pathfinder": [0.020155, 0.060335, 0.100515, 0.140695, 0.180875], # "image": [0.011200, 0.033635, 0.056034, 0.078433, 0.100869], # "retrieval": [0.015159, 0.045377, 0.075596, 0.105815, 0.136033], |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |