neurogit-gfn 1.0.6__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.
- gfn/README.md +29 -0
- gfn/__init__.py +116 -0
- gfn/__main__.py +10 -0
- gfn/authoring.py +1066 -0
- gfn/bundle.py +729 -0
- gfn/compiler.py +3560 -0
- gfn/discovery.py +315 -0
- gfn/harness.py +1660 -0
- gfn/kkt.py +440 -0
- gfn/studio.py +500 -0
- gfn/subspace.py +191 -0
- neurogit_gfn-1.0.6.dist-info/METADATA +366 -0
- neurogit_gfn-1.0.6.dist-info/RECORD +17 -0
- neurogit_gfn-1.0.6.dist-info/WHEEL +4 -0
- neurogit_gfn-1.0.6.dist-info/entry_points.txt +2 -0
- neurogit_gfn-1.0.6.dist-info/licenses/LICENSE +202 -0
- neurogit_gfn-1.0.6.dist-info/licenses/NOTICE +9 -0
gfn/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# `gfn` — Core NeuroGit-GFN Python Package (`1.0.6`)
|
|
2
|
+
|
|
3
|
+
`gfn` compiles conditional, unconditional, multi-token, and compositional behavioral policies directly into standard Hugging Face `PEFT` `.safetensors` adapters (`adapter_model.safetensors` + `adapter_config.json`) paired with a self-contained float64 KKT commit ledger (`gfn_ledger.npz` + `gfn_manifest.json`) for millisecond selective policy retirement (`git revert`) and multi-layer counterfactual attribution (`git blame`) — with **zero gradient-descent steps** and **zero inference-time routing overhead**.
|
|
4
|
+
|
|
5
|
+
## Package Architecture
|
|
6
|
+
|
|
7
|
+
| Module | Responsibility |
|
|
8
|
+
| :--- | :--- |
|
|
9
|
+
| `gfn/authoring.py` | Enterprise two-role GitOps workflow: staging `/pinch` intake (`propose_pinch`) -> 100% auto-generated `policies.yaml` (`save_policies_yaml` / `load_policies_yaml`) -> headless CI unseen-phrasing compiler & fail-closed verification gate (`compile_policy_book`). |
|
|
10
|
+
| `gfn/discovery.py` | Single-sweep batched multi-rule layer discovery via scale-invariant separability $S_{\text{inv}}(\ell)$ (`discover_layer_schedule`) with full-graph unsevered `register_hook` gradients. |
|
|
11
|
+
| `gfn/subspace.py` | Float64 orthonormal basis construction (`ortho_basis`), null-space shielding (`project_orthogonal`), and trace-normalized `SampleInvariantRidge`. |
|
|
12
|
+
| `gfn/kkt.py` | Coupled asymmetric squared-hinge KKT QP solver (`solve_asymmetric_hinge_qp`), Schur-complement warm start (`schur_spd_downdate`), and certified KKT rollback (`rollback_asymmetric_hinge_qp`). |
|
|
13
|
+
| `gfn/compiler.py` | Strict calibration-only `PolicySpec` contract and 3-stage compiler (`compile_policies`: conditional Dual-Cone or unconditional Single-Cone `L*` + continuation/bridge waves + topology-aware MultiToken cascade with dynamic `(N, d_in)` round-robin atom budgets). |
|
|
14
|
+
| `gfn/bundle.py` | Self-contained cold bundle (`GFNBundle`), disk-only `PEFT` `bfloat16` low-rank hook loader (`apply_peft_adapter_from_disk`), merged checkpoint exporter (`export_merged_model_dir`), cold `revert_rules`, and token-ID-exact multi-layer `blame_prompt`. |
|
|
15
|
+
| `gfn/harness.py` | Capability-introspected CausalLM loader (`discover_backbone`), chat/reasoning/tool-call template codec discovery (`DirectChatHarness`, `ReasoningSpec`, `ToolCallCodec`), batched KV-cached greedy decoder (`greedy_generate_with_ids`), and token-weighted NLL evaluator. |
|
|
16
|
+
| `gfn/studio.py` | CLI entrypoint (`python -m gfn compile | revert | blame | export-merged | chat`, including interactive `/pinch`, `/diff`, `/thinking`, `/blame`, `/revert`, `/status`, and `/log`). |
|
|
17
|
+
|
|
18
|
+
## Enterprise Two-Role GitOps Workflow
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 1. SecOps Staging Sandbox: reproduce ticket, /pinch, confirm scope, auto-generate policies.yaml
|
|
22
|
+
python -m gfn chat --model <org>/<model-id> --policies policies.yaml
|
|
23
|
+
|
|
24
|
+
# 2. Headless CI Pull-Request Gate: auto-synthesize unseen phrasings & verify fail-closed
|
|
25
|
+
python -m gfn compile --model <org>/<model-id> --policies policies.yaml --out-dir /tmp/bundle --verify
|
|
26
|
+
|
|
27
|
+
# 3. Selective Ticket Retirement (sub-2 ms cold KKT re-solve, zero retraining)
|
|
28
|
+
python -m gfn revert --bundle-dir /tmp/bundle --rules sec-4902-npm-axios-to-got --policies policies.yaml
|
|
29
|
+
```
|
gfn/__init__.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""NeuroGit-GFN (`gfn`): Rule-Addressable Weight Compilation & Neural Version-Control Algebra."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from gfn.authoring import (
|
|
6
|
+
PinchProposal,
|
|
7
|
+
PolicyReceipt,
|
|
8
|
+
compile_policy_book,
|
|
9
|
+
load_policies_yaml,
|
|
10
|
+
parse_pinch_command,
|
|
11
|
+
propose_pinch,
|
|
12
|
+
save_policies_yaml,
|
|
13
|
+
)
|
|
14
|
+
from gfn.bundle import (
|
|
15
|
+
GFNBundle,
|
|
16
|
+
StageRecord,
|
|
17
|
+
apply_peft_adapter_from_disk,
|
|
18
|
+
export_merged_model_dir,
|
|
19
|
+
sha256_file,
|
|
20
|
+
)
|
|
21
|
+
from gfn.compiler import (
|
|
22
|
+
CompilerConfig,
|
|
23
|
+
PolicySpec,
|
|
24
|
+
compile_policies,
|
|
25
|
+
compute_dynamic_atom_budget,
|
|
26
|
+
select_candidates_round_robin,
|
|
27
|
+
)
|
|
28
|
+
from gfn.discovery import (
|
|
29
|
+
compute_pair_s_inv_scores,
|
|
30
|
+
discover_layer_schedule,
|
|
31
|
+
select_schedule_from_profiles,
|
|
32
|
+
)
|
|
33
|
+
from gfn.harness import (
|
|
34
|
+
DIRECT_SYSTEM_PROMPT,
|
|
35
|
+
WIKI_SHIELD_CORPUS,
|
|
36
|
+
BackboneSpec,
|
|
37
|
+
DirectChatHarness,
|
|
38
|
+
ReasoningSpec,
|
|
39
|
+
ToolCallCodec,
|
|
40
|
+
batched_greedy_generate,
|
|
41
|
+
clean_first_line,
|
|
42
|
+
detect_norm_topology,
|
|
43
|
+
discover_backbone,
|
|
44
|
+
discover_layer_ffn_rel_path,
|
|
45
|
+
enable_full_graph_input_grads,
|
|
46
|
+
eval_token_weighted_nll,
|
|
47
|
+
greedy_generate_with_ids,
|
|
48
|
+
load_causal_lm,
|
|
49
|
+
make_layer_capture_closures,
|
|
50
|
+
paired_cluster_bootstrap,
|
|
51
|
+
select_device,
|
|
52
|
+
strip_special_suffix,
|
|
53
|
+
)
|
|
54
|
+
from gfn.kkt import rollback_asymmetric_hinge_qp, schur_spd_downdate, solve_asymmetric_hinge_qp
|
|
55
|
+
from gfn.subspace import (
|
|
56
|
+
SampleInvariantRidge,
|
|
57
|
+
nullspace_complement,
|
|
58
|
+
ortho_basis,
|
|
59
|
+
project_orthogonal,
|
|
60
|
+
safe_matmul,
|
|
61
|
+
unit_norm,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
__version__ = "1.0.6"
|
|
65
|
+
|
|
66
|
+
__all__ = [
|
|
67
|
+
"__version__",
|
|
68
|
+
"BackboneSpec",
|
|
69
|
+
"CompilerConfig",
|
|
70
|
+
"DIRECT_SYSTEM_PROMPT",
|
|
71
|
+
"DirectChatHarness",
|
|
72
|
+
"GFNBundle",
|
|
73
|
+
"PinchProposal",
|
|
74
|
+
"PolicyReceipt",
|
|
75
|
+
"PolicySpec",
|
|
76
|
+
"ReasoningSpec",
|
|
77
|
+
"SampleInvariantRidge",
|
|
78
|
+
"StageRecord",
|
|
79
|
+
"ToolCallCodec",
|
|
80
|
+
"WIKI_SHIELD_CORPUS",
|
|
81
|
+
"apply_peft_adapter_from_disk",
|
|
82
|
+
"batched_greedy_generate",
|
|
83
|
+
"clean_first_line",
|
|
84
|
+
"compile_policies",
|
|
85
|
+
"compile_policy_book",
|
|
86
|
+
"compute_dynamic_atom_budget",
|
|
87
|
+
"compute_pair_s_inv_scores",
|
|
88
|
+
"detect_norm_topology",
|
|
89
|
+
"discover_backbone",
|
|
90
|
+
"discover_layer_ffn_rel_path",
|
|
91
|
+
"discover_layer_schedule",
|
|
92
|
+
"enable_full_graph_input_grads",
|
|
93
|
+
"eval_token_weighted_nll",
|
|
94
|
+
"export_merged_model_dir",
|
|
95
|
+
"greedy_generate_with_ids",
|
|
96
|
+
"load_causal_lm",
|
|
97
|
+
"load_policies_yaml",
|
|
98
|
+
"make_layer_capture_closures",
|
|
99
|
+
"nullspace_complement",
|
|
100
|
+
"ortho_basis",
|
|
101
|
+
"paired_cluster_bootstrap",
|
|
102
|
+
"parse_pinch_command",
|
|
103
|
+
"project_orthogonal",
|
|
104
|
+
"propose_pinch",
|
|
105
|
+
"rollback_asymmetric_hinge_qp",
|
|
106
|
+
"safe_matmul",
|
|
107
|
+
"save_policies_yaml",
|
|
108
|
+
"schur_spd_downdate",
|
|
109
|
+
"select_candidates_round_robin",
|
|
110
|
+
"select_schedule_from_profiles",
|
|
111
|
+
"select_device",
|
|
112
|
+
"sha256_file",
|
|
113
|
+
"solve_asymmetric_hinge_qp",
|
|
114
|
+
"strip_special_suffix",
|
|
115
|
+
"unit_norm",
|
|
116
|
+
]
|