invarlock 0.3.6__py3-none-any.whl → 0.3.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. invarlock/__init__.py +4 -4
  2. invarlock/adapters/__init__.py +10 -14
  3. invarlock/adapters/auto.py +37 -50
  4. invarlock/adapters/capabilities.py +2 -2
  5. invarlock/adapters/hf_causal.py +418 -0
  6. invarlock/adapters/{hf_onnx.py → hf_causal_onnx.py} +3 -3
  7. invarlock/adapters/hf_loading.py +7 -7
  8. invarlock/adapters/hf_mixin.py +53 -9
  9. invarlock/adapters/{hf_bert.py → hf_mlm.py} +4 -11
  10. invarlock/adapters/{hf_t5.py → hf_seq2seq.py} +9 -9
  11. invarlock/assurance/__init__.py +15 -23
  12. invarlock/cli/adapter_auto.py +32 -26
  13. invarlock/cli/app.py +128 -27
  14. invarlock/cli/commands/__init__.py +2 -2
  15. invarlock/cli/commands/calibrate.py +48 -4
  16. invarlock/cli/commands/doctor.py +8 -10
  17. invarlock/cli/commands/evaluate.py +986 -0
  18. invarlock/cli/commands/explain_gates.py +25 -17
  19. invarlock/cli/commands/export_html.py +11 -9
  20. invarlock/cli/commands/plugins.py +13 -9
  21. invarlock/cli/commands/report.py +326 -92
  22. invarlock/cli/commands/run.py +1160 -228
  23. invarlock/cli/commands/verify.py +157 -97
  24. invarlock/cli/config.py +1 -1
  25. invarlock/cli/determinism.py +1 -1
  26. invarlock/cli/doctor_helpers.py +4 -5
  27. invarlock/cli/output.py +193 -0
  28. invarlock/cli/provenance.py +4 -4
  29. invarlock/core/bootstrap.py +1 -1
  30. invarlock/core/registry.py +9 -11
  31. invarlock/core/retry.py +14 -14
  32. invarlock/core/runner.py +112 -26
  33. invarlock/edits/noop.py +2 -2
  34. invarlock/edits/quant_rtn.py +67 -39
  35. invarlock/eval/__init__.py +1 -1
  36. invarlock/eval/bench.py +14 -10
  37. invarlock/eval/data.py +68 -23
  38. invarlock/eval/metrics.py +59 -1
  39. invarlock/eval/primary_metric.py +1 -1
  40. invarlock/eval/tasks/__init__.py +12 -0
  41. invarlock/eval/tasks/classification.py +48 -0
  42. invarlock/eval/tasks/qa.py +36 -0
  43. invarlock/eval/tasks/text_generation.py +102 -0
  44. invarlock/guards/invariants.py +19 -10
  45. invarlock/guards/rmt.py +2 -2
  46. invarlock/guards/spectral.py +1 -1
  47. invarlock/guards/variance.py +2 -2
  48. invarlock/model_profile.py +64 -62
  49. invarlock/observability/health.py +6 -6
  50. invarlock/observability/metrics.py +108 -0
  51. invarlock/plugins/hf_bnb_adapter.py +32 -21
  52. invarlock/reporting/__init__.py +18 -4
  53. invarlock/reporting/guards_analysis.py +154 -4
  54. invarlock/reporting/html.py +61 -11
  55. invarlock/reporting/normalizer.py +9 -2
  56. invarlock/reporting/policy_utils.py +1 -1
  57. invarlock/reporting/primary_metric_utils.py +11 -11
  58. invarlock/reporting/render.py +876 -510
  59. invarlock/reporting/report.py +72 -30
  60. invarlock/reporting/{certificate.py → report_builder.py} +252 -99
  61. invarlock/reporting/{certificate_schema.py → report_schema.py} +22 -22
  62. invarlock/reporting/report_types.py +6 -1
  63. invarlock/reporting/telemetry.py +86 -0
  64. invarlock-0.3.8.dist-info/METADATA +283 -0
  65. {invarlock-0.3.6.dist-info → invarlock-0.3.8.dist-info}/RECORD +69 -64
  66. {invarlock-0.3.6.dist-info → invarlock-0.3.8.dist-info}/WHEEL +1 -1
  67. {invarlock-0.3.6.dist-info → invarlock-0.3.8.dist-info}/entry_points.txt +5 -3
  68. invarlock/adapters/hf_gpt2.py +0 -404
  69. invarlock/adapters/hf_llama.py +0 -487
  70. invarlock/cli/commands/certify.py +0 -422
  71. invarlock-0.3.6.dist-info/METADATA +0 -588
  72. {invarlock-0.3.6.dist-info → invarlock-0.3.8.dist-info}/licenses/LICENSE +0 -0
  73. {invarlock-0.3.6.dist-info → invarlock-0.3.8.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
- invarlock/__init__.py,sha256=_KZRr1cTUSCHY7ZiPIk71h06tEznF_LOZQbyXcQfBMk,1268
1
+ invarlock/__init__.py,sha256=5SfeXbFvAxg2c1dblfdTyPB9MB91SgRJ4DFHxGgJJto,1273
2
2
  invarlock/__main__.py,sha256=ffhoKctw89j-henmQXThbHDIdlvK9fBfsy8LpjhOEXc,146
3
3
  invarlock/config.py,sha256=7BUOl7EW258YnsgRipjOx6lmWou5jNDzimREd35ewsQ,1725
4
- invarlock/model_profile.py,sha256=K-RSLbQRv9uM4RMfLvApLf3p2wp8iKrfy3BZ4p1h3m4,13756
4
+ invarlock/model_profile.py,sha256=OooTlTpsSfAOzJlMw2TsjExXShdAVyitvaKbLebzGsw,13689
5
5
  invarlock/model_utils.py,sha256=mEl9KOF2yOJgx-6r38PbD9SNFeAScamy9K-csxtl40Q,6395
6
6
  invarlock/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
7
7
  invarlock/security.py,sha256=xUjbHu-bHKUfFqDyN_21Hj00NBmAcGgnAg4JCjb0JOE,4861
@@ -9,21 +9,20 @@ invarlock/sparsity_utils.py,sha256=30SC3osptca2GmzxezbfX31EE6sRUhmEz8u3jn4vB2c,8
9
9
  invarlock/_data/runtime/tiers.yaml,sha256=9EbVnNw6MX18NKMI9xjKzJt-BsaB-JhUtC13c3Skmls,3619
10
10
  invarlock/_data/runtime/profiles/ci_cpu.yaml,sha256=FE5vxeemAFWW7oRxPvp_8hIcCO8qrJilvQpXuS3f6u0,389
11
11
  invarlock/_data/runtime/profiles/release.yaml,sha256=xF0Qb0OTm904U6L3wK674JMTcDPegYvpKgwUB9pfq_w,482
12
- invarlock/adapters/__init__.py,sha256=MxWJGRxVrV2TL5c7MA4FqmWyu1e_Kwpk7Ol4IFUJcNM,3411
12
+ invarlock/adapters/__init__.py,sha256=wZBhjYAnD7a0ZV36EDwje6D0FGG45CIfJ41WYqUPGg0,3296
13
13
  invarlock/adapters/_capabilities.py,sha256=FmzUR5BHsxWe92Z9W1As-G5_5wG1PvqF2sUpjZ2_CdY,1483
14
- invarlock/adapters/auto.py,sha256=4F3I63PRW604v_NtaTY7aGvUJVjGSjejVKFff-X_1t4,7693
14
+ invarlock/adapters/auto.py,sha256=7PUDCnWhW6Pi7nppIbpMTzUkaczhkBFJ7xb17eDZThs,7411
15
15
  invarlock/adapters/base.py,sha256=szSh1bECeDSDGQSr5oIWhs5RlI587gE4gzdt5cnOJ1s,16100
16
16
  invarlock/adapters/base_types.py,sha256=3IuHt63_RjGZqoTOdkMpfGPiZTGqcvXXDq1KU-8QemQ,1612
17
- invarlock/adapters/capabilities.py,sha256=oAK_zgCzAFmss8qAU2zgc8kcahtadGtbPTYR7StXiCo,15360
18
- invarlock/adapters/hf_bert.py,sha256=KTEk2HRSPlH57bfdVjV6imn_-aYqXAlbnWfEFlRm8h4,35555
19
- invarlock/adapters/hf_gpt2.py,sha256=TBn1cd_yZDSyVF5aJ-YNEwZzbVYI-m1c8U0CJl_74CM,14808
20
- invarlock/adapters/hf_llama.py,sha256=P3T7m9j61EmHtzzhemIfM2I2e5nbl4RwXSdoaVsueGc,19141
21
- invarlock/adapters/hf_loading.py,sha256=6hdSFRz_JMtBzQfHcwvyDlIVP2y-KwLwhDorg73DZ6c,2742
22
- invarlock/adapters/hf_mixin.py,sha256=3YGoamAG6OCubsbJ9S583yYiQEy2fZOsBJeBiLZTEbk,22307
23
- invarlock/adapters/hf_onnx.py,sha256=kEqgQEEdGUeaXDF0EgaMHOQQMhc1xIvur0bQvdky-AY,4446
24
- invarlock/adapters/hf_t5.py,sha256=sqHmi8io7oKlr7GrAk8tGo72zb-hmHGmXplCQSZgrA8,4774
17
+ invarlock/adapters/capabilities.py,sha256=wcSUkWm0_bVMHo3CEhGxplldG8M5nrB3Uhij8cwutzY,15373
18
+ invarlock/adapters/hf_causal.py,sha256=N9-L-Px4dzjAP4EsnJI_od1GMBqDVJ5JReyV4MyNtjs,15139
19
+ invarlock/adapters/hf_causal_onnx.py,sha256=eMqLPs0aIb7v4KjY0krdgfImVRTPht1D_k9LCulXw6w,4451
20
+ invarlock/adapters/hf_loading.py,sha256=iiztMDIVKi60AdlHRp9TaCOi-IRsni0p1dCeryzARsA,2694
21
+ invarlock/adapters/hf_mixin.py,sha256=uDRM5tPR6GhVh-fLql8sIUaBVFWl4Y4vvB0d6ms_3SY,24014
22
+ invarlock/adapters/hf_mlm.py,sha256=iCyiy-0aYO43d2eTM8brKeJGBhZsMkjhzGhj580oh4s,35221
23
+ invarlock/adapters/hf_seq2seq.py,sha256=_5jmTB0sMpXs5N1_rNJ7vpntkpj4k68Ca7tM-Iy8HPw,4796
25
24
  invarlock/adapters/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
26
- invarlock/assurance/__init__.py,sha256=SFDT2klaUaKZejulL5cfBTW29ehJxyW5srE-LuqP7z0,1388
25
+ invarlock/assurance/__init__.py,sha256=TTvJGsysPfonfJGIW2qdl3D0_yjslpzyFR0nb70ot_Q,1192
27
26
  invarlock/calibration/__init__.py,sha256=M5lbkNQtLBuQjQJGeRzHovkpYI87fEWIm7a0b23jSp4,110
28
27
  invarlock/calibration/spectral_null.py,sha256=2WQU7YgnnJ2i3OF60Zj4miaWBvWBXQmztukQtIWhvro,9601
29
28
  invarlock/calibration/variance_ve.py,sha256=QkHO2vxht-n56LNqWbHYYY106Ge5PbxzHfGV1QktnN8,4487
@@ -31,55 +30,56 @@ invarlock/cli/__init__.py,sha256=mRjYDVmNykhxJxfQBxJMzhFfmNhmvP6OWI-vJL-ehUA,196
31
30
  invarlock/cli/__main__.py,sha256=spgMrx0eJQSEf4rcd0_mB2B8rHOc3iWlTFO3P_qEvoM,175
32
31
  invarlock/cli/_evidence.py,sha256=38QMfFlPUT_qIRAZmpDROkwSIpHGiNKRWDyXfZ9xI_U,769
33
32
  invarlock/cli/_json.py,sha256=AKrRNFza76tH3GBVHO8gSA3klUVQ9XpDo_aYh8l-7j8,2367
34
- invarlock/cli/adapter_auto.py,sha256=Qwh4hJXm_vGexCXPt3iP70rQPC7ozwlEzSTYay0svQ8,5284
35
- invarlock/cli/app.py,sha256=iWO4tTwglZTH2CGEW_SXIQ95MyFTw6NYxlBujhpZQRg,9179
36
- invarlock/cli/config.py,sha256=vyLxR9WKW2vnIFACmS6k79yHEaO1zKuZ9q5bufaoB18,14203
33
+ invarlock/cli/adapter_auto.py,sha256=uazFcSck4f_S2fSlV-utJsuCdoCQpBPBl8KRPXkC3_k,5448
34
+ invarlock/cli/app.py,sha256=nWn3Ptgwa27LrwLqkbqxmoc9F2TuGIP_XyGouoalx3U,12453
35
+ invarlock/cli/config.py,sha256=DNCsepPCY_l0JTPUqI9QRa-cLIl8n4H2xzolXjtL7q8,14205
37
36
  invarlock/cli/constants.py,sha256=RuXxG82pukfBnEuJB2CVF5dyu4lEi-l8eAxkR314yuk,2107
38
- invarlock/cli/determinism.py,sha256=ux3AODjZbSdYE29uSrHXvY2qrEPxeAJd04QLT52lnec,8346
37
+ invarlock/cli/determinism.py,sha256=kf7WD8bB11WWzpzdGu3j55JfPSfCK3gYYCSNVVf8jyU,8352
39
38
  invarlock/cli/device.py,sha256=5X0j2yiZbSKX9-SlDaAbSeHCoWhfEQ74YWPTb8WRk8k,3165
40
- invarlock/cli/doctor_helpers.py,sha256=e3A6rWYAcs1Q1WVFWt3OOGgqd5iMsKASD34TzI98wqA,2542
39
+ invarlock/cli/doctor_helpers.py,sha256=3QkE4P6lrb2YQA-OC5m6K6CQEoe7PSRiSuQDYEvmRsY,2503
41
40
  invarlock/cli/errors.py,sha256=IzFikxe5gthlZ27wrRYUiM_SJsd2Sa5onUUhjm8e2kA,189
41
+ invarlock/cli/output.py,sha256=lNEQ189iyV-EEsdTY4rmFcKKjq0lJuIP-gzsEIFL7BA,4883
42
42
  invarlock/cli/overhead_utils.py,sha256=Ygvl192UDTroAbVAd7v35jgigmmfVxNkCIGYlWfh6Co,2124
43
- invarlock/cli/provenance.py,sha256=2E_8MxpSVEcxe5UewTb5Hlz6x4jXFwGd1567F4nIbEc,1939
43
+ invarlock/cli/provenance.py,sha256=ksoAVOhMnSrPYCh0osLDEbgxKOCS1DjoXuBuZmV6m5k,1948
44
44
  invarlock/cli/utils.py,sha256=R6IN21lGfko2lGUgspmkZyjA6Nl_dVRaP8F8nRtN5yw,1393
45
- invarlock/cli/commands/__init__.py,sha256=afpKpU8hJI41Ol46oXxVwQgPwFBy4OmLaa_v4AAOdts,712
46
- invarlock/cli/commands/calibrate.py,sha256=TnoYKjvmz2pSj3Wak8HluSV27hN2D8O1dGAQWCcHeeE,20830
47
- invarlock/cli/commands/certify.py,sha256=n62diGs7eFymuJNz-EJmWldYVO5KehHWeYtwtL1UWRY,15861
48
- invarlock/cli/commands/doctor.py,sha256=IQciP1Xs-_W4R5lhZv1ZbYwvIjy9VY_WMBypvbok1FI,56944
49
- invarlock/cli/commands/explain_gates.py,sha256=7cnc_FBxvSkjmM12JOA2yfhY4JH1puDDaIHo3r6IC9M,9444
50
- invarlock/cli/commands/export_html.py,sha256=oUGtt6EpKhjlywdtz_0FqYqcmA219H4eSjPuSMDShgY,3095
51
- invarlock/cli/commands/plugins.py,sha256=u5E6ThcWE5RUs2YKH-m6x7n-5K1jt2IudkF9kl9T5xg,53486
52
- invarlock/cli/commands/report.py,sha256=AaGq4J1qm8ERMZmbAkAHtc8kZ0CvMp14wili1K2tX8g,12987
53
- invarlock/cli/commands/run.py,sha256=S25dVLxQe1RVxLQ6cD8CSlpqGxp1Eggvbk4WzsHSwW4,204782
54
- invarlock/cli/commands/verify.py,sha256=zKoSTPLrMgCw6LseCNn5RkPDEZTuRZ8j14tWHbvcZxM,49234
45
+ invarlock/cli/commands/__init__.py,sha256=Nvjvw9Jo0Wq3BHBpEGZBTUnj25920hw9jZ0qm1jm6yw,715
46
+ invarlock/cli/commands/calibrate.py,sha256=IFWIvkwMFmXl8c0V6mY0AQ4gS9Jkl7MP96W2DFMEbMU,22663
47
+ invarlock/cli/commands/doctor.py,sha256=F-q5CJ2qRgCDqbaZYBRApPUy7V6E_jkgSCqZgkxlOqA,56879
48
+ invarlock/cli/commands/evaluate.py,sha256=eCnT9m4LzYCf5lmZd8hCvn-8CgdtXwx7CJvyMRaYRbg,36799
49
+ invarlock/cli/commands/explain_gates.py,sha256=m1TRR6jQWMkFCDHocw6-arwIANeCz337ZRhT4PCE1Ps,9720
50
+ invarlock/cli/commands/export_html.py,sha256=v5UCbFcRrJvRFC5ek-LhZbaBTZtkmaQikg2QHZR73RA,3142
51
+ invarlock/cli/commands/plugins.py,sha256=VTJKTMjFO4Dh4dqcY4qlkwhsWJixyHSNk8tWBcYGyfA,53620
52
+ invarlock/cli/commands/report.py,sha256=UY52S2q5UzUJZFougJr6yDJGRP9Pe0_idnmK81meB3o,21226
53
+ invarlock/cli/commands/run.py,sha256=7D2s8WM5o02n9oVsNpaVpdeBKXY812jXkNS4MZwColQ,236332
54
+ invarlock/cli/commands/verify.py,sha256=o8WtTaw2JZFNXb3fREhlC0eLutujDaGzqDSIXwIrtl8,51481
55
55
  invarlock/core/__init__.py,sha256=4wb83Xv7NE5M1FgvaFUviiNtVSTVATiPH3gqavNmp2w,1490
56
56
  invarlock/core/abi.py,sha256=gmU1F7LDd2HTcF4kcznn8vgG4zj9UCHSqhBk9jyu05k,484
57
57
  invarlock/core/api.py,sha256=RTFswFBuUH38gary5X7qmccOD7vAYLtSN0ie8Y6p1ck,8480
58
58
  invarlock/core/auto_tuning.py,sha256=Gj0AhpThoDYnzr9DyuXM9iCuieMKR4xv43tC7ZcjHzs,18543
59
- invarlock/core/bootstrap.py,sha256=0mA_x1Ipz4eTwJqoz4-F4H0O2AqvlmQGA9BVJpTNqXs,10655
59
+ invarlock/core/bootstrap.py,sha256=c4bd8GFUiL53oI7t2QVM46Ah7Tl1LbtbyQGb5VzXuWQ,10647
60
60
  invarlock/core/checkpoint.py,sha256=a78L-mZd3j2kC1az2eTScRxTHjrULuYs-UPfWUcDgqM,6933
61
61
  invarlock/core/contracts.py,sha256=ESK3-ErieGEf8e84wiphlCjahdr87zoKyTSskq6o23E,2468
62
62
  invarlock/core/error_utils.py,sha256=T23-p5ONQ-SeVuMR4Ts0cWyupsSa-0DAgsejRTfxeCg,1782
63
63
  invarlock/core/events.py,sha256=8XBAi-9A7ys7QJQwqlz8PVlfxF0TM_TvLqjcPtDwZm4,9428
64
64
  invarlock/core/exceptions.py,sha256=b4OszJ0Fd0Ezy8s99AzprS7lAkqdZYGXaSj9fYaln4E,2077
65
- invarlock/core/registry.py,sha256=ZRW7JY-XgWrQMtN451n_Uk4it3CMLCsZUPHqic2G1x4,19109
66
- invarlock/core/retry.py,sha256=KTVkrTnWs60jwATOZDHinERH56GnOGjsKR0lmohagEo,4503
67
- invarlock/core/runner.py,sha256=BYvJlWhsrSRyudXNdY-vuZVt5NypYqMTS5yK28jhIVI,104105
65
+ invarlock/core/registry.py,sha256=hQrAqVEyDOCF88KHn80a5oMMS73_i4KTjL3Wwo08YkI,18910
66
+ invarlock/core/retry.py,sha256=gdMZRouhyjwgbSGEpwGBIqrrtRO8-jPcN50ebIwOPR0,4441
67
+ invarlock/core/runner.py,sha256=y0FLefuosmEFwpAmEy_Wa2mkcPUJRxPDr9J1MdPzmbM,107587
68
68
  invarlock/core/types.py,sha256=nVLMP4yqlxwhE1moQU7FWVeGJqTuud-cvTZiutdBGKk,3585
69
69
  invarlock/edits/__init__.py,sha256=5CJTX6oJTLj79Vmks2_8mXRGFQH0oyKaZOrBLTlRtV0,277
70
70
  invarlock/edits/_edit_utils.py,sha256=VGl32JAt7XsovxJbX1YvW9DJvtG-K2EKu-TjBFTQmDY,6329
71
71
  invarlock/edits/_external_utils.py,sha256=Ltaua-eNooDagPSb20wxK-QXXpHjFJaymbDIjI3ZoWY,7625
72
- invarlock/edits/noop.py,sha256=I9ICb9m4RLK7BllERlydujQciHQm9Hj8gbqKz5_rCTg,1304
72
+ invarlock/edits/noop.py,sha256=RpqiZy5jZaxZ_O-aSz3FlOzo_isszZ2NDiHNNDpGBDk,1302
73
73
  invarlock/edits/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
74
- invarlock/edits/quant_rtn.py,sha256=8rseGbF_-EFuL8MWCuzgGXYfzp9LsONhV72-OK56mlk,30684
74
+ invarlock/edits/quant_rtn.py,sha256=-ENk7VnJi3uSptlBmVg4jVDwwfMtWhhp0ginpc9ShQw,31663
75
75
  invarlock/edits/registry.py,sha256=MmUfJhhvc3WxB03wQkPxFMS6nkT7YcXFPQqhbksfOUc,4523
76
- invarlock/eval/__init__.py,sha256=GsKoszCysh3TT_UHiuJcqeoiXT7AUNZoqMuBmefnWtY,755
77
- invarlock/eval/bench.py,sha256=pG1OSO5-Ela46ReImhQJAuLTxE6oSfTFjHSTSL_09-8,55925
76
+ invarlock/eval/__init__.py,sha256=SDz0f1t00ZBgT5xMXblRxbW0j0ai75EimJ78ZOwgegs,756
77
+ invarlock/eval/bench.py,sha256=dt7-UEv5Znk_mg1JSMxIo2vLOsdPPr6EW_Sg8_OdZUk,56032
78
78
  invarlock/eval/bench_regression.py,sha256=GDphmdcH7NI8P_afSkQAPMChEgW15J0gqTZ4Kj3kxgw,456
79
79
  invarlock/eval/bootstrap.py,sha256=CNn7W_MY716Wa_wn6cYRmbTYB9lT2X0yLOAIHCRw29k,1766
80
- invarlock/eval/data.py,sha256=YUOvgM3h_KSIZ0FQw5yhrsU_YonIb5Ml950t8hg3qn8,66652
81
- invarlock/eval/metrics.py,sha256=Ff72jgeLAWCn1WgpDE2lX0RzdJMrb39fgjKCF2rwkpk,78972
82
- invarlock/eval/primary_metric.py,sha256=lGDWiXM1cyXqGH6XprLrxBl1hTwjrlSYbQCzF687zsA,29545
80
+ invarlock/eval/data.py,sha256=WcnH9nMaEpWqsGLnVfSFIps1a_16aVw0qtpQtm0-G2c,68326
81
+ invarlock/eval/metrics.py,sha256=PHfsIZQpCDesj7oL_vAIDdB3nH-10qVRl6kvfRU8-u4,80789
82
+ invarlock/eval/primary_metric.py,sha256=DxD2tTahPEInMolynMkJR2PsM915-prncmr3c08en2w,29563
83
83
  invarlock/eval/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
84
84
  invarlock/eval/tail_stats.py,sha256=ueScFzPvBnBC4jVW5EElnB0c3LPK3cAITcOUdyPCsEk,7114
85
85
  invarlock/eval/probes/__init__.py,sha256=KocOJmEWrD90c2HbDW3wDsdsibRyidskpI4rNNfLbZ0,593
@@ -90,16 +90,20 @@ invarlock/eval/providers/base.py,sha256=27Cn7-TRtVRPrSHt7qBBqtLMnMEslO88zHiEsxQz
90
90
  invarlock/eval/providers/seq2seq.py,sha256=lYxI6d1-YCyxjGyHVLi2ZbFFwxJVVUewH9luFBoDehM,3711
91
91
  invarlock/eval/providers/text_lm.py,sha256=EpQWjQEkxSMhTiABsJzZqfYsgSYeMmUW-ZgePmdyj7U,4149
92
92
  invarlock/eval/providers/vision_text.py,sha256=pqhPHwvYEnyKupchIy-g-jM_oWeYNXRHb23_Qm4v2hU,3180
93
+ invarlock/eval/tasks/__init__.py,sha256=Z5CG7jwVNTMnQ0OZEzqsbYZzQkmPm3lHt2k2V8f2e6U,327
94
+ invarlock/eval/tasks/classification.py,sha256=s1v649MlKn2u1z1q8rvor5yMg3AvORFxoKoAXEDp088,1398
95
+ invarlock/eval/tasks/qa.py,sha256=D4nnj2A_6Tsmi5mz3x2bN9j88eCB-ajE4h7x-obNf-0,1134
96
+ invarlock/eval/tasks/text_generation.py,sha256=gefCcwqpsIoz3Sq6V6XDEZvChR1K2Hn4pHfzFDo7CMk,3355
93
97
  invarlock/guards/__init__.py,sha256=Kj7Jwb4qLyaY0ATRku34T628vom3QMjTiVrlpfJAWw8,443
94
98
  invarlock/guards/_contracts.py,sha256=WPhg3iWpHGkKfPvlPPQ-umzOakpy3s289DKkYQ0e64I,263
95
99
  invarlock/guards/_estimators.py,sha256=84nT5eF7uN-zr-RfYF2uOvdHlmE5c8_yvor4IqxvwWk,4642
96
- invarlock/guards/invariants.py,sha256=2mD5WSJMCksjO-DodAac5pvZN0nl29NKHhqwqH_gyCQ,22379
100
+ invarlock/guards/invariants.py,sha256=pnzjB1_2e0yD7jjySLIm_McDail_HTWpbAsGuYD2I40,22747
97
101
  invarlock/guards/policies.py,sha256=ggY0zZ3i39OAeFZJSG1FjwnR3-wjWntKLLvumBvG8pc,25933
98
102
  invarlock/guards/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
99
- invarlock/guards/rmt.py,sha256=eKWbF4htt_0-Cuby5T9Q6Di6QmQPsCBUWh-dCXlrxic,99864
100
- invarlock/guards/spectral.py,sha256=TP_xmzL0iP3CSQjnkulNbuJegxCrp68MuMPWdLeE0Gg,69597
103
+ invarlock/guards/rmt.py,sha256=aRMtRR7LfrjR-ZkeL_AsGb61bbBadYHhQx424WIRFVs,99878
104
+ invarlock/guards/spectral.py,sha256=AJqMx7oPHMOlnMWf4lN9mIFKparC0lOKkIB8ydABMw0,69603
101
105
  invarlock/guards/tier_config.py,sha256=6JzS1TOlhUVX2NdUodWhb4VOA_AnAFVOXvwY9aiopbA,10796
102
- invarlock/guards/variance.py,sha256=8WauGx34ORBMrArYTDRtyEZuTcZSeBIqJHqG067wugc,136371
106
+ invarlock/guards/variance.py,sha256=iNursnzCHbc2fd3icZ3cYG-dk4WFYqn6CKxKcKn2MJI,136385
103
107
  invarlock/guards_ref/__init__.py,sha256=jLnyFqdqQaheG1qQMlU4Gx7R118rkkQHPqFVF3_1ih0,366
104
108
  invarlock/guards_ref/rmt_ref.py,sha256=IfwN-l9cLExUQJhZmr-1uJv7qRSoYrGg2w2caCG53hs,1399
105
109
  invarlock/guards_ref/spectral_ref.py,sha256=FdwFfrs5hxEEUIfBV3CvAJvTX78gAM00mKLEXyZ0zJo,4386
@@ -108,35 +112,36 @@ invarlock/observability/__init__.py,sha256=_fCH1H51M0PYOvpuNq9sVQLTiDAtdQMvtnhVt
108
112
  invarlock/observability/alerting.py,sha256=y_mReOy5KHbHhglQIoChzTl-4BZz9aaGDreLGFzhl8M,17887
109
113
  invarlock/observability/core.py,sha256=lMsXCp5HZj3YIdfrkxRYQWpu1ib6pm8TkPab_1aKjHM,19050
110
114
  invarlock/observability/exporters.py,sha256=bNpuN7ulQ3KQSySozJZvNHythMw2ciF54aQzZ9t2hKE,18712
111
- invarlock/observability/health.py,sha256=28jKOb8dPDJVunh8FOBe6FS4rqtp0vP8mGQcotxkIUY,21564
112
- invarlock/observability/metrics.py,sha256=ciYhz7R11rW3FR4BLb-ES2R0k7IaUPCew89k359r-CQ,15476
115
+ invarlock/observability/health.py,sha256=jKVfThhe985oY1koS8EhWm08VQaVhHgRcspkuNrvO9E,21573
116
+ invarlock/observability/metrics.py,sha256=RhEz4B5zvRHAgFHukyZHGhDJDSxR3szYwk7TTFzIZTQ,19016
113
117
  invarlock/observability/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
114
118
  invarlock/observability/utils.py,sha256=1AC3ZEzbrDzTOvSIFxAtWlITy1BHEPZ032HKKzqK_10,16492
115
119
  invarlock/plugins/__init__.py,sha256=aZqkpuTT0K3y0SX4702k3YpHnM3kng9fz0qO3XE43hY,260
116
120
  invarlock/plugins/hello_guard.py,sha256=-peYJaZd52bbdw6y8cBxEd3CbtFWualDs8nX60CeXhI,896
117
121
  invarlock/plugins/hf_awq_adapter.py,sha256=UGwzcqJyuqrYHWZ4F-vn-9LNfEDyolOgVDBi0jN35xc,3770
118
- invarlock/plugins/hf_bnb_adapter.py,sha256=g0ysWEi8dQzLtJy8iCszfTsYCOACuZMFYnTLMAEVxs0,6011
122
+ invarlock/plugins/hf_bnb_adapter.py,sha256=sJXOIX-gIZwgIW7fYqohY7DqsZMI2fnU0ALkhm0T5nM,6715
119
123
  invarlock/plugins/hf_gptq_adapter.py,sha256=ysugAcnjLqF5sqpijSNiim1xUpRmoIgBrG053X3S2hE,3743
120
124
  invarlock/plugins/py.typed,sha256=LCPmZeE_vANVVJDNvuq9A07i7jg9Nxrq6f10UeuNfZc,37
121
- invarlock/reporting/__init__.py,sha256=A0541EqxcdTpslNbZEWIO4q-LCqzCQcadev2IBKEBbM,232
122
- invarlock/reporting/certificate.py,sha256=UyUhhrgWsdNG2xPtOVvRjaiWaOhHP-Aw6PuzOD8UBHQ,154177
123
- invarlock/reporting/certificate_schema.py,sha256=aZPDvJcFOIcwNJ06iTHJtXAHTmb5BPvv_T7qaSTjW8o,8978
125
+ invarlock/reporting/__init__.py,sha256=gLawo1x41oHX3jNQVC0XwnZ4iFcwez6MwdYN9SLoxnQ,534
124
126
  invarlock/reporting/dataset_hashing.py,sha256=igDq9iMB8sqed5CEWT2fXtx9z5QAxIZ9bbs5RndDDC4,9228
125
- invarlock/reporting/guards_analysis.py,sha256=JYZ-_Aoc1XI7BrYYm1Pit4n5vTewnt8wqhzMDrWYpO8,38014
126
- invarlock/reporting/html.py,sha256=d3LQ_brDGYW7GLR_Kj4rimIfGZsAgVE9XQtIjqsJ1rw,1029
127
- invarlock/reporting/normalizer.py,sha256=7zUyx9pUPuV6IrEi7PRBFIAid_14ABuU4xhHLjkONCI,8271
128
- invarlock/reporting/policy_utils.py,sha256=540fw6cFvyvYL7avlvId9GUvY9-g6MkeDlcPt18uuE0,22934
129
- invarlock/reporting/primary_metric_utils.py,sha256=7h6CzMQzu0A8xN10vbRgSNcQ0YTMxsT2JiNEgCVaXyM,14849
130
- invarlock/reporting/render.py,sha256=nujyDXgh11dWUtYPru41mx8FnWer7-5wbCiqqK2ae7A,62450
131
- invarlock/reporting/report.py,sha256=oqNjusy2wseURakW3Icn0MPSDNMm6bpcvKREFTzbd3o,32286
132
- invarlock/reporting/report_types.py,sha256=cw6UxHS67W0Y8uLEFoplGFrdrr9ktZDyzkvjuQkSERU,8873
127
+ invarlock/reporting/guards_analysis.py,sha256=Q3DhV806McbV4NVxbD-Lcw334epcQ1-zTEUF3aT8JGc,44356
128
+ invarlock/reporting/html.py,sha256=UrDIXsiKEFQpxACY3637OiVyL01CkPV2bAwJ_c0cEl4,3286
129
+ invarlock/reporting/normalizer.py,sha256=_t7ugqmIfBqz0HSH_NgKtwByHkQI-7CyL7-CMN9ya44,8482
130
+ invarlock/reporting/policy_utils.py,sha256=yjUOtClY0iMreVo_r1srHFvPgb1QyQ9X6x2cQStVWEM,22937
131
+ invarlock/reporting/primary_metric_utils.py,sha256=Ing2LKIvgpqQQLAuB0x80J3qMd1rBJV2UrePWHZeHCo,14912
132
+ invarlock/reporting/render.py,sha256=zliYsn79a0s-DkaKsAdcjKBLyPTdPfS-DHGb2b3fYOs,75618
133
+ invarlock/reporting/report.py,sha256=2w-REyyvbeuOm6l4BIEqVf0lT1ldPWZD7N378_DDR5I,33871
134
+ invarlock/reporting/report_builder.py,sha256=l3w7WUcMWtxXmg6dtZjyOkUWA_50mQB88ovibpXyxgU,159829
135
+ invarlock/reporting/report_schema.py,sha256=yvxSbbppdhQchQCBmMcVQTszUBERQg7rrZ-4obnzafc,8902
136
+ invarlock/reporting/report_types.py,sha256=NcA6PkI8JJA-FbPAGT-q_QcDkRcz57ayEKHyFbqe-Rk,9211
137
+ invarlock/reporting/telemetry.py,sha256=1A4ZgsmT7BzaEMiG56OzCwc0dX6MKVh8TPOwyXNGSb8,2705
133
138
  invarlock/reporting/utils.py,sha256=1aLYgSUR4XvgmhDvU9YK9ICd7W5sjft1qdsZC9JJSRY,5540
134
139
  invarlock/reporting/validate.py,sha256=aFcac5iaaNOLMYEf6g5xoF4-a-J5E430utFLnfu6fKc,21782
135
140
  invarlock/utils/__init__.py,sha256=DR2pBrgddLH2PW-6ninOE8CM7DNvlvgyYsCkckozbPU,4276
136
141
  invarlock/utils/digest.py,sha256=sfnqGFRiRf7l950MjSIrWO1XbUfXlcEfNLeWFbBUr8I,1290
137
- invarlock-0.3.6.dist-info/licenses/LICENSE,sha256=uFddaXYY02nEFdPpS7bam_bnm0st41BibzD0jHULPXw,10413
138
- invarlock-0.3.6.dist-info/METADATA,sha256=PYnrgExSymgE3QAyfJbHect9jVt6cJatWY3zVp7npNo,21875
139
- invarlock-0.3.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
140
- invarlock-0.3.6.dist-info/entry_points.txt,sha256=i0e4ZzmJNMBGG-69lbgP-muEcn1je2TUIWwl9SJERm0,670
141
- invarlock-0.3.6.dist-info/top_level.txt,sha256=GXfftc_YDHHcQC2vQgYbZ5cTO82YuWY3HusHMT3DuKs,10
142
- invarlock-0.3.6.dist-info/RECORD,,
142
+ invarlock-0.3.8.dist-info/licenses/LICENSE,sha256=uFddaXYY02nEFdPpS7bam_bnm0st41BibzD0jHULPXw,10413
143
+ invarlock-0.3.8.dist-info/METADATA,sha256=9A66_l4i-uTNQvWASLPe5XPouoxglNdr1aLFv13YS4s,13419
144
+ invarlock-0.3.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
145
+ invarlock-0.3.8.dist-info/entry_points.txt,sha256=7zdvDjsIPqOGEhfQFn596IrodvkhYrkybFgQ2ywPHYQ,780
146
+ invarlock-0.3.8.dist-info/top_level.txt,sha256=GXfftc_YDHHcQC2vQgYbZ5cTO82YuWY3HusHMT3DuKs,10
147
+ invarlock-0.3.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -2,12 +2,14 @@
2
2
  invarlock = invarlock.cli.app:app
3
3
 
4
4
  [invarlock.adapters]
5
+ hf_auto = invarlock.adapters:HF_Auto_Adapter
5
6
  hf_awq = invarlock.plugins.hf_awq_adapter:HF_AWQ_Adapter
6
- hf_bert = invarlock.adapters:HF_BERT_Adapter
7
7
  hf_bnb = invarlock.plugins.hf_bnb_adapter:HF_BNB_Adapter
8
- hf_gpt2 = invarlock.adapters:HF_GPT2_Adapter
8
+ hf_causal = invarlock.adapters:HF_Causal_Adapter
9
+ hf_causal_onnx = invarlock.adapters:HF_Causal_ONNX_Adapter
9
10
  hf_gptq = invarlock.plugins.hf_gptq_adapter:HF_GPTQ_Adapter
10
- hf_llama = invarlock.adapters:HF_LLaMA_Adapter
11
+ hf_mlm = invarlock.adapters:HF_MLM_Adapter
12
+ hf_seq2seq = invarlock.adapters:HF_Seq2Seq_Adapter
11
13
 
12
14
  [invarlock.edits]
13
15
  quant_rtn = invarlock.edits:RTNQuantEdit
@@ -1,404 +0,0 @@
1
- """
2
- HuggingFace GPT-2 Model Adapter
3
- ===============================
4
-
5
- ModelAdapter implementation for HuggingFace GPT-2 architecture models.
6
-
7
- This adapter provides enhanced HuggingFace integration including:
8
- - Better model detection for HF model variants
9
- - Proper handling of transformers library specifics
10
- - Device-aware state serialization with HF model handling
11
- - Weight tying preservation (lm_head ↔ wte)
12
- - Split size and layer naming convention support
13
- """
14
-
15
- import os
16
- from types import SimpleNamespace
17
- from typing import Any
18
-
19
- import torch
20
- import torch.nn as nn
21
-
22
- from invarlock.core.api import ModelAdapter
23
- from invarlock.core.error_utils import wrap_errors
24
- from invarlock.core.exceptions import AdapterError, DependencyError, ModelLoadError
25
-
26
- from .hf_mixin import HFAdapterMixin
27
-
28
- LIGHT_IMPORT = os.getenv("INVARLOCK_LIGHT_IMPORT", "").strip().lower() in {
29
- "1",
30
- "true",
31
- "yes",
32
- }
33
-
34
- TensorType = torch.Tensor
35
- ModuleType = nn.Module
36
-
37
-
38
- class HF_GPT2_Adapter(HFAdapterMixin, ModelAdapter):
39
- """
40
- HuggingFace-specific ModelAdapter implementation for GPT-2 models.
41
-
42
- Supports HuggingFace GPT2Model and GPT2LMHeadModel variants with:
43
- - Enhanced HF model detection and validation
44
- - Device-aware state serialization
45
- - Weight tying preservation across snapshot/restore cycles
46
- - Proper handling of Conv1D layers and split_size conventions
47
- """
48
-
49
- name = "hf_gpt2"
50
-
51
- def load_model(
52
- self, model_id: str, device: str = "auto", **kwargs: Any
53
- ) -> ModuleType | Any:
54
- """
55
- Load a HuggingFace GPT-2 model.
56
-
57
- Args:
58
- model_id: Model identifier (e.g. "gpt2", "gpt2-medium")
59
- device: Target device ("auto", "cuda", "mps", "cpu")
60
-
61
- Returns:
62
- Loaded GPT-2 model
63
- """
64
- # Lazy import to allow dependency mapping; in light-import mode fall back to a stub
65
- try:
66
- with wrap_errors(
67
- DependencyError,
68
- "E203",
69
- "DEPENDENCY-MISSING: transformers",
70
- lambda e: {"dependency": "transformers"},
71
- ):
72
- from transformers import AutoModelForCausalLM # type: ignore
73
-
74
- with wrap_errors(
75
- ModelLoadError,
76
- "E201",
77
- "MODEL-LOAD-FAILED: transformers AutoModelForCausalLM",
78
- lambda e: {"model_id": model_id},
79
- ):
80
- model = AutoModelForCausalLM.from_pretrained(model_id, **kwargs)
81
-
82
- return self._safe_to_device(model, device)
83
- except DependencyError:
84
- if LIGHT_IMPORT:
85
- # Minimal stand-in that satisfies downstream interface requirements
86
- stub = SimpleNamespace(name="hf_gpt2_stub")
87
- stub.to = lambda *_a, **_k: stub # type: ignore[attr-defined]
88
- return stub
89
- raise
90
-
91
- def can_handle(self, model: ModuleType | Any) -> bool:
92
- """
93
- Check if this adapter can handle the given model.
94
-
95
- Enhanced detection for HuggingFace GPT-2 models with validation
96
- of expected structure and configuration.
97
-
98
- Args:
99
- model: The model to check
100
-
101
- Returns:
102
- True if this is a HuggingFace GPT-2 compatible model
103
- """
104
- # Check for HuggingFace GPT-2 class names (avoid importing classes at module import time)
105
- model_name = model.__class__.__name__
106
- if model_name in ["GPT2Model", "GPT2LMHeadModel"]:
107
- # Verify it has HF config
108
- if hasattr(model, "config") and hasattr(model.config, "model_type"):
109
- return model.config.model_type == "gpt2"
110
-
111
- # Structural validation for GPT-2-like models
112
- if hasattr(model, "config") and hasattr(model, "transformer"):
113
- config = model.config
114
- transformer = model.transformer
115
-
116
- # Check for GPT-2 configuration attributes
117
- if (
118
- hasattr(config, "n_layer")
119
- and hasattr(config, "n_head")
120
- and hasattr(config, "hidden_size")
121
- and hasattr(transformer, "h")
122
- ):
123
- # Validate transformer structure
124
- try:
125
- h_layers = transformer.h
126
- if hasattr(h_layers, "__len__") and len(h_layers) > 0:
127
- layer = h_layers[0]
128
- elif hasattr(h_layers, "__iter__"):
129
- # Handle iterables without len() (like Mock objects in tests)
130
- try:
131
- layer = next(iter(h_layers))
132
- except (StopIteration, TypeError):
133
- return False
134
- else:
135
- return False
136
-
137
- # Check for GPT-2 layer structure with HF conventions
138
- if (
139
- hasattr(layer, "attn")
140
- and hasattr(layer, "mlp")
141
- and hasattr(layer.attn, "c_attn")
142
- and hasattr(layer.attn, "c_proj")
143
- and hasattr(layer.mlp, "c_fc")
144
- and hasattr(layer.mlp, "c_proj")
145
- ):
146
- return True
147
- except (AttributeError, TypeError):
148
- return False
149
-
150
- # Check for bare GPT2Model structure (less common but possible)
151
- if hasattr(model, "h") and hasattr(model, "config"):
152
- if hasattr(model.config, "n_layer") and len(model.h) > 0:
153
- layer = model.h[0]
154
- if (
155
- hasattr(layer, "attn")
156
- and hasattr(layer, "mlp")
157
- and hasattr(layer.attn, "c_attn")
158
- and hasattr(layer.mlp, "c_fc")
159
- ):
160
- return True
161
-
162
- return False
163
-
164
- def describe(self, model: ModuleType | Any) -> dict[str, Any]:
165
- """
166
- Get structural description of the HuggingFace GPT-2 model.
167
-
168
- Returns the required format for validation gates:
169
- - n_layer: int
170
- - heads_per_layer: List[int]
171
- - mlp_dims: List[int]
172
- - tying: Dict[str, str] (weight tying map)
173
-
174
- Args:
175
- model: The HuggingFace GPT-2 model to describe
176
-
177
- Returns:
178
- Dictionary with model structure info in required format
179
- """
180
- # Determine model structure
181
- if hasattr(model, "transformer"):
182
- # GPT2LMHeadModel structure
183
- transformer = model.transformer
184
- layers = transformer.h
185
- config = model.config
186
- elif hasattr(model, "h"):
187
- # Direct GPT2Model structure
188
- layers = model.h
189
- config = model.config
190
- transformer = model
191
- else:
192
- raise AdapterError(
193
- code="E202",
194
- message=(
195
- "ADAPTER-STRUCTURE-INVALID: unrecognized HuggingFace GPT-2 model structure"
196
- ),
197
- details={"model_class": model.__class__.__name__},
198
- )
199
-
200
- # Extract basic configuration
201
- n_layers = len(layers)
202
- n_heads = getattr(
203
- config, "n_head", getattr(config, "num_attention_heads", None)
204
- )
205
- hidden_size = getattr(config, "hidden_size", getattr(config, "d_model", None))
206
- vocab_size = getattr(config, "vocab_size", None)
207
-
208
- if n_heads is None or hidden_size is None:
209
- raise AdapterError(
210
- code="E202",
211
- message=(
212
- "ADAPTER-STRUCTURE-INVALID: missing n_heads or hidden_size in config"
213
- ),
214
- details={"model_class": model.__class__.__name__},
215
- )
216
-
217
- # Get device info
218
- try:
219
- device = next(model.parameters()).device
220
- except StopIteration:
221
- device = torch.device("cpu")
222
-
223
- # Calculate total parameters
224
- total_params = sum(p.numel() for p in model.parameters())
225
-
226
- # Get MLP dimensions for each layer
227
- mlp_dims = []
228
- heads_per_layer = []
229
-
230
- for layer_idx in range(n_layers):
231
- layer = layers[layer_idx]
232
-
233
- # For GPT-2, all layers have the same head count
234
- heads_per_layer.append(n_heads)
235
-
236
- # Get MLP intermediate dimension
237
- # HuggingFace GPT-2 uses Conv1D layers where weight shape is (in_features, out_features)
238
- if hasattr(layer.mlp.c_fc, "weight"):
239
- if hasattr(layer.mlp.c_fc, "nf"): # Conv1D layer
240
- mlp_dim = layer.mlp.c_fc.nf # out_features for Conv1D
241
- else:
242
- # Regular linear layer: (out_features, in_features)
243
- mlp_dim = layer.mlp.c_fc.weight.shape[0]
244
- else:
245
- # Fallback to config
246
- mlp_dim = getattr(config, "n_inner", hidden_size * 4)
247
-
248
- mlp_dims.append(mlp_dim)
249
-
250
- # Detect weight tying (lm_head ↔ wte)
251
- tying_map = {}
252
- if hasattr(model, "lm_head") and hasattr(transformer, "wte"):
253
- # Check if the weights are the same tensor (tied)
254
- if model.lm_head.weight is transformer.wte.weight:
255
- tying_map["lm_head.weight"] = "transformer.wte.weight"
256
-
257
- # Build the required description format
258
- description = {
259
- # Required fields for validation gates
260
- "n_layer": n_layers,
261
- "heads_per_layer": heads_per_layer,
262
- "mlp_dims": mlp_dims,
263
- "tying": tying_map, # Use 'tying' instead of 'weight_tying' as per spec
264
- # Additional useful information
265
- "model_type": "gpt2",
266
- "model_class": model.__class__.__name__,
267
- "n_heads": n_heads,
268
- "hidden_size": hidden_size,
269
- "vocab_size": vocab_size,
270
- "total_params": total_params,
271
- "device": str(device),
272
- # HuggingFace specific info
273
- "hf_model_type": getattr(config, "model_type", "gpt2"),
274
- "hf_config_class": config.__class__.__name__
275
- if hasattr(config, "__class__")
276
- else "unknown",
277
- # Architecture details
278
- "architecture": {
279
- "has_lm_head": hasattr(model, "lm_head"),
280
- "has_transformer_wrapper": hasattr(model, "transformer"),
281
- "layer_norm_type": "pre", # GPT-2 uses pre-layer norm
282
- "activation": getattr(config, "activation_function", "gelu_new"),
283
- "positional_encoding": "learned", # GPT-2 uses learned position embeddings
284
- "use_bias": getattr(config, "use_bias", True),
285
- "split_size": getattr(config, "split_size", None),
286
- },
287
- }
288
-
289
- return description
290
-
291
- def _extract_weight_tying_info(self, model: ModuleType | Any) -> dict[str, str]:
292
- """
293
- Extract weight tying relationships from the model.
294
-
295
- Args:
296
- model: The model to analyze
297
-
298
- Returns:
299
- Dictionary mapping tied parameter names to their source parameter names
300
- """
301
- tying_info = {}
302
-
303
- # Check for lm_head ↔ wte tying (most common in GPT-2)
304
- if hasattr(model, "lm_head") and hasattr(model, "transformer"):
305
- if hasattr(model.transformer, "wte"):
306
- if model.lm_head.weight is model.transformer.wte.weight:
307
- tying_info["lm_head.weight"] = "transformer.wte.weight"
308
-
309
- # Could be extended for other tying relationships
310
- return tying_info
311
-
312
- def _restore_weight_tying(
313
- self, model: ModuleType | Any, tied_param: str, source_param: str
314
- ) -> None:
315
- """
316
- Restore a weight tying relationship between parameters.
317
-
318
- Args:
319
- model: The model to modify
320
- tied_param: Name of the parameter that should be tied
321
- source_param: Name of the source parameter to tie to
322
- """
323
- # This is a placeholder for weight tying restoration logic
324
- # In practice, this would need to handle the specific tying relationships
325
- # For now, we just warn about broken tying
326
- print(
327
- f"Warning: Weight tying relationship {tied_param} -> {source_param} may have been broken during restore"
328
- )
329
-
330
- def validate_split_size(self, model: ModuleType | Any) -> bool:
331
- """
332
- Validate that split_size handling is correct for HuggingFace models.
333
-
334
- Args:
335
- model: The model to validate
336
-
337
- Returns:
338
- True if split_size is handled correctly
339
- """
340
- if not hasattr(model, "config"):
341
- return True # No config to validate
342
-
343
- config = model.config
344
- split_size = getattr(config, "split_size", None)
345
-
346
- if split_size is None:
347
- return True # No split_size specified
348
-
349
- # Validate that c_attn layers respect split_size
350
- try:
351
- desc = self.describe(model)
352
- if desc["n_layer"] > 0:
353
- # Check first layer as representative
354
- if hasattr(model, "transformer"):
355
- layer = model.transformer.h[0]
356
- else:
357
- layer = model.h[0]
358
-
359
- c_attn = layer.attn.c_attn
360
- if hasattr(c_attn, "weight"):
361
- # For Conv1D: weight shape is (in_features, out_features)
362
- # out_features should be 3 * hidden_size for combined Q,K,V
363
- expected_out = 3 * desc["hidden_size"]
364
- actual_out = (
365
- c_attn.weight.shape[1]
366
- if hasattr(c_attn, "nf")
367
- else c_attn.weight.shape[0]
368
- )
369
-
370
- return actual_out == expected_out
371
-
372
- return True
373
-
374
- except Exception:
375
- return False
376
-
377
- def get_layer_modules(
378
- self, model: ModuleType | Any, layer_idx: int
379
- ) -> dict[str, ModuleType | Any]:
380
- """
381
- Get the modules for a specific layer (utility method).
382
-
383
- Args:
384
- model: The HuggingFace GPT-2 model
385
- layer_idx: Index of the layer to get modules for
386
-
387
- Returns:
388
- Dictionary mapping module names to modules
389
- """
390
- if hasattr(model, "transformer"):
391
- layer = model.transformer.h[layer_idx]
392
- else:
393
- layer = model.h[layer_idx]
394
-
395
- modules = {
396
- "attn.c_attn": layer.attn.c_attn, # Combined Q,K,V projection
397
- "attn.c_proj": layer.attn.c_proj, # Output projection
398
- "mlp.c_fc": layer.mlp.c_fc, # Feed-forward expansion
399
- "mlp.c_proj": layer.mlp.c_proj, # Feed-forward projection
400
- "ln_1": layer.ln_1, # Layer norm 1
401
- "ln_2": layer.ln_2, # Layer norm 2
402
- }
403
-
404
- return modules