hknt 1.0.0__tar.gz
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.
- hknt-1.0.0/CHANGELOG.md +173 -0
- hknt-1.0.0/CITATION.cff +19 -0
- hknt-1.0.0/CONTRIBUTING.md +105 -0
- hknt-1.0.0/LICENSE +190 -0
- hknt-1.0.0/MANIFEST.in +10 -0
- hknt-1.0.0/PKG-INFO +331 -0
- hknt-1.0.0/README.md +303 -0
- hknt-1.0.0/SECURITY.md +34 -0
- hknt-1.0.0/include/hk.h +507 -0
- hknt-1.0.0/include/hk.hpp +554 -0
- hknt-1.0.0/pyproject.toml +52 -0
- hknt-1.0.0/python/hk/__init__.py +217 -0
- hknt-1.0.0/python/hk/adaptive/__init__.py +102 -0
- hknt-1.0.0/python/hk/adaptive/appendix.py +271 -0
- hknt-1.0.0/python/hk/adaptive/code_eval.py +187 -0
- hknt-1.0.0/python/hk/adaptive/expansion_evaluator.py +145 -0
- hknt-1.0.0/python/hk/adaptive/growth.py +576 -0
- hknt-1.0.0/python/hk/adaptive/self_conversation.py +188 -0
- hknt-1.0.0/python/hk/adaptive/self_play.py +165 -0
- hknt-1.0.0/python/hk/adaptive/self_training.py +281 -0
- hknt-1.0.0/python/hk/adaptive/topology.py +148 -0
- hknt-1.0.0/python/hk/benchmark.py +120 -0
- hknt-1.0.0/python/hk/cli.py +199 -0
- hknt-1.0.0/python/hk/composite.py +965 -0
- hknt-1.0.0/python/hk/config.py +186 -0
- hknt-1.0.0/python/hk/constants.py +315 -0
- hknt-1.0.0/python/hk/flax.py +103 -0
- hknt-1.0.0/python/hk/format.py +266 -0
- hknt-1.0.0/python/hk/gguf_parser.py +265 -0
- hknt-1.0.0/python/hk/gui.py +33 -0
- hknt-1.0.0/python/hk/hf_mapper.py +940 -0
- hknt-1.0.0/python/hk/hk.dll +0 -0
- hknt-1.0.0/python/hk/jax.py +69 -0
- hknt-1.0.0/python/hk/libhk-linux-aarch64.so +0 -0
- hknt-1.0.0/python/hk/libhk-linux-x86_64.so +0 -0
- hknt-1.0.0/python/hk/libhk-macos-arm64.dylib +0 -0
- hknt-1.0.0/python/hk/libhk-macos-x86_64.dylib +0 -0
- hknt-1.0.0/python/hk/libhk.dylib +0 -0
- hknt-1.0.0/python/hk/libhk.so +0 -0
- hknt-1.0.0/python/hk/modeling.py +703 -0
- hknt-1.0.0/python/hk/models.py +443 -0
- hknt-1.0.0/python/hk/native.py +2579 -0
- hknt-1.0.0/python/hk/numpy.py +158 -0
- hknt-1.0.0/python/hk/pipeline.py +182 -0
- hknt-1.0.0/python/hk/pruning.py +343 -0
- hknt-1.0.0/python/hk/py.typed +1 -0
- hknt-1.0.0/python/hk/quantization.py +683 -0
- hknt-1.0.0/python/hk/raw.py +411 -0
- hknt-1.0.0/python/hk/remote.py +297 -0
- hknt-1.0.0/python/hk/tokenizer.py +816 -0
- hknt-1.0.0/python/hk/torch.py +1180 -0
- hknt-1.0.0/python/hk/trainer.py +205 -0
- hknt-1.0.0/python/hknt.egg-info/PKG-INFO +331 -0
- hknt-1.0.0/python/hknt.egg-info/SOURCES.txt +69 -0
- hknt-1.0.0/python/hknt.egg-info/dependency_links.txt +1 -0
- hknt-1.0.0/python/hknt.egg-info/entry_points.txt +3 -0
- hknt-1.0.0/python/hknt.egg-info/requires.txt +2 -0
- hknt-1.0.0/python/hknt.egg-info/top_level.txt +1 -0
- hknt-1.0.0/setup.cfg +4 -0
- hknt-1.0.0/tests/test_adaptive.py +720 -0
- hknt-1.0.0/tests/test_expanded_features.py +342 -0
- hknt-1.0.0/tests/test_expansion_rigorous.py +293 -0
- hknt-1.0.0/tests/test_gguf_hf_parity.py +468 -0
- hknt-1.0.0/tests/test_hf_style.py +389 -0
- hknt-1.0.0/tests/test_native_engine.py +172 -0
- hknt-1.0.0/tests/test_new_features.py +392 -0
- hknt-1.0.0/tests/test_parity_pillars.py +204 -0
- hknt-1.0.0/tests/test_raw_weights.py +208 -0
- hknt-1.0.0/tests/test_self_training_pipeline.py +267 -0
- hknt-1.0.0/tests/test_torch_integration.py +235 -0
- hknt-1.0.0/tests/test_universal_pipeline.py +199 -0
hknt-1.0.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the **HK Neural Tensor Framework** will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [1.0.0] - 2026-09-14 - The Unified Release
|
|
11
|
+
|
|
12
|
+
This release establishes the HK Neural Tensor Framework as a complete, unified replacement for legacy model formats (SafeTensors, GGUF, and PyTorch checkpoints). It packages raw unquantized weight storage with zero compute headroom, universal multi-device super-coalescing, dual-mode quantization, hardware structured sparsity, live architecture growth, and in-container evolution into a single seamless system.
|
|
13
|
+
|
|
14
|
+
### Core Container & Hardware Acceleration
|
|
15
|
+
- **Universal Multi-Device Super-Coalescing (`HeaderFlags.UNIVERSAL_PAGE_ALIGNED = 0x100`)**:
|
|
16
|
+
- Super-coalesced 4096-byte (4 KB) page alignment satisfying AMD ROCm DirectGMA, Intel NPU/OpenVINO Direct DMA, Apple Silicon Metal (16 KB), and ARM NEON/SVE.
|
|
17
|
+
- **NVIDIA Tensor Core Coalescing Invariance**: Because $4096 = 32 \times 128$, a single shared `.hk` file guarantees 100% strict 128-byte warp-coalesced memory transactions with zero performance loss and zero storage duplication.
|
|
18
|
+
- **Raw Weight Storage (`HeaderFlags.RAW_WEIGHT_STORAGE = 0x80`)**:
|
|
19
|
+
- Full-precision native storage for BF16, FP16, FP32, INT8, INT16, INT32, INT64, and BOOL.
|
|
20
|
+
- Zero compute headroom: weights are memory-mapped directly with zero decoding, transcoding, or unpacking latency.
|
|
21
|
+
- **4-Row Unrolled SIMD GEMV Compute Engine**:
|
|
22
|
+
- `gemvBF16_4rows` evaluates 4 output rows simultaneously in registers with 8 interleaved 256-bit SIMD accumulators, eliminating cache thrashing and achieving **34.38 GFLOPS** single-core throughput (1.72x faster than multi-threaded PyTorch CPU).
|
|
23
|
+
- **Single-Call Batch TOC Deserialization**:
|
|
24
|
+
- `hk_get_all_tensor_infos` fetches all tensor metadata in a single C call, avoiding hundreds of individual ctypes FFI roundtrips.
|
|
25
|
+
- **Zero-Copy `HKDict` Container**:
|
|
26
|
+
- `load_raw` returns an `HKDict` binding reader lifetime directly to output tensors, loading 1.75 GB of model weights into PyTorch in 15 ms.
|
|
27
|
+
- **Production 1B Parameter Model Benchmark (`Qwen3.5-0.8B`)**:
|
|
28
|
+
- Verified on 873,438,784 bfloat16 parameters (488 tensors, 1.75 GB): 1.72x faster GEMV, 346x faster autoregressive layer access (80 ns vs 28.84 us), and 222 MB/s streaming conversion.
|
|
29
|
+
- **Split Mode Sharding (`HeaderFlags.IS_SHARDED = 0x40`)**:
|
|
30
|
+
- Splits multi-hundred-gigabyte raw checkpoints cleanly across storage boundaries with standardized manifest indexes (`save_sharded_raw` / `load_sharded_raw`) for regeneratable weights, adapters, and modular layer swapping.
|
|
31
|
+
- **HK Binary Container Specification (HKNT)**:
|
|
32
|
+
- Fixed 128-byte header, extensible typed key-value metadata section, and 128-byte aligned Tensor Table of Contents.
|
|
33
|
+
- Strict 128-byte cache-line and Tensor Core memory alignment matching GPU memory transactions.
|
|
34
|
+
- Universal flexible alignment mode (`0x20` flag): seamlessly supports 1-byte compact alignment for mobile and embedded systems, 16-byte for ARM NEON, and 128-byte for datacenter GPUs.
|
|
35
|
+
- **Zero-Copy Memory Mapping**:
|
|
36
|
+
- Direct zero-copy page mapping on POSIX (`mmap`) and native Windows (`CreateFileMappingA` + `MapViewOfFile`).
|
|
37
|
+
- True copy-on-write page safety ensuring all loaded tensors are directly writable without duplicating memory.
|
|
38
|
+
- **Dual-Mode Quantization**:
|
|
39
|
+
- Dual-mode 4-bit NormalFloat4 (NF4) with residual delta stream for bit-exact recovery ($>0.99999$ cosine similarity).
|
|
40
|
+
- Dual-mode 8-bit integer (DQ8) quantization.
|
|
41
|
+
- BitNet b1.58 ternary (DQT $\{-1, 0, +1\}$) quantization.
|
|
42
|
+
- **NVIDIA Ampere 2:4 Structured Hardware Sparsity**:
|
|
43
|
+
- True 2-bit nibble metadata packing for 50% non-zero weights (1.88× physical compression).
|
|
44
|
+
- Native Zig SIMD unpacking kernel (`hk_unpack_2_4`) delivering $>3\text{ GB/s}$ unpacking throughput.
|
|
45
|
+
- **Tensor Core 16x16 Tile Transformation**:
|
|
46
|
+
- K-contiguous tile packing and untiling for NVIDIA WMMA tensor cores.
|
|
47
|
+
- **Sparse Matrix Representations**:
|
|
48
|
+
- Bitmask sparse packing and Block Sparse Row (BSR) packing for Mixture-of-Experts (MoE).
|
|
49
|
+
|
|
50
|
+
### Live Architecture Evolution & Adaptation
|
|
51
|
+
- **Dynamic Capacity Expansion (Net2Net)**:
|
|
52
|
+
- Function-preserving width expansion (`net2wider_linear` and `net2wider_swiglu`) for standard linear layers and modern SwiGLU MLP architectures ($||f_{wider}(x) - f(x)||_{\infty} < 10^{-6}$).
|
|
53
|
+
- Identity layer stacking (`net2deeper_linear`) and zero-initialized residual adapters (`ModularResidualBlock`) guaranteeing zero degradation upon insertion.
|
|
54
|
+
- `GrowthGovernor` hardware resource manager enforcing strict VRAM and system memory bounds.
|
|
55
|
+
- **Version-Chained Appendix Region**:
|
|
56
|
+
- 80-byte binary appendix record specification supporting all 6 evolutionary entry types: `LORA_ADAPTER (0x01)`, `DELTA_PATCH (0x02)`, `NEW_LAYER (0x03)`, `CODE_EVAL (0x04)`, `KV_CACHE_SINK (0x05)`, and `TOPOLOGY_HEAD (0x06)`.
|
|
57
|
+
- Cryptographic SHA-256 DAG hash-chaining across generations (`parent_hash`).
|
|
58
|
+
- Instant rollback to any prior generation (`hk_appendix_rollback`) via Python API and native CLI (`hk rollback <model.hk> [gen]`).
|
|
59
|
+
- **Self-Play Evolution Engine (SPIN-Style)**:
|
|
60
|
+
- Targeted `LoRAAdapter` fine-tuning on salient projections.
|
|
61
|
+
- Automated context poisoning mitigation with regression detection and immediate parameter rollback.
|
|
62
|
+
- **Persistent Code Evaluation Sandbox**:
|
|
63
|
+
- Subprocess isolation with strict execution timeouts, syntax tree validation (`ast.parse`), and unit test scoring persisted into `.hk` appendix entries.
|
|
64
|
+
- **Single-File Runnable Model Topology**:
|
|
65
|
+
- Embedded model topologies, hyper-parameters, and inference runner scripts (`load_standalone_hk`).
|
|
66
|
+
|
|
67
|
+
### Developer Experience & Multilingual Ecosystem
|
|
68
|
+
- **Clean & Consolidated Python Architecture (`hk`)**:
|
|
69
|
+
- Completely removed legacy `python/hk_format/` package (~3,850 lines of duplicate pure-Python code).
|
|
70
|
+
- Consolidated all functionality into a unified, high-performance `python/hk/` package delegating directly to native `hk.dll` via C ABI.
|
|
71
|
+
- Native container serialization via `NativeHKWriter` and zero-copy loading via `NativeHKReader`.
|
|
72
|
+
- Added dedicated submodules: `hk.torch`, `hk.quantization`, `hk.pruning`, `hk.benchmark`, `hk.format`, and `hk.adaptive`.
|
|
73
|
+
- **Hugging Face-Style Python API**:
|
|
74
|
+
- `AutoModel`, `AutoConfig`, and `AutoTokenizer` mirroring Hugging Face developer workflows.
|
|
75
|
+
- `HKForCausalLM`, `HKForSequenceClassification`, `HKForHandwritingRecognition`.
|
|
76
|
+
- Task pipelines: `pipeline("text-generation")`, `pipeline("sequence-classification")`, `pipeline("handwriting-recognition")`.
|
|
77
|
+
- `HKTrainer` supporting automatic plateau-triggered Net2WiderNet growth and QLoRA adapter training.
|
|
78
|
+
- **Autonomous Self-Training & Conversational Thinking Engine**:
|
|
79
|
+
- `ExpansionEvaluator`: Autonomous diagnostic capacity evaluation for identifying domain and vocabulary bottlenecks.
|
|
80
|
+
- `SelfConversationalEngine`: Proposer-Thinker inner monologue (`<think> ... </think>`) with multi-step reasoning and syntax synthesis.
|
|
81
|
+
- `CodeSandbox`: AST-isolated execution environment with automatic unit test grading and metric recording.
|
|
82
|
+
- Plasticity Shield: In-place gradient masking preventing catastrophic forgetting of base representations during new language/task acquisition.
|
|
83
|
+
- **Native Zig Engine & Standalone CLI (`hk.exe`)**:
|
|
84
|
+
- Added native C ABI container writer functions (`hk_writer_create`, `hk_writer_add_tensor`, etc.).
|
|
85
|
+
- Standalone binary supporting `inspect`, `verify`, `eval`, `expand`, `benchmark`, `retile`, `prune`, `appendix`, and `rollback`.
|
|
86
|
+
- **Universal Multi-Language Bindings**:
|
|
87
|
+
- **Rust**: Safe idiomatic crate (`bindings/rust/Cargo.toml`).
|
|
88
|
+
- **TypeScript / Node.js**: NPM package (`bindings/js/package.json`).
|
|
89
|
+
- **C# / .NET**: Package for Unity and .NET applications (`bindings/csharp/Hk.csproj`).
|
|
90
|
+
- **Go**: Module with cgo integration (`bindings/go/go.mod`).
|
|
91
|
+
- **Java / Android**: JNI package with direct NIO `ByteBuffer` mapping (`bindings/java/pom.xml`).
|
|
92
|
+
- **C / C++**: Header definitions (`include/hk.h`) and C++20 RAII wrappers (`include/hk.hpp`).
|
|
93
|
+
|
|
94
|
+
### Advanced Quantization Zoo & Importance Calibration
|
|
95
|
+
- **K-Quants Super-Block Engine (`0x40` - `0x45`)**:
|
|
96
|
+
- Implemented 256-element super-block structures: `BlockQ4_K` (144 bytes, 4.5 bpw), `BlockQ8_K` (292 bytes, 9.125 bpw), `BlockQ6_K` (210 bytes, 6.56 bpw), `BlockQ2_K`, `BlockQ3_K`, and `BlockQ5_K`.
|
|
97
|
+
- Native Zig SIMD dequantization routines with AVX2/AVX-512 vectorization and C ABI exports.
|
|
98
|
+
- **Non-Linear & Importance Quants (`0x50` - `0x57`)**:
|
|
99
|
+
- `IQ4_NL` non-linear codebook quantization using Gaussian optimal distribution tables.
|
|
100
|
+
- Low-bit I-quant types: `IQ1_S`, `IQ1_M`, `IQ2_XXS`, `IQ2_XS`, `IQ2_S`, `IQ3_XXS`, `IQ4_XS`.
|
|
101
|
+
- **Hardware Microscaling & Ternary Formats (`0x60` - `0x63`)**:
|
|
102
|
+
- OCP Microscaling FP4 (`mxfp4`): E2M1 floating point with 32-element blocks and 8-bit scale factor.
|
|
103
|
+
- NVIDIA Blackwell Microscaling (`nvfp4`): E2M1 with FP8 micro-scales.
|
|
104
|
+
- Ternary quants: `tq1_0`, `tq2_0`, and BitNet b1.58 `dqt`.
|
|
105
|
+
- **Activation-Aware Importance Matrix Calibration (`imatrix`)**:
|
|
106
|
+
- `ImportanceMatrixCalibrator`: Fisher information second-moment accumulator ($I = \frac{1}{N}\sum x x^T$) for activation-guided quantization error minimization.
|
|
107
|
+
- Predefined mixed-precision per-tensor recipes: `Q4_K_M`, `Q5_K_M`, `Q4_K_S`, `Q5_K_S`, `Q3_K_M`, `Q2_K`, `Q6_K`, `Q8_K`, `IQ4_NL`.
|
|
108
|
+
- `resolve_quant_type_for_tensor`: Automatic per-tensor precision assignment using architectural regex matching.
|
|
109
|
+
|
|
110
|
+
### Massive Architectural Breadth (137+ Models)
|
|
111
|
+
- **Comprehensive Model Registry (`ARCHITECTURES_REGISTRY`)**:
|
|
112
|
+
- 137+ foundation model architectures supported across LLMs, SSMs, VLMs, Audio, and Diffusion.
|
|
113
|
+
- Cutting-Edge LLMs: DeepSeek V2/V3/R1 (MLA attention and Multi-Token Prediction), LLaMA 4, Qwen 2.5/3/MoE, Gemma 1/2, Grok, Falcon, Phi-3/Phi-MoE, DBRX, Command-R+, OLMoE, MiniCPM-3, Starcoder2, Jais, Exaone, ChatGLM.
|
|
114
|
+
- State-Space & Recurrent Models: Mamba, Mamba-2, Jamba, RWKV-5/6.
|
|
115
|
+
- Vision-Language Models: CLIP, SigLIP, LLaVA, MobileVLM, Qwen2-VL, Pixtral, Gemma-Vision, SAM / SAM-2.
|
|
116
|
+
- Audio & Diffusion: Whisper audio encoders/decoders, Stable Diffusion, and FLUX.1 rectified flow transformer backbones.
|
|
117
|
+
- Modern Encoders: ModernBERT, Nomic-BERT, Jina-BERT-v2/v3, EuroBERT.
|
|
118
|
+
- **Bi-Directional Regex Tensor Mapping**:
|
|
119
|
+
- 8 bidirectional regex mapping tables translating state dicts between Hugging Face and HK naming conventions without data copying.
|
|
120
|
+
|
|
121
|
+
### Deep Tokenizer Ingestion & Zero-Dependency Decoders
|
|
122
|
+
- **Protocol-Buffer-Free Binary SentencePiece (`.model`) Parser**:
|
|
123
|
+
- Embedded pure-Python wire-format varint decoder (`parse_sentencepiece_model`) parsing SentencePiece binary models into tokens, float32 scores, and token types with zero external C++ or wheel dependencies.
|
|
124
|
+
- **Mistral Tekkenizer Ingestion**:
|
|
125
|
+
- `parse_tekken_json` parser for Mistral NeMo and Large 2 tokenizers.
|
|
126
|
+
- **Rich Tokenizer Metadata**:
|
|
127
|
+
- 6 explicit token types (`TokenType`: `NORMAL`, `UNKNOWN`, `CONTROL`, `USER_DEFINED`, `UNUSED`, `BYTE`).
|
|
128
|
+
- Pre-tokenizer regex split patterns (`PreTokenizerType`: `default`, `llama3`, `qwen2`, `deepseek_v3`, `phi3`, `mistral`).
|
|
129
|
+
- `AutoTokenizer.from_pretrained` automatically detects and ingests embedded container tokenizer metadata.
|
|
130
|
+
|
|
131
|
+
### Standardized Hyperparameter & Sampling Taxonomy
|
|
132
|
+
- **200+ Standardized Taxonomy Keys (`HKTaxonomyKeys` / `StandardKeys`)**:
|
|
133
|
+
- Unified namespaces across `general.*`, `attention.*` (MLA, SWA, ALiBi), `rope.*` (YaRN, dynamic), `moe.*` (routed & shared experts), `ssm.*` (state size, conv kernel, inner size), `tokenizer.*`, `sampling.*` (top_p, top_k, min_p, temperature, repetition penalty, mirostat), and `quant.*`.
|
|
134
|
+
|
|
135
|
+
### Standalone CLI & Graphical Model Studio
|
|
136
|
+
- **Auxiliary Developer Tools**:
|
|
137
|
+
- `hk dump <model.hk>`: 128-byte hex dumper, bitflag breakdown, section offsets, and automated alignment audit.
|
|
138
|
+
- `hk hash <model.hk>`: Whole-file streaming SHA-256 and per-tensor cryptographic digest verification.
|
|
139
|
+
- `hk convert-endian <in> <out>`: Zero-loss Little-Endian <-> Big-Endian conversion preserving 128-byte hardware alignment.
|
|
140
|
+
- **Graphical Model Studio (`hk gui` / `hk-gui`)**:
|
|
141
|
+
- Lightweight, responsive desktop GUI editor with Hugging Face / GGUF inspired tabs:
|
|
142
|
+
- Container Overview (header audit, bitflags, memory stats, compression ratio).
|
|
143
|
+
- Metadata & Hyperparameter Tree (namespace-grouped, in-place zero-copy byte patching, JSON import/export).
|
|
144
|
+
- Tensor Table & Quantization Inspector (shapes, storage types, 128-byte alignment verification).
|
|
145
|
+
- Lineage & Appendix History (generations, test pass rates, one-click rollback).
|
|
146
|
+
|
|
147
|
+
### Multilingual SDKs Sync
|
|
148
|
+
- Updated all 7 multilingual bindings to support all new StorageType definitions and quantization APIs:
|
|
149
|
+
- C / C++ (`include/hk.h`, `include/hk.hpp`)
|
|
150
|
+
- Rust (`bindings/rust/src/lib.rs`)
|
|
151
|
+
- C# / .NET (`bindings/csharp/HkModel.cs`)
|
|
152
|
+
- Go (`bindings/go/hk/hk.go`)
|
|
153
|
+
- Java / Android (`bindings/java/com/hk/HkModel.java`)
|
|
154
|
+
- TypeScript / JS (`bindings/js/hk.ts`)
|
|
155
|
+
- Python (`python/hk/`)
|
|
156
|
+
|
|
157
|
+
### Verification & Test Coverage
|
|
158
|
+
- **100% Passing Test Suites (90 / 90 Tests Passing)**:
|
|
159
|
+
- 25 native Zig unit tests (`zig build test`).
|
|
160
|
+
- 5 comprehensive parity pillar tests (`tests/test_parity_pillars.py`).
|
|
161
|
+
- 6 PyTorch & SafeTensors integration tests (`tests/test_torch_integration.py`).
|
|
162
|
+
- 6 rigorous architecture expansion tests (`tests/test_expansion_rigorous.py`).
|
|
163
|
+
- 4 autonomous self-training pipeline tests (`tests/test_self_training_pipeline.py`).
|
|
164
|
+
- 16 exhaustive adaptive neural framework tests (`tests/test_adaptive.py`).
|
|
165
|
+
- 13 Hugging Face-style API and pipeline tests (`tests/test_hf_style.py`).
|
|
166
|
+
- 7 Sharding, In-Place Patching, and AutoTokenizer tests (`tests/test_new_features.py`).
|
|
167
|
+
- 5 Universal Heterogeneous Multi-Stage Pipeline tests (`tests/test_universal_pipeline.py`).
|
|
168
|
+
- 6 Tokenizer Metadata, Sharding Manifests, JAX/Flax/NumPy, and Conversion Tables (`tests/test_expanded_features.py`).
|
|
169
|
+
- **Validated End-to-End Live Demonstrations**:
|
|
170
|
+
- `run_self_training_demo.py`: Autonomous acquisition of MiniZig systems programming via conversational thinking.
|
|
171
|
+
- `run_new_language_expansion_demo.py`: Autonomous new language acquisition with zero catastrophic forgetting.
|
|
172
|
+
- `run_llm_demo.py`: 8-stage comprehensive LLM evaluation with SmollM-135M.
|
|
173
|
+
- `run_hwr_pruning_demo.py`: Complete pruning and compression suite.
|
hknt-1.0.0/CITATION.cff
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use the HK Neural Tensor Framework in your research or production systems, please cite it as below."
|
|
3
|
+
authors:
|
|
4
|
+
- name: "HK AI Research Team"
|
|
5
|
+
title: "HK: Next-Generation AI Framework featuring Dual-Mode Quantization, Native SIMD Zig Engine, and Adaptive Architecture Growth"
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
date-released: 2026-09-13
|
|
8
|
+
url: "https://github.com/harshitkhandelwal208/hk"
|
|
9
|
+
repository-code: "https://github.com/harshitkhandelwal208/hk"
|
|
10
|
+
license: "Apache-2.0"
|
|
11
|
+
keywords:
|
|
12
|
+
- deep-learning
|
|
13
|
+
- quantization
|
|
14
|
+
- tensor-container
|
|
15
|
+
- simd
|
|
16
|
+
- zig
|
|
17
|
+
- gguf
|
|
18
|
+
- safetensors
|
|
19
|
+
- llm-inference
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Contributing to HK Neural Tensor Framework
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to HK! We welcome contributions across all areas: native Zig kernels, high-performance quantizers, quantization zoo expansions, multilingual SDKs, Python framework bridges, documentation, and benchmarks.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Code of Conduct
|
|
8
|
+
|
|
9
|
+
We are committed to providing a welcoming, inclusive, and harassment-free environment for everyone. Please be respectful, constructive, and collaborative in all discussions and pull requests.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 2. Architecture Overview
|
|
14
|
+
|
|
15
|
+
HK is structured as a layered, multi-language system:
|
|
16
|
+
- **`src/`**: High-performance core engine written in Zig 0.16. Includes:
|
|
17
|
+
- `format.zig`: Binary container layout, headers, TOC, metadata, and chunk formats.
|
|
18
|
+
- `quantization.zig`: Quantization algorithms (`Q4_0`, `Q8_0`, `Q4_K`, `Q5_K`, `Q6_K`, `Q2_K`, `IQ` codebooks, etc.) with SIMD vectorization.
|
|
19
|
+
- `tensor_ops.zig`: Packed-weight SIMD GEMV kernels (`gemvQ8_0`, `gemvQ4_0`, `gemvQ4_K`), RoPE coordinates, and LayerNorm offsets.
|
|
20
|
+
- `gguf.zig`: Native binary GGUF reader, writer, and zero-copy bitstream transcoders.
|
|
21
|
+
- `c_api.zig`: ABI-stable C interface exported as a shared library (`hk.dll`, `libhk.so`, `libhk.dylib`).
|
|
22
|
+
- **`include/`**: C and C++ header files (`hk.h`, `hk.hpp`).
|
|
23
|
+
- **`python/hk/`**: Python SDK with PyTorch zero-copy tensors, safe open, packed execution (`HKQuantizedLinear`), and tokenizer integration.
|
|
24
|
+
- **`bindings/`**: Official foreign function interfaces for Rust, C#, Go, Java, and TypeScript.
|
|
25
|
+
- **`tests/`**: Comprehensive pytest and native unit test suites.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 3. Development Environment Setup
|
|
30
|
+
|
|
31
|
+
### Prerequisites
|
|
32
|
+
- **Zig**: `0.16.x` or latest master build. Verify with `zig version`.
|
|
33
|
+
- **Python**: Python `3.10`+ (Python 3.12 recommended).
|
|
34
|
+
- **C/C++ Compiler**: Clang, GCC, or MSVC (optional, Zig acts as C compiler).
|
|
35
|
+
- **Rust** (optional, for Rust SDK): `rustc` & `cargo`.
|
|
36
|
+
- **.NET SDK** (optional, for C# SDK): .NET 8.0+.
|
|
37
|
+
- **JDK** (optional, for Java SDK): Java 17+.
|
|
38
|
+
|
|
39
|
+
### Setup Instructions
|
|
40
|
+
|
|
41
|
+
1. **Clone the repository**:
|
|
42
|
+
```bash
|
|
43
|
+
git clone https://github.com/harshitkhandelwal208/hk.git
|
|
44
|
+
cd hk
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
2. **Build the native Zig engine and run native tests**:
|
|
48
|
+
```bash
|
|
49
|
+
zig build
|
|
50
|
+
zig build test --summary all
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. **Install the Python package in editable mode**:
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e ".[dev]"
|
|
56
|
+
# or with core dependencies:
|
|
57
|
+
pip install torch numpy safetensors transformers gguf pytest
|
|
58
|
+
pip install -e .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
4. **Verify the Python CLI**:
|
|
62
|
+
```bash
|
|
63
|
+
python -m hk.cli --help
|
|
64
|
+
hk --help
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
5. **Run the Python test suite**:
|
|
68
|
+
```bash
|
|
69
|
+
pytest tests/
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 4. Testing Guidelines
|
|
75
|
+
|
|
76
|
+
Any PR touching native code or quantization kernels **must** satisfy:
|
|
77
|
+
- **Numerical Parity**: Quantizers and dequantizers must match reference implementations within acceptable epsilon (`max_discrepancy == 0.0` for bit-identical dequantization, or $\le 10^{-4}$ for floating point math).
|
|
78
|
+
- **Zero Failures, Zero Warnings**: All tests in `tests/` must pass with 0 pytest warnings and 0 errors.
|
|
79
|
+
- **Cross-Platform Portability**: File I/O and SIMD intrinsics must compile cleanly across Windows (`x86_64`), Linux (`x86_64`, `aarch64`), and macOS (`aarch64`).
|
|
80
|
+
```bash
|
|
81
|
+
zig build -Dtarget=x86_64-linux
|
|
82
|
+
zig build -Dtarget=aarch64-linux
|
|
83
|
+
zig build -Dtarget=aarch64-macos
|
|
84
|
+
zig build -Dtarget=x86_64-windows
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 5. Submitting a Pull Request
|
|
90
|
+
|
|
91
|
+
1. **Fork the repository** and create a feature branch:
|
|
92
|
+
```bash
|
|
93
|
+
git checkout -b feat/my-quant-kernel
|
|
94
|
+
```
|
|
95
|
+
2. **Commit your changes**:
|
|
96
|
+
- Write clear, concise commit messages.
|
|
97
|
+
- Reference any relevant issues (e.g. `Fixes #123`).
|
|
98
|
+
3. **Run all tests locally before opening the PR**:
|
|
99
|
+
```bash
|
|
100
|
+
zig build test
|
|
101
|
+
pytest tests/
|
|
102
|
+
```
|
|
103
|
+
4. **Open a Pull Request** against `main`:
|
|
104
|
+
- Fill out the PR template completely.
|
|
105
|
+
- CI will automatically run multi-platform tests and multilingual SDK verification.
|
hknt-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or exemplary damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 HK Framework Authors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
hknt-1.0.0/MANIFEST.in
ADDED