|
Download README.md from chrisuser/neuro-compiler: direct link, hf CLI and curl.
- Browser
- Download file 12.4 kB
-
https://huggingface.co/chrisuser/neuro-compiler/resolve/main/README.md
- Command line
-
hf download hf://chrisuser/neuro-compiler/README.md
-
curl -L -o README.md https://huggingface.co/chrisuser/neuro-compiler/resolve/main/README.md
12.4 kB
| language: | |
| - en | |
| license: apache-2.0 | |
| library_name: neuro_compiler | |
| base_model: Qwen/Qwen2.5-Coder-0.5B | |
| tags: | |
| - neural-compiler | |
| - experimental | |
| - non-autoregressive | |
| - graph | |
| - x86-64 | |
| # Neuro-Compiler · 0.2.0-experimental | |
| Neuro-Compiler is an experimental, non-autoregressive neural compiler that | |
| translates restricted C++ source directly into callable x86-64 machine-code | |
| functions. Specialized neural networks learn syntax construction, SSA generation, | |
| instruction selection, register allocation and binary encoding. The output is | |
| bytes, not generated assembly text. | |
| **Research proof of concept, not a production-ready C++ compiler.** Generated | |
| machine code can be incorrect or unsafe. Sampled verification is not formal | |
| equivalence and provides no correctness guarantee. No API executes code natively. | |
| ## What changed | |
| This graph architecture replaces the first release's fixed balanced-tree | |
| representations with source identities, graph dependencies and physical resource | |
| streams. It supports the trained range of arbitrary binary tree topologies with | |
| one through seven operations. Specialized parameters decrease from 3,934,092 to | |
| 3,642,283; this is an architectural change, not simply a larger model. | |
| ```text | |
| Restricted C++ source | |
| ↓ tokenizer + raw character/token offset mapping | |
| Frozen Qwen blocks 1–6 | |
| ↓ | |
| Source-indexed neural AST | |
| ↓ | |
| Graph neural SSA | |
| ↓ | |
| Graph neural instruction selection | |
| ↓ | |
| Occupancy-supervised physical resource streams | |
| ↓ | |
| Independent neural binary encoding | |
| ↓ byte packing and serialization | |
| Callable x86-64 System V function bytes | |
| ``` | |
| The backbone is [Qwen/Qwen2.5-Coder-0.5B](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B), | |
| revision `0576a1bc0ae53f21860e905e081807bd7ff4a4c7`, first six layers, | |
| 96 input tokens and 225,608,960 retained parameters. Its weights are downloaded | |
| separately. Loading may initially download the complete backbone before unused | |
| layers are discarded. Total retained compiler parameters: **229,251,243**. | |
| ## Installation | |
| Python 3.11+; install a CPU or CUDA PyTorch build appropriate for your machine. | |
| ```bash | |
| hf download chrisuser/neuro-compiler --revision 0.2.0-experimental --local-dir neuro-compiler | |
| python -m pip install ./neuro-compiler | |
| # Optional subprocess-isolated Unicorn verification: | |
| python -m pip install './neuro-compiler[evaluation]' | |
| ``` | |
| CUDA regression used Python 3.14, PyTorch 2.13.0+cu132, Transformers 4.57.6, | |
| SafeTensors 0.8.0 and Hugging Face Hub 0.36.2. A fresh, fully isolated environment | |
| installed the documented dependencies and passed CPU inference with PyTorch | |
| 2.15.0+cpu. Exact cross-version or CPU/CUDA byte identity is not guaranteed. | |
| ## Python and CLI usage | |
| ```python | |
| from neuro_compiler import NeuralCompiler | |
| compiler = NeuralCompiler.from_pretrained( | |
| 'chrisuser/neuro-compiler', revision='0.2.0-experimental', device='cuda' | |
| ) | |
| # Local loading and CPU inference also work: | |
| # compiler = NeuralCompiler.from_pretrained('./neuro-compiler', device='cpu') | |
| source = '''unsigned f(unsigned a,unsigned b,unsigned c){ | |
| return ((a+b)*(c-7u)); | |
| }''' | |
| machine_code = compiler.compile(source) | |
| print(machine_code.hex()) | |
| results = compiler.compile_batch([source, source], batch_size=32) | |
| result = compiler.compile(source, return_intermediates=True) | |
| print(result.ast, result.ssa, result.virtual_mir, result.physical_mir) | |
| print(result.machine_code, result.diagnostics) | |
| ``` | |
| ```bash | |
| neuro-compiler --model ./neuro-compiler --file example.cpp --output f.bin | |
| neuro-compiler --model ./neuro-compiler --file example.cpp --verify | |
| ``` | |
| The CLI supports `--revision`, `--device`, source strings and source files. | |
| Output files are raw callable function bytes, **not ELF or PE executables**. | |
| Existing output files are not overwritten. With `--verify`, failed sampled | |
| semantics prevents writing an output file. | |
| ```python | |
| from neuro_compiler.verification import verify | |
| if __name__ == '__main__': # required for multiprocessing in standalone scripts | |
| report = verify(source, machine_code, samples=32, timeout=30) | |
| print(report['disassembled'], report['semantic']) | |
| ``` | |
| Verification uses a spawned subprocess, Capstone and Unicorn, with an enforced | |
| timeout. It never repairs model predictions. Serialization, complete disassembly, | |
| sampled semantic correctness, and formal equivalence are distinct. This project | |
| does not provide formal verification or native execution. | |
| ## Language and target scope | |
| The training grammar uses `unsigned f(unsigned a,unsigned b,unsigned c)` with | |
| a single return expression. Operands are the three arguments or literals `1u` | |
| through `63u`; operators are `+`, `-`, `*`, `^`, `&`, `|`. Expressions are fully | |
| parenthesized arbitrary binary trees containing one through seven operations. | |
| Arithmetic is unsigned 32-bit wrapping arithmetic. The target is **x86-64 System V**, | |
| not the Windows x64 ABI, even when inference runs on Windows. | |
| Loops, branches, arbitrary identifiers, pointers, function calls, general memory | |
| operations, broader C++ syntax and general-purpose linking are unsupported. | |
| Lexical checks reject some unsupported inputs but are not a complete grammar | |
| validator. Formatting outside the synthetic training distribution is unvalidated. | |
| Inputs exceeding 96 Qwen tokens are rejected without truncation. Character/token | |
| offset mapping is preserved; there is no deterministic parser in inference. | |
| Allocation overflow and malformed byte sequences raise errors. | |
| ## Measured end-to-end results | |
| | Metric | Validation | Held-out test | | |
| | --- | ---: | ---: | | |
| | Programs | 2,000 | 2,000 | | |
| | Sampled-correct programs | 1,974 | 1,963 | | |
| | Sampled semantic accuracy | 98.70% | **98.15%** | | |
| | Fully disassembled | 100% | 100% | | |
| | Serializable | 100% | 100% | | |
| | Exact reference bytes | 98.20% | Not measured | | |
| | Input triples per function | 32 | 32 | | |
| Packaged versus original `neurocc_graph_live.py` predictions match byte-for-byte | |
| on **all 4,000 validation and held-out programs**. AST, SSA, virtual MIR, physical | |
| MIR, emission counts, overflow flags and instruction lengths also match exactly. | |
| Semantic results match. Single-versus-batch tests passed on 32 programs from | |
| each split. Checkpoints were fixed before these comparisons; held-out results | |
| were not used to select weights or change the architecture. | |
| | Binary operations | Held-out sampled semantic accuracy | | |
| | ---: | ---: | | |
| | 1 | 100% | | |
| | 2 | 100% | | |
| | 3 | 99.30% | | |
| | 4 | 100% | | |
| | 5 | 98.95% | | |
| | 6 | 95.79% | | |
| | 7 | 92.98% | | |
| | Expression topology | Held-out sampled semantic accuracy | | |
| | --- | ---: | | |
| | Left chain | 99.80% | | |
| | Balanced shape | 98.39% | | |
| | Right chain | 97.59% | | |
| | Random | 96.83% | | |
| These are narrow synthetic-distribution measurements. See the exact counts and | |
| split hashes in `evaluation/` and `manifest.json`. | |
| ## Individual-network measurements | |
| The occupancy allocator's saved validation reports 98.15% exact physical MIR | |
| reconstruction and 98.60% sampled semantics. These are allocator-stage metrics, | |
| not final held-out compiler metrics. The independent binary encoder reconstructs | |
| 100% of reference validation binaries **given correct reference physical MIR**; | |
| it cannot correct earlier neural errors. | |
| Occupancy readouts achieve 99.48% overall register-content identity accuracy and | |
| 99.34% computed-value identity accuracy. These measurements use **supervised, | |
| reference-aligned instruction boundaries**; they do not establish end-to-end | |
| runtime register-state correctness. The manifest retains the saved stage metrics. | |
| ## Performance | |
| New end-to-end graph-runtime measurements on 2,000 test functions, batch 32, | |
| three repeats: median **4.961 seconds**, **403.15 candidates/second** and | |
| **395.69 sampled-correct candidates/second**. Peak CUDA allocation: **562.14 MiB** | |
| (reserved 616 MiB). Hardware: RTX 2060 SUPER and Intel Core i9-10850K. | |
| Timing includes tokenization, host/device transfers, all neural stages, byte | |
| packing and CPU serialization; it excludes model initialization, file I/O and | |
| verification. Correct throughput multiplies measured candidate throughput by | |
| the separately sampled semantic rate. | |
| Clang 23.1.2 at `-O0`, batch 128 and eight CPU workers measured **17,648.68 | |
| functions/second**, median 0.1133 seconds, for the same source set. This baseline | |
| uses batched C++ translation units and includes frontend/backend compilation; | |
| its correctness was not evaluated by the timing. **These measurements do not | |
| show a performance advantage over Clang.** Conditions differ in batching and | |
| hardware use; see `evaluation/benchmark.json` for the complete methodology. | |
| Separate synchronized profiling measured milliseconds per function: | |
| | Stage | ms/function | | |
| | --- | ---: | | |
| | Tokenization and input transfer | 1.0031 | | |
| | Qwen | 1.1426 | | |
| | AST | 0.1522 | | |
| | SSA | 0.2170 | | |
| | Instruction selection | 0.2272 | | |
| | Register allocation | 0.3193 | | |
| | Binary encoding | 0.0618 | | |
| | Output transfer | 0.0038 | | |
| Synchronization adds overhead; these separate-pass values need not sum to the | |
| unsynchronized end-to-end time. Initialization and CPU smoke-test timings are | |
| recorded in the regression and portability JSON reports. No historical V1 or | |
| 0.1.0 throughput is presented as a measurement of this architecture. | |
| ## Training and reproducibility | |
| The base graph curriculum has 16,000 training, 2,000 validation and 2,000 held-out | |
| programs. Register-allocation training additionally uses 48,000 generated training | |
| candidates (approximately 64,000 total curriculum programs; some generated traces | |
| may be filtered). Exact expansion provenance is recorded in the manifest. | |
| Reference traces supervise training and evaluation only. No dataset, cached | |
| activations, compiler traces, optimizer state or training script is required by | |
| the installed inference package. | |
| All five original checkpoint hashes and selected epochs are recorded in | |
| `manifest.json`, together with configs, vocabularies, register descriptors, | |
| encoding templates, dataset hashes and exported SafeTensors hashes. They are | |
| unquantized FP32 specialized weights, preserving exact values and dtypes. | |
| CUDA Qwen uses the original FP16/autocast path; FP16 inter-stage boundaries and | |
| FP32 specialized operations match the live implementation. CPU Qwen uses FP32. | |
| The loader verifies file hashes, state schemas and vocabulary compatibility. | |
| Local preparation tools in the development checkout are | |
| `neurocc_graph_export.py`, `neurocc_graph_release_test.py`, | |
| `neurocc_graph_release_smoke.py` and `neurocc_graph_release_benchmark.py`. | |
| They operate on original artifacts without training or modifying weights. | |
| The installed-wheel portability test ran in a fresh dependency environment, | |
| outside the checkout, while denying access to original development directories. | |
| The previous release remains reproducible at commit | |
| `757aecb2942c3bd66c324b925a93dd366a6a6de1`. The library also dispatches legacy | |
| V2 manifests to its preserved legacy inference implementation. Use a pinned | |
| revision rather than moving `main` for reproducibility. | |
| ## Research directions | |
| The next studies target 15, 31 and larger operation counts; more identifiers, | |
| literals and operators; longer-range value tracking and allocation; control flow | |
| and memory; and alternative pretrained frontends. Generalization beyond the | |
| current seven-operation curriculum remains open. | |
| Source identities and graph pointers retain computational associations across | |
| stages. Several stages have size-independent learned parameters. Resource streams | |
| and independent binary encoding have approximately linear length scaling under | |
| fixed-resource and local-processing assumptions. **The whole compiler is not | |
| linear-time**: Qwen and other attention stages retain quadratic components. | |
| See [ARCHITECTURE.md](ARCHITECTURE.md). | |
| Natural-language-to-SSA compilation and general-purpose language models with | |
| specialized executable-output heads are proposed research directions, not | |
| features of this release. The long-term question is whether pretrained models | |
| can emit executable computations through learned backends without textual source | |
| or assembly as intermediate outputs. No claim of being the first neural compiler | |
| or of guaranteed executable correctness is made. | |
| ## License | |
| Apache-2.0 for project code and specialized weights, following 0.1.0's conventions. | |
| The pinned Qwen model metadata declares Apache-2.0. Qwen weights and third-party | |
| source are not redistributed here. See `LICENSE` and `THIRD_PARTY_NOTICES.md`. | |