NZFC-GRAM v1.2.1 final: non-quantized BF16 long-memory validation and loader
Browse files- COMMERCIAL_LICENSE.md +0 -1
- FINAL_NONQUANT_VALIDATION.md +71 -0
- LICENSE +0 -1
- NZFC_GRAM_RELEASE_MANIFEST.json +48 -15
- PATENT_NOTICE.md +5 -13
- README.md +64 -72
- SECURITY.md +0 -3
- examples/__pycache__/nonquant_bf16_final_usage.cpython-312.pyc +0 -0
- examples/__pycache__/quick_nonquant_bf16.cpython-312.pyc +0 -0
- examples/nonquant_bf16_final_usage.py +52 -0
- examples/quick_nonquant_bf16.py +16 -0
- nzfc_gram_runtime/__init__.py +6 -0
- nzfc_gram_runtime/__pycache__/__init__.cpython-312.pyc +0 -0
- nzfc_gram_runtime/__pycache__/nonquant.cpython-312.pyc +0 -0
- nzfc_gram_runtime/nonquant.py +344 -0
- release_notes/NZFC_GRAM_v1_2_1_nonquant_final_release.md +30 -0
- requirements-nonquant.txt +10 -0
- validation_evidence/nonquant_v121_final/NONQUANT_FINAL_VALIDATION_SUMMARY.json +38 -0
COMMERCIAL_LICENSE.md
CHANGED
|
@@ -22,4 +22,3 @@ For commercial licensing, patent licensing, paid evaluation, or technology-trans
|
|
| 22 |
Jewon Moon / Singularity Principle Institute
|
| 23 |
|
| 24 |
director@singularityprinciple.com
|
| 25 |
-
|
|
|
|
| 22 |
Jewon Moon / Singularity Principle Institute
|
| 23 |
|
| 24 |
director@singularityprinciple.com
|
|
|
FINAL_NONQUANT_VALIDATION.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NZFC-GRAM v1.2.1 Non-Quantized Final Validation
|
| 2 |
+
|
| 3 |
+
Date: 2026-06-08
|
| 4 |
+
|
| 5 |
+
This document records the final non-quantized validation status for NZFC-GRAM v1.2.1.
|
| 6 |
+
|
| 7 |
+
## Result
|
| 8 |
+
|
| 9 |
+
```json
|
| 10 |
+
{
|
| 11 |
+
"created_at": "2026-06-08 06:30:26",
|
| 12 |
+
"repo_main_sha": "239818353eaaf876a6a3f31a3543e6beca512ede",
|
| 13 |
+
"tests": 11,
|
| 14 |
+
"passed": 11,
|
| 15 |
+
"failed": 0,
|
| 16 |
+
"all_passed": true,
|
| 17 |
+
"hotfix_present": true,
|
| 18 |
+
"marker_redaction_present": true,
|
| 19 |
+
"underscore_norm_present": true,
|
| 20 |
+
"quantization": "none",
|
| 21 |
+
"load_mode": "nonquant_bf16_fp16_balanced_cpu_disk_offload",
|
| 22 |
+
"dtype": "torch.bfloat16",
|
| 23 |
+
"device_map": "balanced_low_0",
|
| 24 |
+
"gpu_max_memory_gib": 11,
|
| 25 |
+
"model_loaded": true,
|
| 26 |
+
"static_nzfc_archive_loaded": true,
|
| 27 |
+
"local_sqlite_memory_persistence_tested": true,
|
| 28 |
+
"generation_patch": "use_cache_false_oom_retry",
|
| 29 |
+
"safety_boundary": "external_nzfc_archive_and_local_long_term_memory_not_internal_10m_context",
|
| 30 |
+
"vram_final": {
|
| 31 |
+
"gpu1_alloc_gb": 10.217637376,
|
| 32 |
+
"gpu1_reserved_gb": 11.448352768,
|
| 33 |
+
"gpu1_peak_gb": 11.845826048,
|
| 34 |
+
"max_alloc_gb": 10.217637376,
|
| 35 |
+
"max_peak_gb": 11.845826048
|
| 36 |
+
},
|
| 37 |
+
"key_test_metrics": {
|
| 38 |
+
"T8_slope_tokens_per_turn": 105.964,
|
| 39 |
+
"T8_slope_limit": 220.0,
|
| 40 |
+
"T8_growth_ratio": 1.392,
|
| 41 |
+
"T8_growth_ratio_limit": 3.2,
|
| 42 |
+
"T8_hard_cap_context_tokens": 16000,
|
| 43 |
+
"T10_gram_trace_budget": 1.861558246118043,
|
| 44 |
+
"T10_gram_soft_cap": 4.35,
|
| 45 |
+
"T10_gram_soft_tau_pass": true
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Interpretation
|
| 51 |
+
|
| 52 |
+
NZFC-GRAM v1.2.1 passed a fresh-download, non-quantized BF16 end-to-end long-memory test with Gemma 4 E2B-IT.
|
| 53 |
+
|
| 54 |
+
No 4-bit or 8-bit quantization was used.
|
| 55 |
+
|
| 56 |
+
The system uses external NZFC archive retrieval and local SQLite long-term memory under a Readout-Gramian Context Governor.
|
| 57 |
+
It does not claim internal 10M-token model memory.
|
| 58 |
+
|
| 59 |
+
## Passed test classes
|
| 60 |
+
|
| 61 |
+
1. Repo/runtime/hotfix/nonquant model integrity
|
| 62 |
+
2. Static NZFC 10M exact retrieval
|
| 63 |
+
3. Memory-boundary generation
|
| 64 |
+
4. Project-scope memory recall across sessions
|
| 65 |
+
5. Session/project/user scope isolation
|
| 66 |
+
6. Tombstone deleted-memory no-leak
|
| 67 |
+
7. Malicious memory marker/raw instruction redaction
|
| 68 |
+
8. Exact cross-session recall with Markdown underscore normalization
|
| 69 |
+
9. Context/KV-bloat slope control
|
| 70 |
+
10. SQLite persistence after runtime reload
|
| 71 |
+
11. Final safety and Readout-Gramian budget sanity
|
LICENSE
CHANGED
|
@@ -10,4 +10,3 @@ https://creativecommons.org/licenses/by-nc/4.0/
|
|
| 10 |
No patent license is granted by this repository.
|
| 11 |
|
| 12 |
Commercial use requires a separate written license.
|
| 13 |
-
|
|
|
|
| 10 |
No patent license is granted by this repository.
|
| 11 |
|
| 12 |
Commercial use requires a separate written license.
|
|
|
NZFC_GRAM_RELEASE_MANIFEST.json
CHANGED
|
@@ -1,23 +1,56 @@
|
|
| 1 |
{
|
| 2 |
-
"name": "NZFC-GRAM v1.2.1
|
| 3 |
"repo_id": "SingularityPrinciple/Gemma-E2B-IT-10M-Chat",
|
| 4 |
-
"
|
| 5 |
-
"
|
| 6 |
-
"
|
| 7 |
"base_model": "google/gemma-4-E2B-it",
|
| 8 |
"contains_base_model_weights": false,
|
| 9 |
-
"
|
| 10 |
-
|
| 11 |
-
"
|
| 12 |
-
"
|
| 13 |
-
"
|
| 14 |
-
"preserve external-memory boundary"
|
| 15 |
],
|
| 16 |
-
"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
},
|
| 20 |
"license": "cc-by-nc-4.0",
|
| 21 |
"commercial_use": "separate written license required",
|
| 22 |
-
"patent_license": "not granted by public repository license"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"name": "NZFC-GRAM v1.2.1 Non-Quantized Final",
|
| 3 |
"repo_id": "SingularityPrinciple/Gemma-E2B-IT-10M-Chat",
|
| 4 |
+
"repo_url": "https://huggingface.co/SingularityPrinciple/Gemma-E2B-IT-10M-Chat",
|
| 5 |
+
"created_at": "2026-06-08 07:23:24",
|
| 6 |
+
"version": "1.2.1-nonquant-final",
|
| 7 |
"base_model": "google/gemma-4-E2B-it",
|
| 8 |
"contains_base_model_weights": false,
|
| 9 |
+
"runtime_package": "nzfc_gram_runtime",
|
| 10 |
+
"interfaces": [
|
| 11 |
+
"python_library",
|
| 12 |
+
"local_cli",
|
| 13 |
+
"nonquant_helper"
|
|
|
|
| 14 |
],
|
| 15 |
+
"no_api_server": true,
|
| 16 |
+
"public_release_date": "2026-06-08",
|
| 17 |
+
"patent_status": "patent application filed / patent pending",
|
|
|
|
| 18 |
"license": "cc-by-nc-4.0",
|
| 19 |
"commercial_use": "separate written license required",
|
| 20 |
+
"patent_license": "not granted by public repository license",
|
| 21 |
+
"quantization": "none for final validation",
|
| 22 |
+
"nonquant_loader": {
|
| 23 |
+
"module": "nzfc_gram_runtime.nonquant",
|
| 24 |
+
"functions": [
|
| 25 |
+
"attach_nonquant_gemma",
|
| 26 |
+
"patch_generation_use_cache_false"
|
| 27 |
+
],
|
| 28 |
+
"validated_dtype": "torch.bfloat16",
|
| 29 |
+
"validated_device_map": "balanced_low_0",
|
| 30 |
+
"validated_gpu_max_memory_gib": 11
|
| 31 |
+
},
|
| 32 |
+
"external_memory_boundary": "full_10m_archive_not_inserted_into_model_context",
|
| 33 |
+
"validation": {
|
| 34 |
+
"tests": 11,
|
| 35 |
+
"passed": 11,
|
| 36 |
+
"failed": 0,
|
| 37 |
+
"all_passed": true,
|
| 38 |
+
"hotfix_present": true,
|
| 39 |
+
"marker_redaction_present": true,
|
| 40 |
+
"underscore_norm_present": true,
|
| 41 |
+
"static_nzfc_archive_loaded": true,
|
| 42 |
+
"local_sqlite_memory_persistence_tested": true,
|
| 43 |
+
"generation_patch": "use_cache_false_oom_retry",
|
| 44 |
+
"safety_boundary": "external_nzfc_archive_and_local_long_term_memory_not_internal_10m_context",
|
| 45 |
+
"key_test_metrics": {
|
| 46 |
+
"T8_slope_tokens_per_turn": 105.964,
|
| 47 |
+
"T8_slope_limit": 220.0,
|
| 48 |
+
"T8_growth_ratio": 1.392,
|
| 49 |
+
"T8_growth_ratio_limit": 3.2,
|
| 50 |
+
"T8_hard_cap_context_tokens": 16000,
|
| 51 |
+
"T10_gram_trace_budget": 1.861558246118043,
|
| 52 |
+
"T10_gram_soft_cap": 4.35,
|
| 53 |
+
"T10_gram_soft_tau_pass": true
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
}
|
PATENT_NOTICE.md
CHANGED
|
@@ -4,15 +4,12 @@ This repository is released after patent filing for the NZFC-GRAM external-memor
|
|
| 4 |
|
| 5 |
Patent status:
|
| 6 |
|
| 7 |
-
- Status: patent application filed
|
| 8 |
-
-
|
| 9 |
-
- Public
|
| 10 |
-
- Public release date: 2026-06-05
|
| 11 |
|
| 12 |
No express or implied patent license is granted by this repository.
|
| 13 |
|
| 14 |
-
The public files may include non-commercial research/evaluation code, examples, runtime wrappers, evidence logs, documentation, and model-card material. Commercial use, production deployment, enterprise integration, paid API usage, model-serving integration, resale, sublicensing, or incorporation into commercial products requires a separate written license from the rights holder.
|
| 15 |
-
|
| 16 |
Patent-pending subject matter may include, without limitation:
|
| 17 |
|
| 18 |
- Readout-Gramian-based external-memory evidence selection,
|
|
@@ -24,16 +21,11 @@ Patent-pending subject matter may include, without limitation:
|
|
| 24 |
- claim-evidence verification,
|
| 25 |
- run/session/project/user scoped memory governance,
|
| 26 |
- tombstone/deleted-memory leakage prevention,
|
| 27 |
-
- AI/LLM inference gateway and local runtime implementations
|
| 28 |
-
|
| 29 |
-
Prior public release evidence:
|
| 30 |
-
|
| 31 |
-
- Repository: https://huggingface.co/SingularityPrinciple/Gemma-E2B-IT-10M-Chat
|
| 32 |
-
- Commit evidence: https://huggingface.co/SingularityPrinciple/Gemma-E2B-IT-10M-Chat/commit/1322cafa169d24972e830280a5254b807302b36d
|
| 33 |
|
| 34 |
Contact for commercial and patent licensing:
|
| 35 |
|
| 36 |
Jewon Moon / Singularity Principle Institute
|
| 37 |
|
| 38 |
director@singularityprinciple.com
|
| 39 |
-
|
|
|
|
| 4 |
|
| 5 |
Patent status:
|
| 6 |
|
| 7 |
+
- Status: patent application filed / patent pending
|
| 8 |
+
- Public release version: NZFC-GRAM v1.2.1 Non-Quantized Final
|
| 9 |
+
- Public release date: 2026-06-08
|
|
|
|
| 10 |
|
| 11 |
No express or implied patent license is granted by this repository.
|
| 12 |
|
|
|
|
|
|
|
| 13 |
Patent-pending subject matter may include, without limitation:
|
| 14 |
|
| 15 |
- Readout-Gramian-based external-memory evidence selection,
|
|
|
|
| 21 |
- claim-evidence verification,
|
| 22 |
- run/session/project/user scoped memory governance,
|
| 23 |
- tombstone/deleted-memory leakage prevention,
|
| 24 |
+
- AI/LLM inference gateway and local runtime implementations,
|
| 25 |
+
- non-quantized local long-memory runtime with context-governed evidence packing.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
Contact for commercial and patent licensing:
|
| 28 |
|
| 29 |
Jewon Moon / Singularity Principle Institute
|
| 30 |
|
| 31 |
director@singularityprinciple.com
|
|
|
README.md
CHANGED
|
@@ -10,23 +10,60 @@ tags:
|
|
| 10 |
- untrusted-memory-redaction
|
| 11 |
- claim-evidence-verification
|
| 12 |
- non-commercial
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
# Gemma E2B-IT + NZFC-GRAM v1.2
|
|
|
|
|
|
|
| 16 |
|
| 17 |
This repository provides a local long-term-memory runtime for `google/gemma-4-E2B-it` using NZFC-GRAM external memory.
|
| 18 |
|
| 19 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
- Public copyright license: CC BY-NC 4.0
|
| 26 |
-
- Commercial use: separate written license required
|
| 27 |
-
- Patent license: not granted by this repository
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
## What this is
|
| 32 |
|
|
@@ -45,72 +82,32 @@ It is a local runtime that combines:
|
|
| 45 |
|
| 46 |
The model receives only a small context-governed verified memory pack. The full 10M archive is never inserted into the model context.
|
| 47 |
|
| 48 |
-
##
|
| 49 |
|
| 50 |
```bash
|
| 51 |
git lfs install
|
| 52 |
git clone https://huggingface.co/SingularityPrinciple/Gemma-E2B-IT-10M-Chat
|
| 53 |
cd Gemma-E2B-IT-10M-Chat
|
| 54 |
pip install -r requirements.txt
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
You may need a Hugging Face token with access to `google/gemma-4-E2B-it`:
|
| 58 |
-
|
| 59 |
-
```bash
|
| 60 |
export HF_TOKEN=your_token_here
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
```bash
|
| 66 |
-
python -m nzfc_gram_runtime.cli --repo-dir . --user-id user001 --project-id default --session-id main
|
| 67 |
-
```
|
| 68 |
-
|
| 69 |
-
CLI commands:
|
| 70 |
-
|
| 71 |
-
```text
|
| 72 |
-
/remember <text>
|
| 73 |
-
/forget_tag <tag>
|
| 74 |
-
/reset_session
|
| 75 |
-
/stats
|
| 76 |
-
/exit
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
## Python usage
|
| 80 |
|
| 81 |
```python
|
| 82 |
from nzfc_gram_runtime import NZFCGramLongMemoryChat
|
|
|
|
| 83 |
|
| 84 |
-
bot = NZFCGramLongMemoryChat(repo_dir='.', model_id='google/gemma-4-E2B-it')
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
'내가 선호하는 라이선스는 CC BY-NC 4.0이라고 기억해줘.',
|
| 88 |
-
user_id='user001',
|
| 89 |
-
project_id='demo',
|
| 90 |
-
session_id='s1',
|
| 91 |
-
save_scope='project',
|
| 92 |
-
)
|
| 93 |
-
print(out['answer'])
|
| 94 |
|
| 95 |
-
out = bot.chat(
|
| 96 |
-
'내가 선호한다고 말한 라이선스가 뭐였지?',
|
| 97 |
-
user_id='user001',
|
| 98 |
-
project_id='demo',
|
| 99 |
-
session_id='s2',
|
| 100 |
-
save_scope='project',
|
| 101 |
-
)
|
| 102 |
print(out['answer'])
|
| 103 |
```
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
## Memory scopes
|
| 108 |
-
|
| 109 |
-
- `session`: remembered only in the same session.
|
| 110 |
-
- `project`: remembered across sessions in the same project.
|
| 111 |
-
- `user`: remembered across all projects for the same user.
|
| 112 |
-
|
| 113 |
-
Default chat turns may be saved with `save_scope='project'`, enabling practical long-term memory across sessions.
|
| 114 |
|
| 115 |
## Safety boundary
|
| 116 |
|
|
@@ -120,20 +117,16 @@ Untrusted memory that looks like a prompt-injection or internal-memory claim is
|
|
| 120 |
|
| 121 |
The runtime explicitly avoids claims that Gemma internally remembered, stored, attended to, or processed a 10M-token archive.
|
| 122 |
|
| 123 |
-
##
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
-
- static NZFC archive retrieval ran on every turn,
|
| 129 |
-
- session memory retrieval ran on every turn,
|
| 130 |
-
- Context Governor stayed under the 16,000-token hard cap,
|
| 131 |
-
- stale-run memory leak count was 0,
|
| 132 |
-
- deleted-memory leak count was 0,
|
| 133 |
-
- malicious raw-text leak count was 0,
|
| 134 |
-
- unsafe internal-10M-memory claim count was 0,
|
| 135 |
-
- maximum combined prompt was 4,235 tokens,
|
| 136 |
-
- maximum Readout-Gramian trace budget was 4.0767 under the configured soft cap 4.35.
|
| 137 |
|
| 138 |
## Non-claims
|
| 139 |
|
|
@@ -147,4 +140,3 @@ NZFC-GRAM v1.2 passed a seven-turn end-to-end test with Gemma 4 E2B-IT:
|
|
| 147 |
Jewon Moon / Singularity Principle Institute
|
| 148 |
|
| 149 |
director@singularityprinciple.com
|
| 150 |
-
|
|
|
|
| 10 |
- untrusted-memory-redaction
|
| 11 |
- claim-evidence-verification
|
| 12 |
- non-commercial
|
| 13 |
+
- non-quantized
|
| 14 |
+
- bf16
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# Gemma E2B-IT + NZFC-GRAM v1.2.1
|
| 18 |
+
|
| 19 |
+
**Non-Quantized BF16 Local Long-Term Memory Runtime**
|
| 20 |
|
| 21 |
This repository provides a local long-term-memory runtime for `google/gemma-4-E2B-it` using NZFC-GRAM external memory.
|
| 22 |
|
| 23 |
+
## Final validation status
|
| 24 |
+
|
| 25 |
+
**NZFC-GRAM v1.2.1 passed the final fresh-download non-quantized BF16 long-memory test.**
|
| 26 |
+
|
| 27 |
+
```json
|
| 28 |
+
{
|
| 29 |
+
"tests": 11,
|
| 30 |
+
"passed": 11,
|
| 31 |
+
"failed": 0,
|
| 32 |
+
"all_passed": true,
|
| 33 |
+
"quantization": "none",
|
| 34 |
+
"dtype": "torch.bfloat16",
|
| 35 |
+
"device_map": "balanced_low_0",
|
| 36 |
+
"model_loaded": true,
|
| 37 |
+
"static_nzfc_archive_loaded": true,
|
| 38 |
+
"local_sqlite_memory_persistence_tested": true
|
| 39 |
+
}
|
| 40 |
+
```
|
| 41 |
|
| 42 |
+
The final test used **no 4-bit or 8-bit quantization**.
|
| 43 |
+
Gemma 4 E2B-IT was loaded in non-quantized BF16 mode with balanced/offload.
|
| 44 |
+
|
| 45 |
+
Validation covered:
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
- Hugging Face fresh download
|
| 48 |
+
- v1.2.1 runtime hotfix detection
|
| 49 |
+
- static NZFC 10M archive exact retrieval
|
| 50 |
+
- project/session/user-scoped local long-term memory
|
| 51 |
+
- tombstone deleted-memory no-leak
|
| 52 |
+
- malicious-memory marker and raw instruction redaction
|
| 53 |
+
- exact cross-session recall with underscore normalization
|
| 54 |
+
- context/KV-bloat slope control
|
| 55 |
+
- SQLite persistence after runtime reload
|
| 56 |
+
- final Readout-Gramian budget sanity
|
| 57 |
+
|
| 58 |
+
Key quantitative metrics:
|
| 59 |
+
|
| 60 |
+
```text
|
| 61 |
+
T8 context slope: 105.964 tokens/turn
|
| 62 |
+
T8 growth ratio: 1.392
|
| 63 |
+
Context hard cap: 16000 tokens
|
| 64 |
+
T10 Readout-Gramian trace budget: 1.861558246118043
|
| 65 |
+
Readout-Gramian soft cap: 4.35
|
| 66 |
+
```
|
| 67 |
|
| 68 |
## What this is
|
| 69 |
|
|
|
|
| 82 |
|
| 83 |
The model receives only a small context-governed verified memory pack. The full 10M archive is never inserted into the model context.
|
| 84 |
|
| 85 |
+
## Non-quantized BF16 usage
|
| 86 |
|
| 87 |
```bash
|
| 88 |
git lfs install
|
| 89 |
git clone https://huggingface.co/SingularityPrinciple/Gemma-E2B-IT-10M-Chat
|
| 90 |
cd Gemma-E2B-IT-10M-Chat
|
| 91 |
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
export HF_TOKEN=your_token_here
|
| 93 |
+
python examples/nonquant_bf16_final_usage.py
|
| 94 |
```
|
| 95 |
|
| 96 |
+
Python usage:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
```python
|
| 99 |
from nzfc_gram_runtime import NZFCGramLongMemoryChat
|
| 100 |
+
from nzfc_gram_runtime.nonquant import attach_nonquant_gemma, patch_generation_use_cache_false
|
| 101 |
|
| 102 |
+
bot = NZFCGramLongMemoryChat(repo_dir='.', model_id='google/gemma-4-E2B-it', load_model=False, require_model=False)
|
| 103 |
+
attach_nonquant_gemma(bot, device_map='balanced_low_0', gpu_max_memory_gib=11, cpu_max_memory_gib=48, prefer_bf16=True)
|
| 104 |
+
patch_generation_use_cache_false(bot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
out = bot.chat('내가 전에 말한 내용을 기억해?', user_id='user001', project_id='demo', session_id='s1')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
print(out['answer'])
|
| 108 |
```
|
| 109 |
|
| 110 |
+
If you get CUDA OOM, lower `gpu_max_memory_gib` to 10, 9, or 8.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
## Safety boundary
|
| 113 |
|
|
|
|
| 117 |
|
| 118 |
The runtime explicitly avoids claims that Gemma internally remembered, stored, attended to, or processed a 10M-token archive.
|
| 119 |
|
| 120 |
+
## Patent and license status
|
| 121 |
|
| 122 |
+
- Patent status: patent application filed / patent pending
|
| 123 |
+
- Public release version: NZFC-GRAM v1.2.1 Non-Quantized Final
|
| 124 |
+
- Public release date: 2026-06-08
|
| 125 |
+
- Public copyright license: CC BY-NC 4.0
|
| 126 |
+
- Commercial use: separate written license required
|
| 127 |
+
- Patent license: not granted by this repository
|
| 128 |
|
| 129 |
+
See `PATENT_NOTICE.md` and `COMMERCIAL_LICENSE.md`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
## Non-claims
|
| 132 |
|
|
|
|
| 140 |
Jewon Moon / Singularity Principle Institute
|
| 141 |
|
| 142 |
director@singularityprinciple.com
|
|
|
SECURITY.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
| 2 |
|
| 3 |
NZFC-GRAM treats retrieved memory as evidence, not instruction.
|
| 4 |
|
| 5 |
-
The runtime is designed to reduce the risk that external memories, user notes, retrieved files, or prompt-injection-like records override system behavior.
|
| 6 |
-
|
| 7 |
Security-relevant mechanisms include:
|
| 8 |
|
| 9 |
- source/authority metadata for memory cards,
|
|
@@ -20,4 +18,3 @@ Security-relevant mechanisms include:
|
|
| 20 |
This repository is a research/runtime release and is not a formal production security certification.
|
| 21 |
|
| 22 |
Do not store secrets, credentials, private keys, regulated personal data, or confidential customer data in the local memory store unless you have implemented the necessary security, encryption, access-control, audit, and retention policies.
|
| 23 |
-
|
|
|
|
| 2 |
|
| 3 |
NZFC-GRAM treats retrieved memory as evidence, not instruction.
|
| 4 |
|
|
|
|
|
|
|
| 5 |
Security-relevant mechanisms include:
|
| 6 |
|
| 7 |
- source/authority metadata for memory cards,
|
|
|
|
| 18 |
This repository is a research/runtime release and is not a formal production security certification.
|
| 19 |
|
| 20 |
Do not store secrets, credentials, private keys, regulated personal data, or confidential customer data in the local memory store unless you have implemented the necessary security, encryption, access-control, audit, and retention policies.
|
|
|
examples/__pycache__/nonquant_bf16_final_usage.cpython-312.pyc
ADDED
|
Binary file (1.56 kB). View file
|
|
|
examples/__pycache__/quick_nonquant_bf16.cpython-312.pyc
ADDED
|
Binary file (933 Bytes). View file
|
|
|
examples/nonquant_bf16_final_usage.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# examples/nonquant_bf16_final_usage.py
|
| 2 |
+
from nzfc_gram_runtime import NZFCGramLongMemoryChat
|
| 3 |
+
from nzfc_gram_runtime.nonquant import attach_nonquant_gemma, patch_generation_use_cache_false
|
| 4 |
+
|
| 5 |
+
bot = NZFCGramLongMemoryChat(
|
| 6 |
+
repo_dir='.',
|
| 7 |
+
model_id='google/gemma-4-E2B-it',
|
| 8 |
+
load_model=False,
|
| 9 |
+
require_model=False,
|
| 10 |
+
preload_static_memory=True,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
meta = attach_nonquant_gemma(
|
| 14 |
+
bot,
|
| 15 |
+
model_id='google/gemma-4-E2B-it',
|
| 16 |
+
device_map='balanced_low_0',
|
| 17 |
+
gpu_max_memory_gib=11,
|
| 18 |
+
cpu_max_memory_gib=48,
|
| 19 |
+
prefer_bf16=True,
|
| 20 |
+
use_fp32=False,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
patch_generation_use_cache_false(bot)
|
| 24 |
+
|
| 25 |
+
print('MODEL META:', meta)
|
| 26 |
+
|
| 27 |
+
out1 = bot.chat(
|
| 28 |
+
'앞으로 내 장기 별명은 AlphaFox_Final 이라고 기억해줘.',
|
| 29 |
+
user_id='user001',
|
| 30 |
+
project_id='demo',
|
| 31 |
+
session_id='s1',
|
| 32 |
+
save_turn=True,
|
| 33 |
+
save_scope='project',
|
| 34 |
+
response_language='ko',
|
| 35 |
+
max_new_tokens=48,
|
| 36 |
+
)
|
| 37 |
+
print('\nTURN 1:')
|
| 38 |
+
print(out1['answer'])
|
| 39 |
+
|
| 40 |
+
out2 = bot.chat(
|
| 41 |
+
'내가 전에 말한 장기 별명이 뭐였지?',
|
| 42 |
+
user_id='user001',
|
| 43 |
+
project_id='demo',
|
| 44 |
+
session_id='s2',
|
| 45 |
+
save_turn=False,
|
| 46 |
+
response_language='ko',
|
| 47 |
+
max_new_tokens=64,
|
| 48 |
+
)
|
| 49 |
+
print('\nTURN 2:')
|
| 50 |
+
print(out2['answer'])
|
| 51 |
+
print('\nSTATUS:', out2['status'])
|
| 52 |
+
print('\nMEMORY BOUNDARY:', out2['memory_boundary'])
|
examples/quick_nonquant_bf16.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from nzfc_gram_runtime import NZFCGramLongMemoryChat
|
| 2 |
+
from nzfc_gram_runtime.nonquant import attach_nonquant_gemma, patch_generation_use_cache_false
|
| 3 |
+
|
| 4 |
+
bot = NZFCGramLongMemoryChat(repo_dir='.', load_model=False, require_model=False)
|
| 5 |
+
attach_nonquant_gemma(bot, gpu_max_memory_gib=11, device_map='balanced_low_0')
|
| 6 |
+
patch_generation_use_cache_false(bot)
|
| 7 |
+
|
| 8 |
+
out = bot.chat(
|
| 9 |
+
'NZFC-GRAM의 장기기억 경계가 내부 context인지 외부 memory retrieval인지 설명해줘.',
|
| 10 |
+
user_id='quick_user',
|
| 11 |
+
project_id='quick_project',
|
| 12 |
+
session_id='quick_session',
|
| 13 |
+
save_turn=False,
|
| 14 |
+
max_new_tokens=80,
|
| 15 |
+
)
|
| 16 |
+
print(out['answer'])
|
nzfc_gram_runtime/__init__.py
CHANGED
|
@@ -11,3 +11,9 @@ __all__ = [
|
|
| 11 |
'redact_untrusted_instruction_text',
|
| 12 |
'sanitize_model_answer',
|
| 13 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
'redact_untrusted_instruction_text',
|
| 12 |
'sanitize_model_answer',
|
| 13 |
]
|
| 14 |
+
|
| 15 |
+
# Non-quantized BF16/FP16 loading helpers, added in NZFC-GRAM v1.2.1 final.
|
| 16 |
+
try:
|
| 17 |
+
from .nonquant import attach_nonquant_gemma, patch_generation_use_cache_false
|
| 18 |
+
except Exception:
|
| 19 |
+
pass
|
nzfc_gram_runtime/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/nzfc_gram_runtime/__pycache__/__init__.cpython-312.pyc and b/nzfc_gram_runtime/__pycache__/__init__.cpython-312.pyc differ
|
|
|
nzfc_gram_runtime/__pycache__/nonquant.cpython-312.pyc
ADDED
|
Binary file (16.6 kB). View file
|
|
|
nzfc_gram_runtime/nonquant.py
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===============================================================================
|
| 2 |
+
# NZFC-GRAM nonquant.py
|
| 3 |
+
# Non-quantized BF16/FP16 loading helper for Gemma 4 E2B-IT
|
| 4 |
+
# ===============================================================================
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import gc
|
| 9 |
+
import time
|
| 10 |
+
import types
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any, Dict, Optional, Sequence
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
|
| 16 |
+
from transformers import AutoProcessor, AutoTokenizer, AutoModelForImageTextToText, AutoModelForCausalLM
|
| 17 |
+
|
| 18 |
+
from .runtime import ReadoutGramianGovernor, sanitize_model_answer
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def clear_cuda():
|
| 22 |
+
gc.collect()
|
| 23 |
+
if torch.cuda.is_available():
|
| 24 |
+
torch.cuda.empty_cache()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def vram_snapshot() -> Dict[str, float]:
|
| 28 |
+
snap: Dict[str, float] = {}
|
| 29 |
+
if not torch.cuda.is_available():
|
| 30 |
+
return snap
|
| 31 |
+
allocs = []
|
| 32 |
+
peaks = []
|
| 33 |
+
for i in range(torch.cuda.device_count()):
|
| 34 |
+
alloc = torch.cuda.memory_allocated(i) / 1e9
|
| 35 |
+
reserved = torch.cuda.memory_reserved(i) / 1e9
|
| 36 |
+
peak = torch.cuda.max_memory_allocated(i) / 1e9
|
| 37 |
+
snap[f'gpu{i}_alloc_gb'] = float(alloc)
|
| 38 |
+
snap[f'gpu{i}_reserved_gb'] = float(reserved)
|
| 39 |
+
snap[f'gpu{i}_peak_gb'] = float(peak)
|
| 40 |
+
allocs.append(alloc)
|
| 41 |
+
peaks.append(peak)
|
| 42 |
+
snap['sum_alloc_gb'] = float(sum(allocs))
|
| 43 |
+
snap['max_alloc_gb'] = float(max(allocs)) if allocs else 0.0
|
| 44 |
+
snap['max_peak_gb'] = float(max(peaks)) if peaks else 0.0
|
| 45 |
+
return snap
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def infer_input_device(model_obj):
|
| 49 |
+
try:
|
| 50 |
+
emb = model_obj.get_input_embeddings()
|
| 51 |
+
if emb is not None:
|
| 52 |
+
return next(emb.parameters()).device
|
| 53 |
+
except Exception:
|
| 54 |
+
pass
|
| 55 |
+
for p in model_obj.parameters():
|
| 56 |
+
if not getattr(p, 'is_meta', False):
|
| 57 |
+
return p.device
|
| 58 |
+
return torch.device('cpu')
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def runtime_dtype(prefer_bf16: bool = True, use_fp32: bool = False):
|
| 62 |
+
if use_fp32:
|
| 63 |
+
return torch.float32
|
| 64 |
+
if torch.cuda.is_available():
|
| 65 |
+
if prefer_bf16 and hasattr(torch.cuda, 'is_bf16_supported'):
|
| 66 |
+
try:
|
| 67 |
+
if torch.cuda.is_bf16_supported():
|
| 68 |
+
return torch.bfloat16
|
| 69 |
+
except Exception:
|
| 70 |
+
pass
|
| 71 |
+
return torch.float16
|
| 72 |
+
return torch.float32
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def make_max_memory(gpu_max_memory_gib: int = 11, cpu_max_memory_gib: int = 48):
|
| 76 |
+
max_memory = {}
|
| 77 |
+
if torch.cuda.is_available():
|
| 78 |
+
for i in range(torch.cuda.device_count()):
|
| 79 |
+
max_memory[i] = f'{int(gpu_max_memory_gib)}GiB'
|
| 80 |
+
max_memory['cpu'] = f'{int(cpu_max_memory_gib)}GiB'
|
| 81 |
+
return max_memory
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def attach_nonquant_gemma(
|
| 85 |
+
bot,
|
| 86 |
+
model_id: Optional[str] = None,
|
| 87 |
+
*,
|
| 88 |
+
prefer_bf16: bool = True,
|
| 89 |
+
use_fp32: bool = False,
|
| 90 |
+
device_map: Optional[str] = 'balanced_low_0',
|
| 91 |
+
device_map_candidates: Optional[Sequence[str]] = None,
|
| 92 |
+
gpu_max_memory_gib: int = 11,
|
| 93 |
+
gpu_max_memory_gib_candidates: Optional[Sequence[int]] = None,
|
| 94 |
+
cpu_max_memory_gib: int = 48,
|
| 95 |
+
offload_folder: Optional[str] = None,
|
| 96 |
+
token: Optional[str] = None,
|
| 97 |
+
trust_remote_code: bool = True,
|
| 98 |
+
verbose: bool = True,
|
| 99 |
+
) -> Dict[str, Any]:
|
| 100 |
+
model_id = model_id or getattr(bot, 'model_id', 'google/gemma-4-E2B-it')
|
| 101 |
+
token = token or os.environ.get('HF_TOKEN') or None
|
| 102 |
+
dtype = runtime_dtype(prefer_bf16=prefer_bf16, use_fp32=use_fp32)
|
| 103 |
+
|
| 104 |
+
if device_map_candidates is None:
|
| 105 |
+
if device_map:
|
| 106 |
+
device_map_candidates = [device_map, 'balanced', 'auto']
|
| 107 |
+
else:
|
| 108 |
+
device_map_candidates = ['balanced_low_0', 'balanced', 'auto']
|
| 109 |
+
|
| 110 |
+
if gpu_max_memory_gib_candidates is None:
|
| 111 |
+
gpu_max_memory_gib_candidates = [
|
| 112 |
+
int(gpu_max_memory_gib),
|
| 113 |
+
max(1, int(gpu_max_memory_gib) - 1),
|
| 114 |
+
max(1, int(gpu_max_memory_gib) - 2),
|
| 115 |
+
]
|
| 116 |
+
|
| 117 |
+
if offload_folder is None:
|
| 118 |
+
repo_dir = Path(getattr(bot, 'repo_dir', '.'))
|
| 119 |
+
offload_folder = str(repo_dir / 'model_offload_nonquant')
|
| 120 |
+
Path(offload_folder).mkdir(parents=True, exist_ok=True)
|
| 121 |
+
|
| 122 |
+
if verbose:
|
| 123 |
+
print('[NZFC nonquant] model_id:', model_id)
|
| 124 |
+
print('[NZFC nonquant] dtype:', dtype)
|
| 125 |
+
print('[NZFC nonquant] quantization_config: None')
|
| 126 |
+
print('[NZFC nonquant] device_map_candidates:', list(device_map_candidates))
|
| 127 |
+
print('[NZFC nonquant] gpu_max_memory_gib_candidates:', list(gpu_max_memory_gib_candidates))
|
| 128 |
+
print('[NZFC nonquant] offload_folder:', offload_folder)
|
| 129 |
+
|
| 130 |
+
clear_cuda()
|
| 131 |
+
|
| 132 |
+
processor = None
|
| 133 |
+
tokenizer = None
|
| 134 |
+
try:
|
| 135 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=trust_remote_code, token=token)
|
| 136 |
+
tokenizer = getattr(processor, 'tokenizer', None)
|
| 137 |
+
if verbose:
|
| 138 |
+
print('[NZFC nonquant] AutoProcessor:', type(processor).__name__)
|
| 139 |
+
except Exception as e:
|
| 140 |
+
if verbose:
|
| 141 |
+
print('[NZFC nonquant][WARN] AutoProcessor failed:', repr(e))
|
| 142 |
+
processor = None
|
| 143 |
+
|
| 144 |
+
if tokenizer is None:
|
| 145 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=trust_remote_code, token=token)
|
| 146 |
+
if verbose:
|
| 147 |
+
print('[NZFC nonquant] AutoTokenizer:', type(tokenizer).__name__)
|
| 148 |
+
|
| 149 |
+
if tokenizer is not None and tokenizer.pad_token_id is None and tokenizer.eos_token_id is not None:
|
| 150 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 151 |
+
|
| 152 |
+
model_obj = None
|
| 153 |
+
errors = []
|
| 154 |
+
chosen_device_map = None
|
| 155 |
+
chosen_gpu_gib = None
|
| 156 |
+
|
| 157 |
+
for gpu_gib in gpu_max_memory_gib_candidates:
|
| 158 |
+
max_memory = make_max_memory(gpu_max_memory_gib=int(gpu_gib), cpu_max_memory_gib=cpu_max_memory_gib)
|
| 159 |
+
for dm in device_map_candidates:
|
| 160 |
+
common_kwargs = dict(
|
| 161 |
+
device_map=dm,
|
| 162 |
+
max_memory=max_memory,
|
| 163 |
+
offload_folder=offload_folder,
|
| 164 |
+
offload_state_dict=True,
|
| 165 |
+
low_cpu_mem_usage=True,
|
| 166 |
+
trust_remote_code=trust_remote_code,
|
| 167 |
+
token=token,
|
| 168 |
+
)
|
| 169 |
+
for cls in [AutoModelForImageTextToText, AutoModelForCausalLM]:
|
| 170 |
+
try:
|
| 171 |
+
if verbose:
|
| 172 |
+
print(f'[NZFC nonquant][TRY] {cls.__name__} dtype={dtype} device_map={dm} gpu_max={gpu_gib}GiB')
|
| 173 |
+
model_obj = cls.from_pretrained(model_id, dtype=dtype, **common_kwargs)
|
| 174 |
+
chosen_device_map = dm
|
| 175 |
+
chosen_gpu_gib = int(gpu_gib)
|
| 176 |
+
break
|
| 177 |
+
except TypeError:
|
| 178 |
+
try:
|
| 179 |
+
model_obj = cls.from_pretrained(model_id, torch_dtype=dtype, **common_kwargs)
|
| 180 |
+
chosen_device_map = dm
|
| 181 |
+
chosen_gpu_gib = int(gpu_gib)
|
| 182 |
+
break
|
| 183 |
+
except Exception as e:
|
| 184 |
+
errors.append(f'{cls.__name__} torch_dtype gpu={gpu_gib} map={dm}: {repr(e)}')
|
| 185 |
+
clear_cuda()
|
| 186 |
+
except Exception as e:
|
| 187 |
+
errors.append(f'{cls.__name__} gpu={gpu_gib} map={dm}: {repr(e)}')
|
| 188 |
+
clear_cuda()
|
| 189 |
+
if model_obj is not None:
|
| 190 |
+
break
|
| 191 |
+
if model_obj is not None:
|
| 192 |
+
break
|
| 193 |
+
|
| 194 |
+
if model_obj is None:
|
| 195 |
+
raise RuntimeError(
|
| 196 |
+
'Non-quantized model loading failed. Try lower gpu_max_memory_gib or use a larger GPU.\n'
|
| 197 |
+
+ '\n'.join(errors[-10:])
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
model_obj.eval()
|
| 201 |
+
try:
|
| 202 |
+
model_obj.config.use_cache = False
|
| 203 |
+
except Exception:
|
| 204 |
+
pass
|
| 205 |
+
try:
|
| 206 |
+
model_obj.generation_config.use_cache = False
|
| 207 |
+
except Exception:
|
| 208 |
+
pass
|
| 209 |
+
|
| 210 |
+
bot.processor = processor
|
| 211 |
+
bot.tokenizer = tokenizer
|
| 212 |
+
bot.model = model_obj
|
| 213 |
+
bot.input_device = infer_input_device(model_obj)
|
| 214 |
+
bot.token_budget = bot.TokenBudgetClass(bot.tokenizer)
|
| 215 |
+
bot.governor = ReadoutGramianGovernor(bot.token_budget)
|
| 216 |
+
|
| 217 |
+
meta = {
|
| 218 |
+
'model_id': model_id,
|
| 219 |
+
'quantization': 'none',
|
| 220 |
+
'mode': 'nonquant_bf16_fp16_balanced_cpu_disk_offload',
|
| 221 |
+
'dtype': str(dtype),
|
| 222 |
+
'device_map': chosen_device_map,
|
| 223 |
+
'gpu_max_memory_gib': chosen_gpu_gib,
|
| 224 |
+
'cpu_max_memory_gib': int(cpu_max_memory_gib),
|
| 225 |
+
'model_class': type(model_obj).__name__,
|
| 226 |
+
'processor_class': type(processor).__name__ if processor is not None else None,
|
| 227 |
+
'tokenizer_class': type(tokenizer).__name__ if tokenizer is not None else None,
|
| 228 |
+
'input_device': str(bot.input_device),
|
| 229 |
+
'vram': vram_snapshot(),
|
| 230 |
+
}
|
| 231 |
+
if verbose:
|
| 232 |
+
print('[NZFC nonquant][OK]', meta)
|
| 233 |
+
return meta
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def patch_generation_use_cache_false(
|
| 237 |
+
bot,
|
| 238 |
+
*,
|
| 239 |
+
max_new_tokens_cap: int = 160,
|
| 240 |
+
oom_retry_tokens: int = 24,
|
| 241 |
+
verbose: bool = True,
|
| 242 |
+
):
|
| 243 |
+
@torch.inference_mode()
|
| 244 |
+
def generate_answer_nonquant_oomsafe(
|
| 245 |
+
self,
|
| 246 |
+
system_prompt: str,
|
| 247 |
+
user_prompt: str,
|
| 248 |
+
max_new_tokens: int = 96,
|
| 249 |
+
do_sample: bool = False,
|
| 250 |
+
temperature: float = 0.0,
|
| 251 |
+
):
|
| 252 |
+
if self.model is None:
|
| 253 |
+
return {'ran': False, 'answer': None, 'reason': 'model_not_loaded', 'input_tokens': None}
|
| 254 |
+
|
| 255 |
+
max_new_tokens_local = int(max(8, min(int(max_new_tokens), int(max_new_tokens_cap))))
|
| 256 |
+
|
| 257 |
+
with self.model_lock:
|
| 258 |
+
messages = self._build_messages(system_prompt, user_prompt)
|
| 259 |
+
encoded = self._encode_messages(messages)
|
| 260 |
+
dev = self.input_device or infer_input_device(self.model)
|
| 261 |
+
encoded = {k: (v.to(dev) if torch.is_tensor(v) else v) for k, v in encoded.items()}
|
| 262 |
+
|
| 263 |
+
input_ids = encoded.get('input_ids')
|
| 264 |
+
input_len = int(input_ids.shape[-1]) if input_ids is not None else 0
|
| 265 |
+
if input_len > 16000:
|
| 266 |
+
return {
|
| 267 |
+
'ran': False,
|
| 268 |
+
'answer': None,
|
| 269 |
+
'reason': f'context_hard_cap_exceeded:{input_len}>16000',
|
| 270 |
+
'input_tokens': input_len,
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
gen_kwargs = {'max_new_tokens': max_new_tokens_local, 'do_sample': bool(do_sample), 'use_cache': False}
|
| 274 |
+
if do_sample and temperature and temperature > 0:
|
| 275 |
+
gen_kwargs['temperature'] = float(temperature)
|
| 276 |
+
if self.tokenizer is not None and self.tokenizer.pad_token_id is not None:
|
| 277 |
+
gen_kwargs['pad_token_id'] = self.tokenizer.pad_token_id
|
| 278 |
+
if self.tokenizer is not None and self.tokenizer.eos_token_id is not None:
|
| 279 |
+
gen_kwargs['eos_token_id'] = self.tokenizer.eos_token_id
|
| 280 |
+
|
| 281 |
+
def _run(local_kwargs):
|
| 282 |
+
clear_cuda()
|
| 283 |
+
if torch.cuda.is_available():
|
| 284 |
+
torch.cuda.synchronize()
|
| 285 |
+
t0 = time.perf_counter()
|
| 286 |
+
out = self.model.generate(**encoded, **local_kwargs)
|
| 287 |
+
if torch.cuda.is_available():
|
| 288 |
+
torch.cuda.synchronize()
|
| 289 |
+
t1 = time.perf_counter()
|
| 290 |
+
out_ids = out[0] if isinstance(out, torch.Tensor) else out.sequences[0]
|
| 291 |
+
gen_ids = out_ids[input_len:]
|
| 292 |
+
raw = self._decode_ids(gen_ids).strip()
|
| 293 |
+
ans = sanitize_model_answer(raw)
|
| 294 |
+
return {
|
| 295 |
+
'ran': True,
|
| 296 |
+
'answer': ans,
|
| 297 |
+
'answer_raw': raw,
|
| 298 |
+
'input_tokens': input_len,
|
| 299 |
+
'new_tokens': int(gen_ids.numel()),
|
| 300 |
+
'latency_s': float(t1 - t0),
|
| 301 |
+
'vram': vram_snapshot(),
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
try:
|
| 305 |
+
return _run(gen_kwargs)
|
| 306 |
+
except RuntimeError as e:
|
| 307 |
+
msg = str(e)
|
| 308 |
+
if 'out of memory' not in msg.lower() and 'cuda' not in msg.lower():
|
| 309 |
+
raise
|
| 310 |
+
if verbose:
|
| 311 |
+
print('[NZFC nonquant][OOM RETRY] generation failed; retrying with shorter output.')
|
| 312 |
+
clear_cuda()
|
| 313 |
+
retry_kwargs = dict(gen_kwargs)
|
| 314 |
+
retry_kwargs['max_new_tokens'] = min(int(oom_retry_tokens), max(8, max_new_tokens_local // 3))
|
| 315 |
+
retry_kwargs['use_cache'] = False
|
| 316 |
+
try:
|
| 317 |
+
return _run(retry_kwargs)
|
| 318 |
+
except RuntimeError as e2:
|
| 319 |
+
clear_cuda()
|
| 320 |
+
return {
|
| 321 |
+
'ran': False,
|
| 322 |
+
'answer': 'MODEL_GENERATION_FAILED_CUDA_OOM_AFTER_RETRY',
|
| 323 |
+
'answer_raw': '',
|
| 324 |
+
'reason': 'cuda_oom_after_retry: ' + str(e2)[:700],
|
| 325 |
+
'input_tokens': input_len,
|
| 326 |
+
'new_tokens': 0,
|
| 327 |
+
'latency_s': None,
|
| 328 |
+
'vram': vram_snapshot(),
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
bot.generate_answer = types.MethodType(generate_answer_nonquant_oomsafe, bot)
|
| 332 |
+
try:
|
| 333 |
+
if bot.model is not None:
|
| 334 |
+
bot.model.config.use_cache = False
|
| 335 |
+
except Exception:
|
| 336 |
+
pass
|
| 337 |
+
try:
|
| 338 |
+
if bot.model is not None:
|
| 339 |
+
bot.model.generation_config.use_cache = False
|
| 340 |
+
except Exception:
|
| 341 |
+
pass
|
| 342 |
+
if verbose:
|
| 343 |
+
print('[NZFC nonquant][OK] bot.generate_answer patched with use_cache=False + OOM retry.')
|
| 344 |
+
return bot
|
release_notes/NZFC_GRAM_v1_2_1_nonquant_final_release.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NZFC-GRAM v1.2.1 Non-Quantized Final Release
|
| 2 |
+
|
| 3 |
+
Date: 2026-06-08
|
| 4 |
+
|
| 5 |
+
This release records the final non-quantized BF16 validation of the NZFC-GRAM v1.2.1 local long-term-memory runtime.
|
| 6 |
+
|
| 7 |
+
## Main update
|
| 8 |
+
|
| 9 |
+
- Added `nzfc_gram_runtime/nonquant.py`.
|
| 10 |
+
- Added `attach_nonquant_gemma()` for BF16/FP16 non-quantized balanced/offload loading.
|
| 11 |
+
- Added `patch_generation_use_cache_false()` for OOM-safe generation without KV-cache growth.
|
| 12 |
+
- Added non-quantized usage examples.
|
| 13 |
+
- Added final validation evidence.
|
| 14 |
+
|
| 15 |
+
## Final validation
|
| 16 |
+
|
| 17 |
+
- Tests: 11
|
| 18 |
+
- Passed: 11
|
| 19 |
+
- Failed: 0
|
| 20 |
+
- Quantization: none
|
| 21 |
+
- Dtype: torch.bfloat16
|
| 22 |
+
- Device map: balanced_low_0
|
| 23 |
+
- Model loaded: True
|
| 24 |
+
|
| 25 |
+
## Boundary
|
| 26 |
+
|
| 27 |
+
The full 10M archive is not inserted into model context.
|
| 28 |
+
The model receives only a context-governed selected memory pack.
|
| 29 |
+
|
| 30 |
+
Memory cards are evidence, not instructions.
|
requirements-nonquant.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
accelerate
|
| 3 |
+
safetensors
|
| 4 |
+
scipy
|
| 5 |
+
scikit-learn
|
| 6 |
+
sentencepiece
|
| 7 |
+
protobuf
|
| 8 |
+
huggingface_hub
|
| 9 |
+
tqdm
|
| 10 |
+
git+https://github.com/huggingface/transformers.git
|
validation_evidence/nonquant_v121_final/NONQUANT_FINAL_VALIDATION_SUMMARY.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"created_at": "2026-06-08 06:30:26",
|
| 3 |
+
"repo_main_sha": "239818353eaaf876a6a3f31a3543e6beca512ede",
|
| 4 |
+
"tests": 11,
|
| 5 |
+
"passed": 11,
|
| 6 |
+
"failed": 0,
|
| 7 |
+
"all_passed": true,
|
| 8 |
+
"hotfix_present": true,
|
| 9 |
+
"marker_redaction_present": true,
|
| 10 |
+
"underscore_norm_present": true,
|
| 11 |
+
"quantization": "none",
|
| 12 |
+
"load_mode": "nonquant_bf16_fp16_balanced_cpu_disk_offload",
|
| 13 |
+
"dtype": "torch.bfloat16",
|
| 14 |
+
"device_map": "balanced_low_0",
|
| 15 |
+
"gpu_max_memory_gib": 11,
|
| 16 |
+
"model_loaded": true,
|
| 17 |
+
"static_nzfc_archive_loaded": true,
|
| 18 |
+
"local_sqlite_memory_persistence_tested": true,
|
| 19 |
+
"generation_patch": "use_cache_false_oom_retry",
|
| 20 |
+
"safety_boundary": "external_nzfc_archive_and_local_long_term_memory_not_internal_10m_context",
|
| 21 |
+
"vram_final": {
|
| 22 |
+
"gpu1_alloc_gb": 10.217637376,
|
| 23 |
+
"gpu1_reserved_gb": 11.448352768,
|
| 24 |
+
"gpu1_peak_gb": 11.845826048,
|
| 25 |
+
"max_alloc_gb": 10.217637376,
|
| 26 |
+
"max_peak_gb": 11.845826048
|
| 27 |
+
},
|
| 28 |
+
"key_test_metrics": {
|
| 29 |
+
"T8_slope_tokens_per_turn": 105.964,
|
| 30 |
+
"T8_slope_limit": 220.0,
|
| 31 |
+
"T8_growth_ratio": 1.392,
|
| 32 |
+
"T8_growth_ratio_limit": 3.2,
|
| 33 |
+
"T8_hard_cap_context_tokens": 16000,
|
| 34 |
+
"T10_gram_trace_budget": 1.861558246118043,
|
| 35 |
+
"T10_gram_soft_cap": 4.35,
|
| 36 |
+
"T10_gram_soft_tau_pass": true
|
| 37 |
+
}
|
| 38 |
+
}
|