Upload 40 files
Browse files- .gitattributes +0 -34
- .gitignore +9 -0
- LICENSE +202 -0
- PUBLISHING.md +26 -0
- README.md +227 -0
- THIRD_PARTY_NOTICES.md +17 -0
- config.json +12 -0
- evaluation/EXCLUDED_ARTIFACTS.md +15 -0
- evaluation/benchmark.json +186 -0
- evaluation/fresh_test.json +334 -0
- evaluation/portability.json +30 -0
- evaluation/preparation.json +52 -0
- evaluation/regression.json +28 -0
- evaluation/validation.json +329 -0
- examples/batch_example.py +6 -0
- examples/compile_example.py +3 -0
- examples/inspect_example.py +4 -0
- manifest.json +0 -0
- neuro_compiler/__init__.py +4 -0
- neuro_compiler/cli.py +18 -0
- neuro_compiler/compiler.py +86 -0
- neuro_compiler/neurocc.py +48 -0
- neuro_compiler/neurocc_ast.py +102 -0
- neuro_compiler/neurocc_backend_trace.py +38 -0
- neuro_compiler/neurocc_binary.py +113 -0
- neuro_compiler/neurocc_ir_unfolded.py +47 -0
- neuro_compiler/neurocc_isel.py +44 -0
- neuro_compiler/neurocc_isel_v2.py +41 -0
- neuro_compiler/neurocc_live_v2.py +129 -0
- neuro_compiler/neurocc_regalloc.py +48 -0
- neuro_compiler/neurocc_regalloc_v2.py +23 -0
- neuro_compiler/verification.py +10 -0
- pyproject.toml +21 -0
- requirements.txt +4 -0
- tests/test_contract.py +19 -0
- weights/ast.safetensors +3 -0
- weights/binary.safetensors +3 -0
- weights/isel.safetensors +3 -0
- weights/regalloc.safetensors +3 -0
- weights/ssa.safetensors +3 -0
.gitattributes
CHANGED
|
@@ -1,35 +1 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
.venv/
|
| 4 |
+
*.egg-info/
|
| 5 |
+
build/
|
| 6 |
+
dist/
|
| 7 |
+
.env
|
| 8 |
+
*.pt
|
| 9 |
+
.cache/
|
LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache License
|
| 3 |
+
Version 2.0, January 2004
|
| 4 |
+
http://www.apache.org/licenses/
|
| 5 |
+
|
| 6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
+
|
| 8 |
+
1. Definitions.
|
| 9 |
+
|
| 10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
+
|
| 13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
+
the copyright owner that is granting the License.
|
| 15 |
+
|
| 16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
+
other entities that control, are controlled by, or are under common
|
| 18 |
+
control with that entity. For the purposes of this definition,
|
| 19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
+
direction or management of such entity, whether by contract or
|
| 21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
+
|
| 24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
+
exercising permissions granted by this License.
|
| 26 |
+
|
| 27 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
+
including but not limited to software source code, documentation
|
| 29 |
+
source, and configuration files.
|
| 30 |
+
|
| 31 |
+
"Object" form shall mean any form resulting from mechanical
|
| 32 |
+
transformation or translation of a Source form, including but
|
| 33 |
+
not limited to compiled object code, generated documentation,
|
| 34 |
+
and conversions to other media types.
|
| 35 |
+
|
| 36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
+
Object form, made available under the License, as indicated by a
|
| 38 |
+
copyright notice that is included in or attached to the work
|
| 39 |
+
(an example is provided in the Appendix below).
|
| 40 |
+
|
| 41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
+
form, that is based on (or derived from) the Work and for which the
|
| 43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
+
of this License, Derivative Works shall not include works that remain
|
| 46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
+
the Work and Derivative Works thereof.
|
| 48 |
+
|
| 49 |
+
"Contribution" shall mean any work of authorship, including
|
| 50 |
+
the original version of the Work and any modifications or additions
|
| 51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
+
means any form of electronic, verbal, or written communication sent
|
| 56 |
+
to the Licensor or its representatives, including but not limited to
|
| 57 |
+
communication on electronic mailing lists, source code control systems,
|
| 58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
+
excluding communication that is conspicuously marked or otherwise
|
| 61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
+
|
| 63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
+
subsequently incorporated within the Work.
|
| 66 |
+
|
| 67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
+
Work and such Derivative Works in Source or Object form.
|
| 73 |
+
|
| 74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
+
(except as stated in this section) patent license to make, have made,
|
| 78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
+
where such license applies only to those patent claims licensable
|
| 80 |
+
by such Contributor that are necessarily infringed by their
|
| 81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
+
institute patent litigation against any entity (including a
|
| 84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
+
or contributory patent infringement, then any patent licenses
|
| 87 |
+
granted to You under this License for that Work shall terminate
|
| 88 |
+
as of the date such litigation is filed.
|
| 89 |
+
|
| 90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
+
modifications, and in Source or Object form, provided that You
|
| 93 |
+
meet the following conditions:
|
| 94 |
+
|
| 95 |
+
(a) You must give any other recipients of the Work or
|
| 96 |
+
Derivative Works a copy of this License; and
|
| 97 |
+
|
| 98 |
+
(b) You must cause any modified files to carry prominent notices
|
| 99 |
+
stating that You changed the files; and
|
| 100 |
+
|
| 101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
+
that You distribute, all copyright, patent, trademark, and
|
| 103 |
+
attribution notices from the Source form of the Work,
|
| 104 |
+
excluding those notices that do not pertain to any part of
|
| 105 |
+
the Derivative Works; and
|
| 106 |
+
|
| 107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
+
distribution, then any Derivative Works that You distribute must
|
| 109 |
+
include a readable copy of the attribution notices contained
|
| 110 |
+
within such NOTICE file, excluding those notices that do not
|
| 111 |
+
pertain to any part of the Derivative Works, in at least one
|
| 112 |
+
of the following places: within a NOTICE text file distributed
|
| 113 |
+
as part of the Derivative Works; within the Source form or
|
| 114 |
+
documentation, if provided along with the Derivative Works; or,
|
| 115 |
+
within a display generated by the Derivative Works, if and
|
| 116 |
+
wherever such third-party notices normally appear. The contents
|
| 117 |
+
of the NOTICE file are for informational purposes only and
|
| 118 |
+
do not modify the License. You may add Your own attribution
|
| 119 |
+
notices within Derivative Works that You distribute, alongside
|
| 120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
+
that such additional attribution notices cannot be construed
|
| 122 |
+
as modifying the License.
|
| 123 |
+
|
| 124 |
+
You may add Your own copyright statement to Your modifications and
|
| 125 |
+
may provide additional or different license terms and conditions
|
| 126 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
+
the conditions stated in this License.
|
| 130 |
+
|
| 131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
+
this License, without any additional terms or conditions.
|
| 135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
+
the terms of any separate license agreement you may have executed
|
| 137 |
+
with Licensor regarding such Contributions.
|
| 138 |
+
|
| 139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
+
except as required for reasonable and customary use in describing the
|
| 142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
+
|
| 144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
+
implied, including, without limitation, any warranties or conditions
|
| 149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
+
appropriateness of using or redistributing the Work and assume any
|
| 152 |
+
risks associated with Your exercise of permissions under this License.
|
| 153 |
+
|
| 154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
+
unless required by applicable law (such as deliberate and grossly
|
| 157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
+
liable to You for damages, including any direct, indirect, special,
|
| 159 |
+
incidental, or consequential damages of any character arising as a
|
| 160 |
+
result of this License or out of the use or inability to use the
|
| 161 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
+
other commercial damages or losses), even if such Contributor
|
| 164 |
+
has been advised of the possibility of such damages.
|
| 165 |
+
|
| 166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
+
or other liability obligations and/or rights consistent with this
|
| 170 |
+
License. However, in accepting such obligations, You may act only
|
| 171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
+
defend, and hold each Contributor harmless for any liability
|
| 174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
+
of your accepting any such warranty or additional liability.
|
| 176 |
+
|
| 177 |
+
END OF TERMS AND CONDITIONS
|
| 178 |
+
|
| 179 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 180 |
+
|
| 181 |
+
To apply the Apache License to your work, attach the following
|
| 182 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 183 |
+
replaced with your own identifying information. (Don't include
|
| 184 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 185 |
+
comment syntax for the file format. We also recommend that a
|
| 186 |
+
file or class name and description of purpose be included on the
|
| 187 |
+
same "printed page" as the copyright notice for easier
|
| 188 |
+
identification within third-party archives.
|
| 189 |
+
|
| 190 |
+
Copyright [yyyy] [name of copyright owner]
|
| 191 |
+
|
| 192 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 193 |
+
you may not use this file except in compliance with the License.
|
| 194 |
+
You may obtain a copy of the License at
|
| 195 |
+
|
| 196 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 197 |
+
|
| 198 |
+
Unless required by applicable law or agreed to in writing, software
|
| 199 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 200 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 201 |
+
See the License for the specific language governing permissions and
|
| 202 |
+
limitations under the License.
|
PUBLISHING.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Publication after owner review
|
| 2 |
+
|
| 3 |
+
No upload has been performed. Run these commands only after reviewing this
|
| 4 |
+
directory and explicitly authorizing publication. Upload only this directory,
|
| 5 |
+
not its parent (which contains private audit data and PyTorch checkpoints).
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
hf auth login
|
| 9 |
+
hf repo create orthagonal/neuro-compiler --repo-type model --private
|
| 10 |
+
hf upload orthagonal/neuro-compiler . --repo-type model
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
Run from the `release/neuro-compiler` directory. If the model repository already
|
| 14 |
+
exists, omit `repo create`. The private flag preserves review access controls;
|
| 15 |
+
changing repository visibility is a separate owner action after approval.
|
| 16 |
+
|
| 17 |
+
Local installation before publication:
|
| 18 |
+
|
| 19 |
+
```bash
|
| 20 |
+
python -m pip install '.[evaluation]'
|
| 21 |
+
neuro-compiler --model . --source 'unsigned f(unsigned a,unsigned b,unsigned c){return (a+b);}' --verify
|
| 22 |
+
python -m unittest discover -s tests
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
The pip package contains inference code; the directory's SafeTensors weights
|
| 26 |
+
are loaded through `--model .` or `from_pretrained`, not embedded into the wheel.
|
README.md
CHANGED
|
@@ -1,3 +1,230 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
license: apache-2.0
|
| 5 |
+
library_name: neuro_compiler
|
| 6 |
+
base_model: Qwen/Qwen2.5-Coder-0.5B
|
| 7 |
+
tags:
|
| 8 |
+
- neural-compiler
|
| 9 |
+
- experimental
|
| 10 |
+
- non-autoregressive
|
| 11 |
+
- x86-64
|
| 12 |
+
model-index:
|
| 13 |
+
- name: neuro-compiler
|
| 14 |
+
results: []
|
| 15 |
---
|
| 16 |
+
|
| 17 |
+
# neuro-compiler · 0.1.0-experimental
|
| 18 |
+
|
| 19 |
+
Neuro-Compiler is an experimental, non-autoregressive neural compiler that
|
| 20 |
+
translates a restricted subset of C++ directly into x86-64 machine code through
|
| 21 |
+
a series of specialized neural networks. Rather than generating assembly text,
|
| 22 |
+
it learns successive compilation transformations through syntax trees,
|
| 23 |
+
intermediate representations, instruction selection, register allocation and
|
| 24 |
+
binary encoding.
|
| 25 |
+
|
| 26 |
+
This is a research proof of concept and work in progress, not a production-ready
|
| 27 |
+
compiler. Generated machine code may be incorrect or unsafe. No semantic
|
| 28 |
+
correctness is guaranteed. Never execute untrusted generated code natively.
|
| 29 |
+
|
| 30 |
+
## Research architecture
|
| 31 |
+
|
| 32 |
+
```text
|
| 33 |
+
C++ source → frozen Qwen blocks 1–6 → neural AST → neural unfolded SSA
|
| 34 |
+
→ neural instruction selection → neural register allocation
|
| 35 |
+
→ neural binary generation → x86-64 SysV machine-code bytes
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
Internal architecture: NeuroCC V2. Stage modes are `deps_w128`, `deps_w128`,
|
| 39 |
+
`discrete_copy_w128`, `aligned_copy_w128`, and `copy_w128`, respectively. No V3
|
| 40 |
+
register allocator is included. All stages predict in parallel, without
|
| 41 |
+
autoregressive decoding. Inference uses tensor operations and learned encoding
|
| 42 |
+
template lookup/packing; it has no conventional compiler, assembler, semantic
|
| 43 |
+
oracle, deterministic instruction selector, or allocator.
|
| 44 |
+
|
| 45 |
+
The backbone is **Qwen/Qwen2.5-Coder-0.5B**, pinned to revision
|
| 46 |
+
`0576a1bc0ae53f21860e905e081807bd7ff4a4c7`. The loader downloads that revision
|
| 47 |
+
from Hugging Face and retains its first six blocks; full base weights may be
|
| 48 |
+
downloaded before unused blocks are discarded. The remaining backbone has
|
| 49 |
+
225,608,960 parameters. Specialized stages have 3,934,092 parameters.
|
| 50 |
+
Weights are unquantized and retain trained dtypes. CUDA Qwen uses FP16 and
|
| 51 |
+
FP16 autocast; specialized computation uses FP32 with explicit FP16 stage
|
| 52 |
+
boundaries, including before discrete head decoding. CPU Qwen uses FP32;
|
| 53 |
+
cross-device byte identity is not assumed.
|
| 54 |
+
|
| 55 |
+
## Installation and use
|
| 56 |
+
|
| 57 |
+
Use Python 3.10 or newer. Install a PyTorch build suitable for your CPU or CUDA
|
| 58 |
+
device first. The measured environment used Python 3.14, PyTorch 2.13.0+cu132,
|
| 59 |
+
Transformers 4.57.6, SafeTensors 0.8.0 and Hugging Face Hub 0.36.2. Other PyTorch
|
| 60 |
+
versions satisfy the install bounds but have not been regression-tested here.
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
hf download orthagonal/neuro-compiler --local-dir neuro-compiler
|
| 64 |
+
python -m pip install ./neuro-compiler
|
| 65 |
+
# Optional sampled semantic verification:
|
| 66 |
+
python -m pip install './neuro-compiler[evaluation]'
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from neuro_compiler import NeuralCompiler
|
| 71 |
+
|
| 72 |
+
compiler = NeuralCompiler.from_pretrained('orthagonal/neuro-compiler', device='cuda')
|
| 73 |
+
# A downloaded local directory also works:
|
| 74 |
+
# compiler = NeuralCompiler.from_pretrained('./neuro-compiler', device='cpu')
|
| 75 |
+
source = 'unsigned f(unsigned a,unsigned b,unsigned c){return ((a+b)*(c-7u));}'
|
| 76 |
+
machine_code = compiler.compile(source)
|
| 77 |
+
print(machine_code.hex(' '))
|
| 78 |
+
results = compiler.compile_batch([source, source], batch_size=32)
|
| 79 |
+
result = compiler.compile(source, return_intermediates=True)
|
| 80 |
+
print(result.ast, result.ssa, result.virtual_mir, result.physical_mir)
|
| 81 |
+
print(result.machine_code)
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
neuro-compiler --model ./neuro-compiler --file example.cpp --device cuda
|
| 86 |
+
neuro-compiler --model ./neuro-compiler --source 'unsigned f(unsigned a,unsigned b,unsigned c){return (a+b);}' --output f.bin --verify
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
There is no native execution interface or Windows executable packaging in this
|
| 90 |
+
release. Output targets **x86-64 SysV**, not the Windows x64 calling convention.
|
| 91 |
+
CUDA and CPU are supported. Empty/malformed byte output raises an error. Source
|
| 92 |
+
capacity is 192 UTF-8 bytes and 96 Qwen tokens; oversized inputs are rejected,
|
| 93 |
+
never silently truncated. Lexical checks detect some unsupported inputs, but
|
| 94 |
+
acceptance is not a guarantee that an input belongs to the trained grammar.
|
| 95 |
+
|
| 96 |
+
## Intermediate representations
|
| 97 |
+
|
| 98 |
+
`result.ast` contains breadth-first node class IDs and FP16 latent features.
|
| 99 |
+
`ssa` contains opcode, operand-address and unsigned constant tensors. Virtual
|
| 100 |
+
MIR contains signature IDs, virtual operand references and immediates. Physical
|
| 101 |
+
MIR contains signature IDs, register IDs, immediates and stack fields. All these
|
| 102 |
+
public intermediate tensors are moved to CPU. Exact vocabularies, dimensions,
|
| 103 |
+
mask conventions, operand reference conventions, and binary templates are in
|
| 104 |
+
`manifest.json` and the inference modules. They are embedded in configurations
|
| 105 |
+
rather than duplicated into separate vocabulary files. SSA references use
|
| 106 |
+
argument IDs 1–3, instruction IDs beginning at 4, constant ID 12, and padding 0.
|
| 107 |
+
|
| 108 |
+
## Supported source grammar
|
| 109 |
+
|
| 110 |
+
The dataset generator uses the signature
|
| 111 |
+
`unsigned f(unsigned a,unsigned b,unsigned c){return EXPR;}`. Expressions are
|
| 112 |
+
fully parenthesized balanced binary trees of depth 1–3, with leaves `a`, `b`,
|
| 113 |
+
`c`, or unsigned literals `1u` through `63u`. Operators are `+`, `-`, `*`, `^`,
|
| 114 |
+
`&`, `|`; arithmetic wraps at 32 bits. Up to seven arithmetic nodes plus return
|
| 115 |
+
fit the eight-slot unfolded SSA. Formatting different from training is not
|
| 116 |
+
validated for accuracy.
|
| 117 |
+
|
| 118 |
+
There is no general control flow, loops, arbitrary calls, pointers, division,
|
| 119 |
+
signed or floating-point arithmetic, arbitrary trees, or full C++ support.
|
| 120 |
+
Spills remain a major weakness. A syntactically accepted source may yield
|
| 121 |
+
semantically wrong machine code.
|
| 122 |
+
|
| 123 |
+
## Training and release provenance
|
| 124 |
+
|
| 125 |
+
The original synthetic corpus contains 10,000 unique balanced expression
|
| 126 |
+
functions: 8,000 training, 1,000 validation and 1,000 original test rows. Frozen
|
| 127 |
+
Qwen features feed progressively trained specialized stages, with compiler
|
| 128 |
+
traces used only as training/reference labels. V2 instruction selection and
|
| 129 |
+
register allocation learn operand-addressed copying; binary prediction learns
|
| 130 |
+
templates and payloads. Dataset fingerprint and checkpoint hashes are recorded
|
| 131 |
+
in the manifest. Training data, traces and activation caches are not included.
|
| 132 |
+
|
| 133 |
+
During release preparation, the retained original register-allocation cache
|
| 134 |
+
matched the historical binary decoder's training cache SHA-256 exactly. The
|
| 135 |
+
current best allocator was epoch 171, whereas the historical allocator was
|
| 136 |
+
epoch 165. Regenerating all 9,000 train/validation rows found 17,254,761 differing
|
| 137 |
+
FP16 feature elements and 66 signature, 163 register, and 21 immediate
|
| 138 |
+
prediction differences. Stack predictions matched. Consequently the historical
|
| 139 |
+
binary decoder was not reused. Only the V2 binary decoder was retrained, for
|
| 140 |
+
50 epochs with seed 42, using a separately regenerated and hash-validated
|
| 141 |
+
allocator cache. No upstream network was retrained. Historical checkpoints,
|
| 142 |
+
caches and results were backed up and preserved.
|
| 143 |
+
|
| 144 |
+
## Verification and reproducibility
|
| 145 |
+
|
| 146 |
+
Successful serialization establishes only valid byte/EOS/padding structure.
|
| 147 |
+
Complete Capstone disassembly establishes decoding into supported straight-line
|
| 148 |
+
instructions. Unicorn checks compare sampled inputs to a separate restricted
|
| 149 |
+
source oracle. None constitutes formal verification. Optional evaluation is
|
| 150 |
+
separate from inference and never corrects model predictions:
|
| 151 |
+
|
| 152 |
+
```python
|
| 153 |
+
from neuro_compiler.verification import verify
|
| 154 |
+
report = verify(source, machine_code, samples=32)
|
| 155 |
+
print(report['disassembled'], report['semantic'])
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
The local preparation tools `neurocc_release_recover.py`,
|
| 159 |
+
`neurocc_release_validate.py`, `neurocc_release_evaluate.py`, and
|
| 160 |
+
`neurocc_export.py` remain in the development checkout. They require private
|
| 161 |
+
training artifacts and are not runtime dependencies. Frozen checkpoint hashes
|
| 162 |
+
are in the manifest. SafeTensors exports are checked for exact tensor and dtype
|
| 163 |
+
round trips. Full stage and semantic comparisons against the live V2
|
| 164 |
+
implementation are reported in `evaluation/regression.json`.
|
| 165 |
+
|
| 166 |
+
Fresh evaluation uses the original generator, seed 20261126, excludes all
|
| 167 |
+
original source strings and preserves original test-depth proportions. Sampled
|
| 168 |
+
live verification uses 32 inputs (eight edge cases plus seeded random triples)
|
| 169 |
+
per function, seed 20261125. Fresh-test summary includes the generated source
|
| 170 |
+
digest. Fresh results must not be used to tune this release.
|
| 171 |
+
|
| 172 |
+
## Measured release results
|
| 173 |
+
|
| 174 |
+
| Metric | Historical V2 validation | This release validation | Fresh source-disjoint test |
|
| 175 |
+
| --- | ---: | ---: | ---: |
|
| 176 |
+
| Functions | 1,000 | 1,000 | 1,000 |
|
| 177 |
+
| Exact unoptimized reference bytes | 97.1% | 97.4% | Not measured |
|
| 178 |
+
| Sampled semantic correctness | 97.7% | 97.7% | 97.3% |
|
| 179 |
+
| Completely disassembled | 99.9% | 99.9% | 99.8% |
|
| 180 |
+
| Serializable | 100% | 100% | 100% |
|
| 181 |
+
|
| 182 |
+
Each semantic evaluation uses 32 input triples per function. New cached versus
|
| 183 |
+
live byte agreement is 100%. Packaged versus new live V2 predictions match
|
| 184 |
+
exactly on all 1,000 validation functions at every stage, including AST
|
| 185 |
+
predictions, SSA, virtual MIR, physical MIR, final bytes and semantic outcomes.
|
| 186 |
+
The new compiler matches historical V2 bytes on 976/1,000 functions: **24 outputs
|
| 187 |
+
changed**. Equal aggregate semantic accuracy does not imply identical programs.
|
| 188 |
+
|
| 189 |
+
The original V2 runtime benchmark of this release's weights measured 648.07
|
| 190 |
+
candidates/second and 633.16 sampled-correct candidates/second on an NVIDIA
|
| 191 |
+
GeForce RTX 2060 SUPER and Intel Core i9-10850K, batch 32, three repeats over
|
| 192 |
+
1,000 functions. Median inference time was 1.5431 seconds; peak CUDA allocation
|
| 193 |
+
was 562.59 MiB. Timing includes tokenization, GPU inference, CPU transfer and
|
| 194 |
+
serialization; it excludes initialization, verification and disk I/O. Correct
|
| 195 |
+
throughput is candidate throughput multiplied by the separately measured sampled
|
| 196 |
+
semantic rate. These are newly measured V2 results; no V1 timing is used.
|
| 197 |
+
|
| 198 |
+
Packaged CUDA initialization measured 4.586 seconds in the standalone smoke
|
| 199 |
+
test with locally cached backbone files; CPU initialization measured 1.034
|
| 200 |
+
seconds afterward in the same process. The warmed second-model initialization
|
| 201 |
+
in the regression harness was 1.206 seconds. These are not first-download times.
|
| 202 |
+
CPU and CUDA both compiled, batched, exposed intermediates and passed sampled
|
| 203 |
+
verification for the documented quick-start source. Full regression was CUDA
|
| 204 |
+
only. An installed wheel ran outside the checkout while audit hooks denied
|
| 205 |
+
access to the development directory and original artifact storage. The separate
|
| 206 |
+
virtual environment shared system CUDA dependencies; a fully isolated dependency
|
| 207 |
+
installation was not tested. See the JSON reports in `evaluation/`.
|
| 208 |
+
|
| 209 |
+
SafeTensors sizes: AST 2,897,832 bytes; SSA 3,275,072; ISEL 3,228,664;
|
| 210 |
+
register allocation 3,029,992; binary 3,331,152. Combined: 15,762,712 bytes,
|
| 211 |
+
including SafeTensors headers and state metadata. No Qwen weights are bundled.
|
| 212 |
+
|
| 213 |
+
## Limitations and future work
|
| 214 |
+
|
| 215 |
+
Accuracy is measured on a narrow synthetic grammar. Validation was used for
|
| 216 |
+
checkpoint selection; it is not an independent generalization estimate.
|
| 217 |
+
Batch-size and numerical backend changes may change predictions. No throughput
|
| 218 |
+
advantage over conventional compilers has been established. Historical V1
|
| 219 |
+
benchmark claims are not measurements of this release.
|
| 220 |
+
|
| 221 |
+
Research directions include variable-sized graphs, learned pointers, arbitrary
|
| 222 |
+
expression trees, control flow and pluggable hardware backends. These are plans,
|
| 223 |
+
not implemented capabilities. The long-term objective is to study whether GPU
|
| 224 |
+
parallelism can outperform conventional compilation while preserving semantics.
|
| 225 |
+
|
| 226 |
+
## License and attribution
|
| 227 |
+
|
| 228 |
+
Apache-2.0 for project code and specialized trained weights, authorized by the
|
| 229 |
+
project owner. Qwen attribution and optional dependency licensing are described
|
| 230 |
+
in `THIRD_PARTY_NOTICES.md`. Qwen weights and third-party source are not bundled.
|
THIRD_PARTY_NOTICES.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Third-party components and release licensing
|
| 2 |
+
|
| 3 |
+
The frozen backbone is Qwen/Qwen2.5-Coder-0.5B, revision
|
| 4 |
+
0576a1bc0ae53f21860e905e081807bd7ff4a4c7. Its weights and tokenizer are downloaded
|
| 5 |
+
from Hugging Face rather than redistributed here. See the upstream model card
|
| 6 |
+
and license: https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B .
|
| 7 |
+
|
| 8 |
+
Runtime dependencies are separately installed: PyTorch (BSD-style license),
|
| 9 |
+
Transformers (Apache-2.0), SafeTensors (Apache-2.0), Hugging Face Hub
|
| 10 |
+
(Apache-2.0). Optional Capstone and Unicorn have their own BSD and GPL-family
|
| 11 |
+
licensing terms respectively; they are evaluation dependencies, not bundled code.
|
| 12 |
+
Consult the installed versions' license files before redistributing them.
|
| 13 |
+
|
| 14 |
+
The project owner authorized Apache-2.0 for project code and specialized trained
|
| 15 |
+
weights during release preparation. See LICENSE. The pinned Qwen revision's
|
| 16 |
+
Hugging Face model metadata declares Apache-2.0; its snapshot does not contain
|
| 17 |
+
a separate LICENSE file. Its model card links to the upstream license.
|
config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": "NeuroCC V2",
|
| 3 |
+
"package_version": "0.1.0.dev0",
|
| 4 |
+
"spec": {
|
| 5 |
+
"backbone": "Qwen/Qwen2.5-Coder-0.5B",
|
| 6 |
+
"revision": "0576a1bc0ae53f21860e905e081807bd7ff4a4c7",
|
| 7 |
+
"tokens": 96,
|
| 8 |
+
"depths": [
|
| 9 |
+
6
|
| 10 |
+
]
|
| 11 |
+
}
|
| 12 |
+
}
|
evaluation/EXCLUDED_ARTIFACTS.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Excluded from publication
|
| 2 |
+
|
| 3 |
+
Original and regenerated training datasets; Qwen activation caches; stage
|
| 4 |
+
latent/prediction caches; LLVM IR, MIR and compilation traces; optimizer and
|
| 5 |
+
resume checkpoints; all original PyTorch checkpoints; V1 models; V3 and other
|
| 6 |
+
architectural experiments; training scripts; full training histories; executable
|
| 7 |
+
demos; screenshots; development logs; local inventory and backup manifests;
|
| 8 |
+
credentials/environment files; Python caches; build and packaging intermediates.
|
| 9 |
+
|
| 10 |
+
Frozen PyTorch checkpoint copies are retained separately in the development
|
| 11 |
+
checkout under `release/checkpoints-v2`, with SHA-256 lock metadata and read-only
|
| 12 |
+
file attributes. They are not needed by the public SafeTensors runtime and must
|
| 13 |
+
not be uploaded. The complete original project/artifact backup is outside this
|
| 14 |
+
release. Selected evaluation summaries contain small failure examples, not the
|
| 15 |
+
training corpus or fresh-evaluation source dataset.
|
evaluation/benchmark.json
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"pipeline": {
|
| 3 |
+
"compiler_version": "v2",
|
| 4 |
+
"abi": "x86_64 SysV",
|
| 5 |
+
"spec": {
|
| 6 |
+
"backbone": "Qwen/Qwen2.5-Coder-0.5B",
|
| 7 |
+
"revision": "0576a1bc0ae53f21860e905e081807bd7ff4a4c7",
|
| 8 |
+
"tokens": 96,
|
| 9 |
+
"depths": [
|
| 10 |
+
6
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
"fingerprint": "b8dd5570bd628cdad71bcb8bbffc76de11cd46f7b5d3be0cc4e3ad0bb2997e31",
|
| 14 |
+
"device": "cuda",
|
| 15 |
+
"checkpoints": {
|
| 16 |
+
"ast": {
|
| 17 |
+
"sha256": "e753e8ab8e997ebe48e166e6b0f2380bb3ab450c087871c4d740eef2326897e3",
|
| 18 |
+
"mode": "deps",
|
| 19 |
+
"epoch": 12
|
| 20 |
+
},
|
| 21 |
+
"ir": {
|
| 22 |
+
"sha256": "90bea9167a71409202397e2543c5c8beecd5a4a2d1169b268337db0175536244",
|
| 23 |
+
"mode": "deps",
|
| 24 |
+
"epoch": 15
|
| 25 |
+
},
|
| 26 |
+
"isel": {
|
| 27 |
+
"sha256": "d95f10f3bca327e65cb3c1e716d1b85d3db1addea2f144b40709809c27c9ff61",
|
| 28 |
+
"mode": "discrete_copy",
|
| 29 |
+
"epoch": 37
|
| 30 |
+
},
|
| 31 |
+
"regalloc": {
|
| 32 |
+
"sha256": "48f77152cff7532ebff835b4d0b15d603504de20f34378ab29634a4c3e83e582",
|
| 33 |
+
"mode": "aligned_copy",
|
| 34 |
+
"epoch": 171
|
| 35 |
+
},
|
| 36 |
+
"binary": {
|
| 37 |
+
"sha256": "3159a286d3b021fb62fec303648545c4abb9a8ad44a27246e02f75420bc58c4b",
|
| 38 |
+
"mode": "copy",
|
| 39 |
+
"epoch": 43
|
| 40 |
+
}
|
| 41 |
+
},
|
| 42 |
+
"precision": "Qwen cache precision; FP16 boundaries, FP32 specialized stages",
|
| 43 |
+
"specialized_parameters": 3934092,
|
| 44 |
+
"backbone_parameters": 225608960,
|
| 45 |
+
"binary_validation": {
|
| 46 |
+
"n": 1000,
|
| 47 |
+
"exact": 0.9739999771118164,
|
| 48 |
+
"byte_accuracy": 0.976840078830719,
|
| 49 |
+
"count_accuracy": 0.9900000095367432,
|
| 50 |
+
"template_accuracy": 0.9810349345207214,
|
| 51 |
+
"template_exact": 0.9779999852180481,
|
| 52 |
+
"payload_byte_accuracy_given_template": 0.9982773661613464,
|
| 53 |
+
"immediate_byte_accuracy_given_template": 0.9982691407203674,
|
| 54 |
+
"displacement_byte_accuracy_given_template": 1.0,
|
| 55 |
+
"spill_exact": 0.1538461595773697,
|
| 56 |
+
"spill_n": 13,
|
| 57 |
+
"nonspill_exact": 0.9848024249076843,
|
| 58 |
+
"semantic32": 0.977,
|
| 59 |
+
"semantic_accuracy": 0.977,
|
| 60 |
+
"semantic_n": 1000,
|
| 61 |
+
"inputs_per_function": 32,
|
| 62 |
+
"fully_disassembled": 0.999,
|
| 63 |
+
"semantic_failure_examples": [
|
| 64 |
+
{
|
| 65 |
+
"row": 8139,
|
| 66 |
+
"reason": "row 8139: emulator mismatch on (0, 0, 0), 13 != 122"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"row": 8143,
|
| 70 |
+
"reason": "row 8143: emulator mismatch on (0, 0, 0), 0 != 7"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"row": 8202,
|
| 74 |
+
"reason": "row 8202: emulator mismatch on (1, 1, 1), 1 != 15"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"row": 8225,
|
| 78 |
+
"reason": "row 8225: emulator mismatch on (1, 1, 1), 57 != 58"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"row": 8232,
|
| 82 |
+
"reason": "row 8232: emulator mismatch on (0, 4294967295, 1), 0 != 150"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"row": 8234,
|
| 86 |
+
"reason": "row 8234: emulator mismatch on (0, 0, 0), 1206 != 582"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"row": 8297,
|
| 90 |
+
"reason": "row 8297: emulator mismatch on (1, 1, 1), 100 != 105"
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"row": 8380,
|
| 94 |
+
"reason": "row 8380: emulator mismatch on (0, 4294967295, 1), 4294967294 != 4294967295"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"row": 8441,
|
| 98 |
+
"reason": "row 8441: emulator mismatch on (2147483648, 2147483647, 1431655765), 4260880241 != 3579139389"
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"row": 8453,
|
| 102 |
+
"reason": "row 8453: emulator mismatch on (0, 0, 0), 0 != 4294967294"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"row": 8493,
|
| 106 |
+
"reason": "row 8493: emulator mismatch on (1, 1, 1), 0 != 16"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"row": 8573,
|
| 110 |
+
"reason": "not a complete supported straight-line function"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"row": 8603,
|
| 114 |
+
"reason": "row 8603: emulator mismatch on (0, 0, 0), 4294966738 != 4294962244"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"row": 8699,
|
| 118 |
+
"reason": "row 8699: emulator mismatch on (1, 1, 1), 0 != 41"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"row": 8742,
|
| 122 |
+
"reason": "row 8742: emulator mismatch on (4294967295, 4294967295, 4294967295), 4294967255 != 4294967287"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"row": 8767,
|
| 126 |
+
"reason": "row 8767: emulator mismatch on (4294967295, 4294967295, 4294967295), 21 != 23"
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"row": 8817,
|
| 130 |
+
"reason": "row 8817: emulator mismatch on (0, 4294967295, 1), 36 != 37"
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"row": 8863,
|
| 134 |
+
"reason": "row 8863: emulator mismatch on (1, 1, 1), 4 != 1604"
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"row": 8890,
|
| 138 |
+
"reason": "row 8890: emulator mismatch on (4294967295, 0, 1), 4294967244 != 44"
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"row": 8908,
|
| 142 |
+
"reason": "row 8908: emulator mismatch on (0, 4294967295, 1), 2154 != 2108"
|
| 143 |
+
}
|
| 144 |
+
]
|
| 145 |
+
},
|
| 146 |
+
"backend_provenance": {
|
| 147 |
+
"unfolded": "e6722114c92eac9f1a4c9d83816bf31ff14f0bcd7aa062ae49165144f4811c9f",
|
| 148 |
+
"post": "c91050116bb488ef934bbbce4eccf54230efbc35d2e000d7085da86c602b83ef",
|
| 149 |
+
"instructions": "aa4085b054722f3372d133ee607e359f6008cf4214a4bac8560bd8335d1792ed",
|
| 150 |
+
"binary": "d3b2dca8f3aec7621d1d46291d0762d99bc22fcf42371ff4da2d8dd38c28a511",
|
| 151 |
+
"templates": "9cea97b4be362f0e0f46084612bd5af961abaab0feabbc6eaae3debeb4e6cc5f",
|
| 152 |
+
"raw_post": "1a77192f19ebf79502b4b63303bc694586a78203aea58a45d0a321615f411915"
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
"split": "validation",
|
| 156 |
+
"evaluation_status": "validation",
|
| 157 |
+
"neural": {
|
| 158 |
+
"functions": 1000,
|
| 159 |
+
"batch": 32,
|
| 160 |
+
"repeats": 3,
|
| 161 |
+
"seconds": [
|
| 162 |
+
1.5238853000337258,
|
| 163 |
+
1.5837862000335008,
|
| 164 |
+
1.5430534000042826
|
| 165 |
+
],
|
| 166 |
+
"median_seconds": 1.5430534000042826,
|
| 167 |
+
"candidates_per_second": 648.0657117875666,
|
| 168 |
+
"peak_cuda_allocated_mib": 562.59033203125,
|
| 169 |
+
"sampled_correct_candidates_per_second": 633.1602004164525
|
| 170 |
+
},
|
| 171 |
+
"verification": {
|
| 172 |
+
"functions": 1000,
|
| 173 |
+
"serializable": 1.0,
|
| 174 |
+
"fully_disassembled": 0.999,
|
| 175 |
+
"semantic_accuracy": 0.977,
|
| 176 |
+
"semantic_correct": 977
|
| 177 |
+
},
|
| 178 |
+
"cpu": "Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz",
|
| 179 |
+
"gpu": "NVIDIA GeForce RTX 2060 SUPER",
|
| 180 |
+
"verification_in_timing": false,
|
| 181 |
+
"timing_scope": "Warm model; tokenization, neural inference, CPU transfer, byte serialization; excludes initialization, emulation and disk I/O",
|
| 182 |
+
"environment": {
|
| 183 |
+
"python": "3.14.0",
|
| 184 |
+
"torch": "2.13.0+cu132"
|
| 185 |
+
}
|
| 186 |
+
}
|
evaluation/fresh_test.json
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"pipeline": {
|
| 3 |
+
"compiler_version": "v2",
|
| 4 |
+
"abi": "x86_64 SysV",
|
| 5 |
+
"spec": {
|
| 6 |
+
"backbone": "Qwen/Qwen2.5-Coder-0.5B",
|
| 7 |
+
"revision": "0576a1bc0ae53f21860e905e081807bd7ff4a4c7",
|
| 8 |
+
"tokens": 96,
|
| 9 |
+
"depths": [
|
| 10 |
+
6
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
"fingerprint": "b8dd5570bd628cdad71bcb8bbffc76de11cd46f7b5d3be0cc4e3ad0bb2997e31",
|
| 14 |
+
"device": "cuda",
|
| 15 |
+
"checkpoints": {
|
| 16 |
+
"ast": {
|
| 17 |
+
"sha256": "e753e8ab8e997ebe48e166e6b0f2380bb3ab450c087871c4d740eef2326897e3",
|
| 18 |
+
"mode": "deps",
|
| 19 |
+
"epoch": 12
|
| 20 |
+
},
|
| 21 |
+
"ir": {
|
| 22 |
+
"sha256": "90bea9167a71409202397e2543c5c8beecd5a4a2d1169b268337db0175536244",
|
| 23 |
+
"mode": "deps",
|
| 24 |
+
"epoch": 15
|
| 25 |
+
},
|
| 26 |
+
"isel": {
|
| 27 |
+
"sha256": "d95f10f3bca327e65cb3c1e716d1b85d3db1addea2f144b40709809c27c9ff61",
|
| 28 |
+
"mode": "discrete_copy",
|
| 29 |
+
"epoch": 37
|
| 30 |
+
},
|
| 31 |
+
"regalloc": {
|
| 32 |
+
"sha256": "48f77152cff7532ebff835b4d0b15d603504de20f34378ab29634a4c3e83e582",
|
| 33 |
+
"mode": "aligned_copy",
|
| 34 |
+
"epoch": 171
|
| 35 |
+
},
|
| 36 |
+
"binary": {
|
| 37 |
+
"sha256": "3159a286d3b021fb62fec303648545c4abb9a8ad44a27246e02f75420bc58c4b",
|
| 38 |
+
"mode": "copy",
|
| 39 |
+
"epoch": 43
|
| 40 |
+
}
|
| 41 |
+
},
|
| 42 |
+
"precision": "Qwen cache precision; FP16 boundaries, FP32 specialized stages",
|
| 43 |
+
"specialized_parameters": 3934092,
|
| 44 |
+
"backbone_parameters": 225608960,
|
| 45 |
+
"binary_validation": {
|
| 46 |
+
"n": 1000,
|
| 47 |
+
"exact": 0.9739999771118164,
|
| 48 |
+
"byte_accuracy": 0.976840078830719,
|
| 49 |
+
"count_accuracy": 0.9900000095367432,
|
| 50 |
+
"template_accuracy": 0.9810349345207214,
|
| 51 |
+
"template_exact": 0.9779999852180481,
|
| 52 |
+
"payload_byte_accuracy_given_template": 0.9982773661613464,
|
| 53 |
+
"immediate_byte_accuracy_given_template": 0.9982691407203674,
|
| 54 |
+
"displacement_byte_accuracy_given_template": 1.0,
|
| 55 |
+
"spill_exact": 0.1538461595773697,
|
| 56 |
+
"spill_n": 13,
|
| 57 |
+
"nonspill_exact": 0.9848024249076843,
|
| 58 |
+
"semantic32": 0.977,
|
| 59 |
+
"semantic_accuracy": 0.977,
|
| 60 |
+
"semantic_n": 1000,
|
| 61 |
+
"inputs_per_function": 32,
|
| 62 |
+
"fully_disassembled": 0.999,
|
| 63 |
+
"semantic_failure_examples": [
|
| 64 |
+
{
|
| 65 |
+
"row": 8139,
|
| 66 |
+
"reason": "row 8139: emulator mismatch on (0, 0, 0), 13 != 122"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"row": 8143,
|
| 70 |
+
"reason": "row 8143: emulator mismatch on (0, 0, 0), 0 != 7"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"row": 8202,
|
| 74 |
+
"reason": "row 8202: emulator mismatch on (1, 1, 1), 1 != 15"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"row": 8225,
|
| 78 |
+
"reason": "row 8225: emulator mismatch on (1, 1, 1), 57 != 58"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"row": 8232,
|
| 82 |
+
"reason": "row 8232: emulator mismatch on (0, 4294967295, 1), 0 != 150"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"row": 8234,
|
| 86 |
+
"reason": "row 8234: emulator mismatch on (0, 0, 0), 1206 != 582"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"row": 8297,
|
| 90 |
+
"reason": "row 8297: emulator mismatch on (1, 1, 1), 100 != 105"
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"row": 8380,
|
| 94 |
+
"reason": "row 8380: emulator mismatch on (0, 4294967295, 1), 4294967294 != 4294967295"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"row": 8441,
|
| 98 |
+
"reason": "row 8441: emulator mismatch on (2147483648, 2147483647, 1431655765), 4260880241 != 3579139389"
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"row": 8453,
|
| 102 |
+
"reason": "row 8453: emulator mismatch on (0, 0, 0), 0 != 4294967294"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"row": 8493,
|
| 106 |
+
"reason": "row 8493: emulator mismatch on (1, 1, 1), 0 != 16"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"row": 8573,
|
| 110 |
+
"reason": "not a complete supported straight-line function"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"row": 8603,
|
| 114 |
+
"reason": "row 8603: emulator mismatch on (0, 0, 0), 4294966738 != 4294962244"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"row": 8699,
|
| 118 |
+
"reason": "row 8699: emulator mismatch on (1, 1, 1), 0 != 41"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"row": 8742,
|
| 122 |
+
"reason": "row 8742: emulator mismatch on (4294967295, 4294967295, 4294967295), 4294967255 != 4294967287"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"row": 8767,
|
| 126 |
+
"reason": "row 8767: emulator mismatch on (4294967295, 4294967295, 4294967295), 21 != 23"
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"row": 8817,
|
| 130 |
+
"reason": "row 8817: emulator mismatch on (0, 4294967295, 1), 36 != 37"
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"row": 8863,
|
| 134 |
+
"reason": "row 8863: emulator mismatch on (1, 1, 1), 4 != 1604"
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"row": 8890,
|
| 138 |
+
"reason": "row 8890: emulator mismatch on (4294967295, 0, 1), 4294967244 != 44"
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"row": 8908,
|
| 142 |
+
"reason": "row 8908: emulator mismatch on (0, 4294967295, 1), 2154 != 2108"
|
| 143 |
+
}
|
| 144 |
+
]
|
| 145 |
+
},
|
| 146 |
+
"backend_provenance": {
|
| 147 |
+
"unfolded": "e6722114c92eac9f1a4c9d83816bf31ff14f0bcd7aa062ae49165144f4811c9f",
|
| 148 |
+
"post": "c91050116bb488ef934bbbce4eccf54230efbc35d2e000d7085da86c602b83ef",
|
| 149 |
+
"instructions": "aa4085b054722f3372d133ee607e359f6008cf4214a4bac8560bd8335d1792ed",
|
| 150 |
+
"binary": "d3b2dca8f3aec7621d1d46291d0762d99bc22fcf42371ff4da2d8dd38c28a511",
|
| 151 |
+
"templates": "9cea97b4be362f0e0f46084612bd5af961abaab0feabbc6eaae3debeb4e6cc5f",
|
| 152 |
+
"raw_post": "1a77192f19ebf79502b4b63303bc694586a78203aea58a45d0a321615f411915"
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
"split": "fresh",
|
| 156 |
+
"evaluation_status": "fresh source-disjoint test; do not tune on these results",
|
| 157 |
+
"fresh_seed": 20261126,
|
| 158 |
+
"fresh_count_requested": 1000,
|
| 159 |
+
"source_sha256": "c00d7cd373f7e9ce39ca1bed86005698de38e7b165fb8da845bf6448b8050eaa",
|
| 160 |
+
"depth_counts": {
|
| 161 |
+
"1": 105,
|
| 162 |
+
"2": 433,
|
| 163 |
+
"3": 462
|
| 164 |
+
},
|
| 165 |
+
"samples": 32,
|
| 166 |
+
"sample_seed": 20261125,
|
| 167 |
+
"functions": 1000,
|
| 168 |
+
"serializable": 1.0,
|
| 169 |
+
"fully_disassembled": 0.998,
|
| 170 |
+
"semantic_accuracy": 0.973,
|
| 171 |
+
"semantic_correct": 973,
|
| 172 |
+
"failure_examples": [
|
| 173 |
+
{
|
| 174 |
+
"row": 10066,
|
| 175 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((19u-b)-(c^b))^((50u-b)&(c+b)));}",
|
| 176 |
+
"hex": "b8 13 00 00 00 29 f0 89 d1 31 f1 29 c8 b9 32 00 00 00 29 f1 01 f2 31 d1 31 c8 c3",
|
| 177 |
+
"disassembled": true,
|
| 178 |
+
"semantic": false,
|
| 179 |
+
"error": "row 10066: emulator mismatch on (0, 0, 0), 33 != 19"
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"row": 10102,
|
| 183 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return ((13u-c)&(61u+c));}",
|
| 184 |
+
"hex": "b8 0d 00 00 00 29 d0 83 c2 3d 01 d0 c3",
|
| 185 |
+
"disassembled": true,
|
| 186 |
+
"semantic": false,
|
| 187 |
+
"error": "row 10102: emulator mismatch on (0, 0, 0), 74 != 13"
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"row": 10106,
|
| 191 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a*30u)*(c*b))|((b+c)*(a^57u)));}",
|
| 192 |
+
"hex": "89 f1 6b c7 1e 89 d6 0f af f1 0f af c6 01 d1 0f af ff 0f af cf 09 c8 c3",
|
| 193 |
+
"disassembled": true,
|
| 194 |
+
"semantic": false,
|
| 195 |
+
"error": "row 10106: emulator mismatch on (1, 1, 1), 30 != 126"
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
"row": 10138,
|
| 199 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return ((c^45u)+(b*1u));}",
|
| 200 |
+
"hex": "89 d0 83 f0 2d d1 e6 01 f0 c3",
|
| 201 |
+
"disassembled": true,
|
| 202 |
+
"semantic": false,
|
| 203 |
+
"error": "row 10138: emulator mismatch on (1, 1, 1), 46 != 45"
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"row": 10180,
|
| 207 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((48u*a)-(23u*61u))&((c&c)&(b*2u)));}",
|
| 208 |
+
"hex": "89 d1 6b c7 30 ba 3d 00 00 00 29 ca 29 d0 21 c9 d1 e6 21 f1 21 c8 c3",
|
| 209 |
+
"disassembled": true,
|
| 210 |
+
"semantic": false,
|
| 211 |
+
"error": "row 10180: emulator mismatch on (4294967295, 4294967295, 4294967295), 4294967186 != 4294965844"
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"row": 10196,
|
| 215 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((51u^c)*(c-a))&((52u&26u)^(7u&20u)));}",
|
| 216 |
+
"hex": "89 d0 83 f0 33 29 fa 0f af c2 b9 1a 00 00 00 83 e1 34 ba 14 00 00 00 83 e2 07 31 d1 21 c8 21 c8",
|
| 217 |
+
"disassembled": false,
|
| 218 |
+
"semantic": false,
|
| 219 |
+
"error": "Not a supported complete straight-line function"
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"row": 10246,
|
| 223 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((b+59u)&(b*34u))|((b*16u)&(14u-a)));}",
|
| 224 |
+
"hex": "89 f1 89 c8 83 c0 3b 6b f1 22 21 d0 c1 e1 05 ba 0e 00 00 00 29 fa 21 d1 09 c8 c3",
|
| 225 |
+
"disassembled": true,
|
| 226 |
+
"semantic": false,
|
| 227 |
+
"error": "row 10246: emulator mismatch on (1, 1, 1), 0 != 32"
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
"row": 10291,
|
| 231 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((37u+2u)+(21u-9u))|((45u^c)^(c+b)));}",
|
| 232 |
+
"hex": "b8 02 00 00 00 83 c0 25 b9 15 00 00 00 83 e9 09 31 c8 89 d1 83 f1 2d 01 f2 31 d1 09 c8 c3",
|
| 233 |
+
"disassembled": true,
|
| 234 |
+
"semantic": false,
|
| 235 |
+
"error": "row 10291: emulator mismatch on (0, 0, 0), 47 != 63"
|
| 236 |
+
},
|
| 237 |
+
{
|
| 238 |
+
"row": 10308,
|
| 239 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c+c)&(c|45u))*((30u*24u)*(10u-a)));}",
|
| 240 |
+
"hex": "89 d0 01 c0 83 ca 2d 21 d0 21 c8 6b c9 1e ba 0a 00 00 00 29 fa 0f af ca 0f af c1 c3",
|
| 241 |
+
"disassembled": true,
|
| 242 |
+
"semantic": false,
|
| 243 |
+
"error": "row 10308: emulator mismatch on (4294967295, 4294967295, 4294967295), 0 != 4294951456"
|
| 244 |
+
},
|
| 245 |
+
{
|
| 246 |
+
"row": 10314,
|
| 247 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a|a)|(b^60u))|((39u|48u)+(a^b)));}",
|
| 248 |
+
"hex": "89 f8 09 c0 89 f1 83 f1 3c 09 c8 89 f1 83 c9 27 31 f7 01 f9 09 c8 c3",
|
| 249 |
+
"disassembled": true,
|
| 250 |
+
"semantic": false,
|
| 251 |
+
"error": "row 10314: emulator mismatch on (0, 4294967295, 1), 4294967295 != 4294967287"
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"row": 10318,
|
| 255 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((54u&a)+(37u^22u))&((b^31u)|(a&b)));}",
|
| 256 |
+
"hex": "89 f8 83 e0 36 b9 15 00 00 00 83 f1 25 01 c8 89 f1 83 f1 1f 21 f7 09 f9 21 c8 c3",
|
| 257 |
+
"disassembled": true,
|
| 258 |
+
"semantic": false,
|
| 259 |
+
"error": "row 10318: emulator mismatch on (0, 0, 0), 16 != 19"
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"row": 10323,
|
| 263 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c|c)^(c-b))-((a*c)^(c^7u)));}",
|
| 264 |
+
"hex": "89 f9 89 d0 09 c0 89 d6 29 f6 31 f0 0f af ca 83 f2 07 31 d1 29 c8 c3",
|
| 265 |
+
"disassembled": true,
|
| 266 |
+
"semantic": false,
|
| 267 |
+
"error": "row 10323: emulator mismatch on (0, 4294967295, 1), 4294967291 != 4294967293"
|
| 268 |
+
},
|
| 269 |
+
{
|
| 270 |
+
"row": 10362,
|
| 271 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((7u*b)-(b&c))-((c-b)^(41u+a)));}",
|
| 272 |
+
"hex": "89 d1 6b c6 07 89 f2 21 d2 29 d0 29 f1 83 c7 29 31 f9 29 c8 c3",
|
| 273 |
+
"disassembled": true,
|
| 274 |
+
"semantic": false,
|
| 275 |
+
"error": "row 10362: emulator mismatch on (0, 4294967295, 1), 4294967247 != 4294967245"
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"row": 10427,
|
| 279 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a*30u)&(c*a))&((a*44u)+(a+a)));}",
|
| 280 |
+
"hex": "6b c7 1e 0f af d7 0f af c7 89 f9 6b cf 2c 01 ff 01 f9 21 c8 c3",
|
| 281 |
+
"disassembled": true,
|
| 282 |
+
"semantic": false,
|
| 283 |
+
"error": "row 10427: emulator mismatch on (1, 1, 1), 14 != 0"
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"row": 10449,
|
| 287 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((19u*b)^(42u*a))*((61u+a)|(c^c)));}",
|
| 288 |
+
"hex": "89 f9 6b c6 2a 6b f1 2a 31 f7 83 c1 3d 31 d2 09 d1 0f af c1 c3",
|
| 289 |
+
"disassembled": true,
|
| 290 |
+
"semantic": false,
|
| 291 |
+
"error": "row 10449: emulator mismatch on (1, 1, 1), 2604 != 3534"
|
| 292 |
+
},
|
| 293 |
+
{
|
| 294 |
+
"row": 10534,
|
| 295 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((29u^58u)-(a&44u))*((b-46u)*(c+39u)));}",
|
| 296 |
+
"hex": "89 f1 b8 3a 00 00 00 83 f0 1d 83 e7 2c 29 f8 83 e9 2e 83 c2 27 01 d1 0f af c1 c3",
|
| 297 |
+
"disassembled": true,
|
| 298 |
+
"semantic": false,
|
| 299 |
+
"error": "row 10534: emulator mismatch on (0, 0, 0), 4294967023 != 4294897330"
|
| 300 |
+
},
|
| 301 |
+
{
|
| 302 |
+
"row": 10558,
|
| 303 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return ((1u|40u)*(30u+a));}",
|
| 304 |
+
"hex": "b8 28 00 00 00 83 c8 01 83 c7 1e 01 f8 c3",
|
| 305 |
+
"disassembled": true,
|
| 306 |
+
"semantic": false,
|
| 307 |
+
"error": "row 10558: emulator mismatch on (0, 0, 0), 71 != 1230"
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"row": 10613,
|
| 311 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((38u^59u)+(11u+19u))|((b|c)*(b*c)));}",
|
| 312 |
+
"hex": "b8 3b 00 00 00 83 f0 26 89 d1 83 c1 0b 01 c8 89 f1 09 d1 0f af f2 0f af ce 09 c8 c3",
|
| 313 |
+
"disassembled": true,
|
| 314 |
+
"semantic": false,
|
| 315 |
+
"error": "row 10613: emulator mismatch on (0, 0, 0), 40 != 59"
|
| 316 |
+
},
|
| 317 |
+
{
|
| 318 |
+
"row": 10662,
|
| 319 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c&c)|(22u|a))*((16u|60u)^(b&c)));}",
|
| 320 |
+
"hex": "89 d0 21 c0 83 cf 16 09 f8 89 d1 83 c9 10 21 d6 31 f1 0f af c1 c3",
|
| 321 |
+
"disassembled": true,
|
| 322 |
+
"semantic": false,
|
| 323 |
+
"error": "row 10662: emulator mismatch on (0, 0, 0), 352 != 1320"
|
| 324 |
+
},
|
| 325 |
+
{
|
| 326 |
+
"row": 10692,
|
| 327 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((50u+34u)*(b*a))&((5u-b)+(39u&42u)));}",
|
| 328 |
+
"hex": "b8 22 00 00 00 83 c0 32 89 f1 0f af cf 0f af c1 b9 05 00 00 00 29 f1 ba 2a 00 00 00 83 e2 27 21 d1 21 c8 c3",
|
| 329 |
+
"disassembled": true,
|
| 330 |
+
"semantic": false,
|
| 331 |
+
"error": "row 10692: emulator mismatch on (1, 1, 1), 0 != 4"
|
| 332 |
+
}
|
| 333 |
+
]
|
| 334 |
+
}
|
evaluation/portability.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cuda": {
|
| 3 |
+
"initialization_seconds": 4.585737199988216,
|
| 4 |
+
"hex": "89 f8 01 f0 83 ea 07 0f af c2 c3",
|
| 5 |
+
"verification": {
|
| 6 |
+
"row": 0,
|
| 7 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return ((a+b)*(c-7u));}",
|
| 8 |
+
"hex": "89 f8 01 f0 83 ea 07 0f af c2 c3",
|
| 9 |
+
"disassembled": true,
|
| 10 |
+
"semantic": true,
|
| 11 |
+
"error": null
|
| 12 |
+
},
|
| 13 |
+
"batch_and_intermediate_api": true
|
| 14 |
+
},
|
| 15 |
+
"cpu": {
|
| 16 |
+
"initialization_seconds": 1.0340769999893382,
|
| 17 |
+
"hex": "89 f8 01 f0 83 ea 07 0f af c2 c3",
|
| 18 |
+
"verification": {
|
| 19 |
+
"row": 0,
|
| 20 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return ((a+b)*(c-7u));}",
|
| 21 |
+
"hex": "89 f8 01 f0 83 ea 07 0f af c2 c3",
|
| 22 |
+
"disassembled": true,
|
| 23 |
+
"semantic": true,
|
| 24 |
+
"error": null
|
| 25 |
+
},
|
| 26 |
+
"batch_and_intermediate_api": true
|
| 27 |
+
},
|
| 28 |
+
"development_artifacts_denied": true,
|
| 29 |
+
"environment": "Separate venv with system-site-packages; installed wheel; outside development working directory"
|
| 30 |
+
}
|
evaluation/preparation.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"original_cache_sha256": "728eb7de1b4cd5e32a7dec37ed199b3ba53f1a2051192719715711347cd375ae",
|
| 3 |
+
"original_checkpoint_sha256": "cf980b3520e0a83522d4f5557bffaf937a84c200ec3e9b7e7b809deed17bd125",
|
| 4 |
+
"current_checkpoint_sha256": "48f77152cff7532ebff835b4d0b15d603504de20f34378ab29634a4c3e83e582",
|
| 5 |
+
"current_epoch": 171,
|
| 6 |
+
"current_validation": {
|
| 7 |
+
"exact": 0.9729999899864197,
|
| 8 |
+
"signature_accuracy": 0.9837442636489868,
|
| 9 |
+
"register_accuracy": 0.98609459400177,
|
| 10 |
+
"immediate_accuracy": 0.9680156707763672,
|
| 11 |
+
"stack_accuracy": 1.0,
|
| 12 |
+
"constant_repair": 0.9769999980926514,
|
| 13 |
+
"register_repair": 0.9789999723434448,
|
| 14 |
+
"spill_exact": 0.1538461595773697,
|
| 15 |
+
"spill_n": 13,
|
| 16 |
+
"nonspill_exact": 0.9837892651557922,
|
| 17 |
+
"n": 1000,
|
| 18 |
+
"epoch": 171,
|
| 19 |
+
"loss": 0.026706223241286353,
|
| 20 |
+
"seconds": 5.911403000005521
|
| 21 |
+
},
|
| 22 |
+
"differences": {
|
| 23 |
+
"features": 17254761,
|
| 24 |
+
"predictions": [
|
| 25 |
+
66,
|
| 26 |
+
163,
|
| 27 |
+
21,
|
| 28 |
+
0
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
"equivalent": false,
|
| 32 |
+
"regenerated_cache_sha256": "9d4784815ded74937a321504d71f956fa8d5f430c823e019d39d46d8bfcd83ae",
|
| 33 |
+
"historical_binary_checkpoint_sha256": "479036e37e256c825d2496e962a9b477a97735a0691cf700dd3a12dd84e9a800",
|
| 34 |
+
"history_epochs": 185,
|
| 35 |
+
"historical_epoch165_metrics": {
|
| 36 |
+
"exact": 0.9700000286102295,
|
| 37 |
+
"signature_accuracy": 0.9837442636489868,
|
| 38 |
+
"register_accuracy": 0.9863322973251343,
|
| 39 |
+
"immediate_accuracy": 0.9686684012413025,
|
| 40 |
+
"stack_accuracy": 1.0,
|
| 41 |
+
"constant_repair": 0.9729999899864197,
|
| 42 |
+
"register_repair": 0.9769999980926514,
|
| 43 |
+
"spill_exact": 0.07692307978868484,
|
| 44 |
+
"spill_n": 13,
|
| 45 |
+
"nonspill_exact": 0.9817629456520081,
|
| 46 |
+
"n": 1000,
|
| 47 |
+
"epoch": 165,
|
| 48 |
+
"loss": 0.028876638630405068,
|
| 49 |
+
"seconds": 5.8465824000304565
|
| 50 |
+
},
|
| 51 |
+
"history_last_epoch": 185
|
| 52 |
+
}
|
evaluation/regression.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"functions": 1000,
|
| 3 |
+
"equal": {
|
| 4 |
+
"ast_features": true,
|
| 5 |
+
"ssa_features": true,
|
| 6 |
+
"ssa_predictions": true,
|
| 7 |
+
"virtual_features": true,
|
| 8 |
+
"virtual_mir": true,
|
| 9 |
+
"physical_features": true,
|
| 10 |
+
"physical_mir": true,
|
| 11 |
+
"ast_predictions": true,
|
| 12 |
+
"binary_predictions": true,
|
| 13 |
+
"machine_code": true
|
| 14 |
+
},
|
| 15 |
+
"verification_equal": true,
|
| 16 |
+
"historical_binary_rows_equal": 976,
|
| 17 |
+
"original_initialization_seconds": 4.489245200064033,
|
| 18 |
+
"package_initialization_seconds": 1.2063965999986976,
|
| 19 |
+
"verification": {
|
| 20 |
+
"functions": 1000,
|
| 21 |
+
"serializable": 1.0,
|
| 22 |
+
"fully_disassembled": 0.999,
|
| 23 |
+
"semantic_accuracy": 0.977,
|
| 24 |
+
"semantic_correct": 977
|
| 25 |
+
},
|
| 26 |
+
"device": "NVIDIA GeForce RTX 2060 SUPER",
|
| 27 |
+
"torch": "2.13.0+cu132"
|
| 28 |
+
}
|
evaluation/validation.json
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"pipeline": {
|
| 3 |
+
"compiler_version": "v2",
|
| 4 |
+
"abi": "x86_64 SysV",
|
| 5 |
+
"spec": {
|
| 6 |
+
"backbone": "Qwen/Qwen2.5-Coder-0.5B",
|
| 7 |
+
"revision": "0576a1bc0ae53f21860e905e081807bd7ff4a4c7",
|
| 8 |
+
"tokens": 96,
|
| 9 |
+
"depths": [
|
| 10 |
+
6
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
"fingerprint": "b8dd5570bd628cdad71bcb8bbffc76de11cd46f7b5d3be0cc4e3ad0bb2997e31",
|
| 14 |
+
"device": "cuda",
|
| 15 |
+
"checkpoints": {
|
| 16 |
+
"ast": {
|
| 17 |
+
"sha256": "e753e8ab8e997ebe48e166e6b0f2380bb3ab450c087871c4d740eef2326897e3",
|
| 18 |
+
"mode": "deps",
|
| 19 |
+
"epoch": 12
|
| 20 |
+
},
|
| 21 |
+
"ir": {
|
| 22 |
+
"sha256": "90bea9167a71409202397e2543c5c8beecd5a4a2d1169b268337db0175536244",
|
| 23 |
+
"mode": "deps",
|
| 24 |
+
"epoch": 15
|
| 25 |
+
},
|
| 26 |
+
"isel": {
|
| 27 |
+
"sha256": "d95f10f3bca327e65cb3c1e716d1b85d3db1addea2f144b40709809c27c9ff61",
|
| 28 |
+
"mode": "discrete_copy",
|
| 29 |
+
"epoch": 37
|
| 30 |
+
},
|
| 31 |
+
"regalloc": {
|
| 32 |
+
"sha256": "48f77152cff7532ebff835b4d0b15d603504de20f34378ab29634a4c3e83e582",
|
| 33 |
+
"mode": "aligned_copy",
|
| 34 |
+
"epoch": 171
|
| 35 |
+
},
|
| 36 |
+
"binary": {
|
| 37 |
+
"sha256": "3159a286d3b021fb62fec303648545c4abb9a8ad44a27246e02f75420bc58c4b",
|
| 38 |
+
"mode": "copy",
|
| 39 |
+
"epoch": 43
|
| 40 |
+
}
|
| 41 |
+
},
|
| 42 |
+
"precision": "Qwen cache precision; FP16 boundaries, FP32 specialized stages",
|
| 43 |
+
"specialized_parameters": 3934092,
|
| 44 |
+
"backbone_parameters": 225608960,
|
| 45 |
+
"binary_validation": {
|
| 46 |
+
"n": 1000,
|
| 47 |
+
"exact": 0.9739999771118164,
|
| 48 |
+
"byte_accuracy": 0.976840078830719,
|
| 49 |
+
"count_accuracy": 0.9900000095367432,
|
| 50 |
+
"template_accuracy": 0.9810349345207214,
|
| 51 |
+
"template_exact": 0.9779999852180481,
|
| 52 |
+
"payload_byte_accuracy_given_template": 0.9982773661613464,
|
| 53 |
+
"immediate_byte_accuracy_given_template": 0.9982691407203674,
|
| 54 |
+
"displacement_byte_accuracy_given_template": 1.0,
|
| 55 |
+
"spill_exact": 0.1538461595773697,
|
| 56 |
+
"spill_n": 13,
|
| 57 |
+
"nonspill_exact": 0.9848024249076843,
|
| 58 |
+
"semantic32": 0.977,
|
| 59 |
+
"semantic_accuracy": 0.977,
|
| 60 |
+
"semantic_n": 1000,
|
| 61 |
+
"inputs_per_function": 32,
|
| 62 |
+
"fully_disassembled": 0.999,
|
| 63 |
+
"semantic_failure_examples": [
|
| 64 |
+
{
|
| 65 |
+
"row": 8139,
|
| 66 |
+
"reason": "row 8139: emulator mismatch on (0, 0, 0), 13 != 122"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"row": 8143,
|
| 70 |
+
"reason": "row 8143: emulator mismatch on (0, 0, 0), 0 != 7"
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"row": 8202,
|
| 74 |
+
"reason": "row 8202: emulator mismatch on (1, 1, 1), 1 != 15"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"row": 8225,
|
| 78 |
+
"reason": "row 8225: emulator mismatch on (1, 1, 1), 57 != 58"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"row": 8232,
|
| 82 |
+
"reason": "row 8232: emulator mismatch on (0, 4294967295, 1), 0 != 150"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"row": 8234,
|
| 86 |
+
"reason": "row 8234: emulator mismatch on (0, 0, 0), 1206 != 582"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"row": 8297,
|
| 90 |
+
"reason": "row 8297: emulator mismatch on (1, 1, 1), 100 != 105"
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"row": 8380,
|
| 94 |
+
"reason": "row 8380: emulator mismatch on (0, 4294967295, 1), 4294967294 != 4294967295"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"row": 8441,
|
| 98 |
+
"reason": "row 8441: emulator mismatch on (2147483648, 2147483647, 1431655765), 4260880241 != 3579139389"
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"row": 8453,
|
| 102 |
+
"reason": "row 8453: emulator mismatch on (0, 0, 0), 0 != 4294967294"
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"row": 8493,
|
| 106 |
+
"reason": "row 8493: emulator mismatch on (1, 1, 1), 0 != 16"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"row": 8573,
|
| 110 |
+
"reason": "not a complete supported straight-line function"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"row": 8603,
|
| 114 |
+
"reason": "row 8603: emulator mismatch on (0, 0, 0), 4294966738 != 4294962244"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"row": 8699,
|
| 118 |
+
"reason": "row 8699: emulator mismatch on (1, 1, 1), 0 != 41"
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
"row": 8742,
|
| 122 |
+
"reason": "row 8742: emulator mismatch on (4294967295, 4294967295, 4294967295), 4294967255 != 4294967287"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"row": 8767,
|
| 126 |
+
"reason": "row 8767: emulator mismatch on (4294967295, 4294967295, 4294967295), 21 != 23"
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"row": 8817,
|
| 130 |
+
"reason": "row 8817: emulator mismatch on (0, 4294967295, 1), 36 != 37"
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"row": 8863,
|
| 134 |
+
"reason": "row 8863: emulator mismatch on (1, 1, 1), 4 != 1604"
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"row": 8890,
|
| 138 |
+
"reason": "row 8890: emulator mismatch on (4294967295, 0, 1), 4294967244 != 44"
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"row": 8908,
|
| 142 |
+
"reason": "row 8908: emulator mismatch on (0, 4294967295, 1), 2154 != 2108"
|
| 143 |
+
}
|
| 144 |
+
]
|
| 145 |
+
},
|
| 146 |
+
"backend_provenance": {
|
| 147 |
+
"unfolded": "e6722114c92eac9f1a4c9d83816bf31ff14f0bcd7aa062ae49165144f4811c9f",
|
| 148 |
+
"post": "c91050116bb488ef934bbbce4eccf54230efbc35d2e000d7085da86c602b83ef",
|
| 149 |
+
"instructions": "aa4085b054722f3372d133ee607e359f6008cf4214a4bac8560bd8335d1792ed",
|
| 150 |
+
"binary": "d3b2dca8f3aec7621d1d46291d0762d99bc22fcf42371ff4da2d8dd38c28a511",
|
| 151 |
+
"templates": "9cea97b4be362f0e0f46084612bd5af961abaab0feabbc6eaae3debeb4e6cc5f",
|
| 152 |
+
"raw_post": "1a77192f19ebf79502b4b63303bc694586a78203aea58a45d0a321615f411915"
|
| 153 |
+
}
|
| 154 |
+
},
|
| 155 |
+
"split": "validation",
|
| 156 |
+
"evaluation_status": "validation",
|
| 157 |
+
"samples": 32,
|
| 158 |
+
"sample_seed": 20261125,
|
| 159 |
+
"functions": 1000,
|
| 160 |
+
"serializable": 1.0,
|
| 161 |
+
"fully_disassembled": 0.999,
|
| 162 |
+
"semantic_accuracy": 0.977,
|
| 163 |
+
"semantic_correct": 977,
|
| 164 |
+
"exact_unoptimized_backend": 0.974,
|
| 165 |
+
"cached_vs_live_exact": 1.0,
|
| 166 |
+
"exact_original_optimized_bytes_diagnostic": 0.082,
|
| 167 |
+
"failure_examples": [
|
| 168 |
+
{
|
| 169 |
+
"row": 8139,
|
| 170 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((b|a)^(45u|56u))^((12u+59u)-(a&36u)));}",
|
| 171 |
+
"hex": "89 f0 09 f8 b9 38 00 00 00 83 c9 2d 31 c8 b9 24 00 00 00 83 c1 0c 83 e7 24 29 f9 31 c8 c3",
|
| 172 |
+
"disassembled": true,
|
| 173 |
+
"semantic": false,
|
| 174 |
+
"error": "row 8139: emulator mismatch on (0, 0, 0), 13 != 122"
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"row": 8143,
|
| 178 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a^c)^(7u-c))|((30u+b)&(a|a)));}",
|
| 179 |
+
"hex": "89 f1 89 f8 31 d0 ba 07 00 00 00 29 d2 31 d0 83 c1 1e 09 ff 21 f9 09 c8 c3",
|
| 180 |
+
"disassembled": true,
|
| 181 |
+
"semantic": false,
|
| 182 |
+
"error": "row 8143: emulator mismatch on (0, 0, 0), 0 != 7"
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"row": 8202,
|
| 186 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c|a)&(b*c))^((a+a)*(b|7u)));}",
|
| 187 |
+
"hex": "89 54 24 fc 89 f9 09 c8 89 f0 09 c8 89 f2 01 fa 83 ce 07 01 f1 31 f6 0f af ce 31 c8 c3",
|
| 188 |
+
"disassembled": true,
|
| 189 |
+
"semantic": false,
|
| 190 |
+
"error": "row 8202: emulator mismatch on (1, 1, 1), 1 != 15"
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
"row": 8225,
|
| 194 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a*51u)-(b&a))|((55u*a)+(a*a)));}",
|
| 195 |
+
"hex": "6b c7 33 21 fe 21 f0 89 f9 6b cf 37 0f af ff 01 f9 09 c8 c3",
|
| 196 |
+
"disassembled": true,
|
| 197 |
+
"semantic": false,
|
| 198 |
+
"error": "row 8225: emulator mismatch on (1, 1, 1), 57 != 58"
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
"row": 8232,
|
| 202 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((50u*3u)*(a^c))|((b-b)|(52u*a)));}",
|
| 203 |
+
"hex": "89 f1 b8 03 00 00 00 6b c0 32 89 fa 31 d2 0f af c2 29 c9 6b d7 34 09 d1 09 c8 c3",
|
| 204 |
+
"disassembled": true,
|
| 205 |
+
"semantic": false,
|
| 206 |
+
"error": "row 8232: emulator mismatch on (0, 4294967295, 1), 0 != 150"
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"row": 8234,
|
| 210 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return ((16u*37u)^(b+22u));}",
|
| 211 |
+
"hex": "b8 25 00 00 00 c1 e0 05 83 c6 16 31 f0 c3",
|
| 212 |
+
"disassembled": true,
|
| 213 |
+
"semantic": false,
|
| 214 |
+
"error": "row 8234: emulator mismatch on (0, 0, 0), 1206 != 582"
|
| 215 |
+
},
|
| 216 |
+
{
|
| 217 |
+
"row": 8297,
|
| 218 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((52u|b)^(15u*b))+((a^c)+(16u^63u)));}",
|
| 219 |
+
"hex": "89 f9 89 f9 83 c8 34 6b f6 0f 31 f8 31 d1 ba 3f 00 00 00 83 f2 10 01 d1 01 c8 c3",
|
| 220 |
+
"disassembled": true,
|
| 221 |
+
"semantic": false,
|
| 222 |
+
"error": "row 8297: emulator mismatch on (1, 1, 1), 100 != 105"
|
| 223 |
+
},
|
| 224 |
+
{
|
| 225 |
+
"row": 8380,
|
| 226 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c-3u)|(a-c))-((b*a)*(a*47u)));}",
|
| 227 |
+
"hex": "89 d0 89 f1 83 e8 03 89 fa 29 d2 09 d0 0f af cf 6b d7 2f 0f af ca 29 c8 c3",
|
| 228 |
+
"disassembled": true,
|
| 229 |
+
"semantic": false,
|
| 230 |
+
"error": "row 8380: emulator mismatch on (0, 4294967295, 1), 4294967294 != 4294967295"
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
"row": 8441,
|
| 234 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c^36u)+(b*c))|((a|c)-(39u-b)));}",
|
| 235 |
+
"hex": "89 f9 89 d0 83 f0 24 89 f7 0f af d2 01 f8 09 d1 ba 27 00 00 00 29 f2 29 d1 09 c8 c3",
|
| 236 |
+
"disassembled": true,
|
| 237 |
+
"semantic": false,
|
| 238 |
+
"error": "row 8441: emulator mismatch on (2147483648, 2147483647, 1431655765), 4260880241 != 3579139389"
|
| 239 |
+
},
|
| 240 |
+
{
|
| 241 |
+
"row": 8453,
|
| 242 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c|a)-(2u-b))-((a^c)+(60u*c)));}",
|
| 243 |
+
"hex": "89 f9 89 d0 09 c8 be 02 00 00 00 29 f6 29 f0 31 d1 6b d2 3c 01 d1 29 c8 c3",
|
| 244 |
+
"disassembled": true,
|
| 245 |
+
"semantic": false,
|
| 246 |
+
"error": "row 8453: emulator mismatch on (0, 0, 0), 0 != 4294967294"
|
| 247 |
+
},
|
| 248 |
+
{
|
| 249 |
+
"row": 8493,
|
| 250 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c&55u)^(27u*a))&((49u^13u)-(9u-c)));}",
|
| 251 |
+
"hex": "89 54 24 fc 89 f1 8b 74 24 fc 6b c0 1b b9 0d 00 00 00 ba 09 00 00 00 ba 09 00 00 00 29 d2 29 d1 21 c8 c3",
|
| 252 |
+
"disassembled": true,
|
| 253 |
+
"semantic": false,
|
| 254 |
+
"error": "row 8493: emulator mismatch on (1, 1, 1), 0 != 16"
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
"row": 8573,
|
| 258 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a-a)-(42u*b))|((c&c)&(42u-c)));}",
|
| 259 |
+
"hex": "89 54 24 fc 89 f1 8b 74 24 fc 6b c1 2a 29 c0 29 c9 29 c8 29 f2 21 c9 ba 2a 00 00 00 29 f2 09 c8 c3 c3",
|
| 260 |
+
"disassembled": false,
|
| 261 |
+
"semantic": false,
|
| 262 |
+
"error": "Not a supported complete straight-line function"
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"row": 8603,
|
| 266 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a*b)-(10u*58u))^((61u+31u)*(50u-b)));}",
|
| 267 |
+
"hex": "89 f8 0f af c6 b9 3a 00 00 00 6b c9 0a 29 c8 b9 1f 00 00 00 83 c1 3d ba 32 00 00 00 29 f2 31 d1 31 c8 c3",
|
| 268 |
+
"disassembled": true,
|
| 269 |
+
"semantic": false,
|
| 270 |
+
"error": "row 8603: emulator mismatch on (0, 0, 0), 4294966738 != 4294962244"
|
| 271 |
+
},
|
| 272 |
+
{
|
| 273 |
+
"row": 8699,
|
| 274 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((6u*b)^(a*45u))^((b+b)-(c^c)));}",
|
| 275 |
+
"hex": "89 f1 6b c1 06 6b f7 2d 31 f0 31 f1 01 ce 29 d1 31 c8 c3",
|
| 276 |
+
"disassembled": true,
|
| 277 |
+
"semantic": false,
|
| 278 |
+
"error": "row 8699: emulator mismatch on (1, 1, 1), 0 != 41"
|
| 279 |
+
},
|
| 280 |
+
{
|
| 281 |
+
"row": 8742,
|
| 282 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((a+32u)|(a-c))-((b+a)&(40u-c)));}",
|
| 283 |
+
"hex": "89 54 24 fc 89 f1 8b 74 24 fc 89 f8 83 c0 20 89 fa 89 ca 09 d0 01 f9 ba 28 00 00 00 29 f2 21 d1 29 c8 c3",
|
| 284 |
+
"disassembled": true,
|
| 285 |
+
"semantic": false,
|
| 286 |
+
"error": "row 8742: emulator mismatch on (4294967295, 4294967295, 4294967295), 4294967255 != 4294967287"
|
| 287 |
+
},
|
| 288 |
+
{
|
| 289 |
+
"row": 8767,
|
| 290 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c|30u)&(21u-c))|((10u&a)+(5u|6u)));}",
|
| 291 |
+
"hex": "89 d0 89 f9 83 c8 1e be 15 00 00 00 29 f2 21 f0 83 e1 0a ba 06 00 00 00 83 ca 05 01 d1 09 c8 c3",
|
| 292 |
+
"disassembled": true,
|
| 293 |
+
"semantic": false,
|
| 294 |
+
"error": "row 8767: emulator mismatch on (4294967295, 4294967295, 4294967295), 21 != 23"
|
| 295 |
+
},
|
| 296 |
+
{
|
| 297 |
+
"row": 8817,
|
| 298 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c&c)-(29u-c))&((27u|a)-(b^25u)));}",
|
| 299 |
+
"hex": "89 d0 89 f9 21 c0 ba 1d 00 00 00 29 ca 29 d0 83 c9 1b 83 f6 19 29 f1 21 c8 c3",
|
| 300 |
+
"disassembled": true,
|
| 301 |
+
"semantic": false,
|
| 302 |
+
"error": "row 8817: emulator mismatch on (0, 4294967295, 1), 36 != 37"
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"row": 8863,
|
| 306 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((c*29u)*(58u-a))&((a-a)-(c*60u)));}",
|
| 307 |
+
"hex": "89 f9 6b c2 1d be 3a 00 00 00 0f af f1 0f af c7 29 c9 6b d2 3c 29 d1 21 c8 c3",
|
| 308 |
+
"disassembled": true,
|
| 309 |
+
"semantic": false,
|
| 310 |
+
"error": "row 8863: emulator mismatch on (1, 1, 1), 4 != 1604"
|
| 311 |
+
},
|
| 312 |
+
{
|
| 313 |
+
"row": 8890,
|
| 314 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((20u^52u)*(c^b))|((27u&a)+(c-16u)));}",
|
| 315 |
+
"hex": "89 f9 b8 34 00 00 00 83 f0 14 89 d6 31 ce 0f af c6 83 e1 1b 83 ea 10 01 d1 09 c8 c3",
|
| 316 |
+
"disassembled": true,
|
| 317 |
+
"semantic": false,
|
| 318 |
+
"error": "row 8890: emulator mismatch on (4294967295, 0, 1), 4294967244 != 44"
|
| 319 |
+
},
|
| 320 |
+
{
|
| 321 |
+
"row": 8908,
|
| 322 |
+
"source": "unsigned f(unsigned a,unsigned b,unsigned c){return (((b+48u)*(c+45u))-((a+54u)-(c^c)));}",
|
| 323 |
+
"hex": "89 f9 89 f8 83 c0 30 89 d6 83 c6 2d 0f af c6 83 c1 36 31 d2 29 d1 29 c8 c3",
|
| 324 |
+
"disassembled": true,
|
| 325 |
+
"semantic": false,
|
| 326 |
+
"error": "row 8908: emulator mismatch on (0, 4294967295, 1), 2154 != 2108"
|
| 327 |
+
}
|
| 328 |
+
]
|
| 329 |
+
}
|
examples/batch_example.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from neuro_compiler import NeuralCompiler
|
| 2 |
+
compiler = NeuralCompiler.from_pretrained('orthagonal/neuro-compiler')
|
| 3 |
+
sources = ['unsigned f(unsigned a,unsigned b,unsigned c){return (a+b);}',
|
| 4 |
+
'unsigned f(unsigned a,unsigned b,unsigned c){return (a^c);}']
|
| 5 |
+
for code in compiler.compile_batch(sources):
|
| 6 |
+
print(code.hex(' '))
|
examples/compile_example.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from neuro_compiler import NeuralCompiler
|
| 2 |
+
compiler = NeuralCompiler.from_pretrained('orthagonal/neuro-compiler', device='auto')
|
| 3 |
+
print(compiler.compile('unsigned f(unsigned a,unsigned b,unsigned c){return ((a+b)*(c-7u));}').hex(' '))
|
examples/inspect_example.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from neuro_compiler import NeuralCompiler
|
| 2 |
+
compiler = NeuralCompiler.from_pretrained('orthagonal/neuro-compiler')
|
| 3 |
+
result = compiler.compile('unsigned f(unsigned a,unsigned b,unsigned c){return (a+b);}', return_intermediates=True)
|
| 4 |
+
print(result.ast, result.ssa, result.virtual_mir, result.physical_mir, result.machine_code)
|
manifest.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
neuro_compiler/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Experimental non-autoregressive neural compiler. Generated code may be unsafe."""
|
| 2 |
+
from .compiler import NeuralCompiler, CompilationResult
|
| 3 |
+
__version__ = '0.1.0.dev0'
|
| 4 |
+
__all__ = ['NeuralCompiler', 'CompilationResult']
|
neuro_compiler/cli.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from . import NeuralCompiler
|
| 4 |
+
|
| 5 |
+
def main():
|
| 6 |
+
p=argparse.ArgumentParser(description='Experimental x86-64 SysV neural compiler; generated bytes may be unsafe.')
|
| 7 |
+
g=p.add_mutually_exclusive_group(required=True); g.add_argument('--source'); g.add_argument('--file',type=Path)
|
| 8 |
+
p.add_argument('--model',default='orthagonal/neuro-compiler'); p.add_argument('--device',choices=['auto','cpu','cuda'],default='auto'); p.add_argument('--output',type=Path); p.add_argument('--verify',action='store_true')
|
| 9 |
+
a=p.parse_args(); source=a.source if a.source is not None else a.file.read_text(encoding='utf-8')
|
| 10 |
+
code=NeuralCompiler.from_pretrained(a.model,device=a.device).compile(source)
|
| 11 |
+
if a.output: a.output.write_bytes(code)
|
| 12 |
+
else: print(code.hex(' '))
|
| 13 |
+
if a.verify:
|
| 14 |
+
import json
|
| 15 |
+
from .verification import verify
|
| 16 |
+
print(json.dumps(verify(source,code)))
|
| 17 |
+
|
| 18 |
+
if __name__=='__main__': main()
|
neuro_compiler/compiler.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import hashlib
|
| 4 |
+
import json
|
| 5 |
+
import warnings
|
| 6 |
+
import torch
|
| 7 |
+
from safetensors.torch import load_file
|
| 8 |
+
from . import neurocc as nc
|
| 9 |
+
from .neurocc_live_v2 import NeuralCompiler as Pipeline, raw_bytes
|
| 10 |
+
from .neurocc_ast import ASTStage
|
| 11 |
+
from .neurocc_ir_unfolded import IRStage
|
| 12 |
+
from .neurocc_isel_v2 import ISELStageV2
|
| 13 |
+
from .neurocc_regalloc_v2 import RegisterStageV2
|
| 14 |
+
from .neurocc_binary import BinaryStage
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class CompilationResult:
|
| 18 |
+
machine_code: bytes
|
| 19 |
+
ast: dict
|
| 20 |
+
ssa: tuple
|
| 21 |
+
virtual_mir: tuple
|
| 22 |
+
physical_mir: tuple
|
| 23 |
+
|
| 24 |
+
class NeuralCompiler:
|
| 25 |
+
"""Load frozen V2 stages; compile without a parser, assembler, or native execution."""
|
| 26 |
+
@classmethod
|
| 27 |
+
def from_pretrained(cls, model_id='orthagonal/neuro-compiler', device='auto', revision=None):
|
| 28 |
+
root=Path(model_id)
|
| 29 |
+
if not root.is_dir():
|
| 30 |
+
from huggingface_hub import snapshot_download
|
| 31 |
+
root=Path(snapshot_download(str(model_id),revision=revision,allow_patterns=['manifest.json','config.json','weights/*.safetensors']))
|
| 32 |
+
self=cls(); self.root=root
|
| 33 |
+
try: self.manifest=json.loads((root/'manifest.json').read_text())
|
| 34 |
+
except FileNotFoundError as e: raise FileNotFoundError(f'Missing release manifest in {root}') from e
|
| 35 |
+
m=self.manifest
|
| 36 |
+
if m['architecture']!='NeuroCC V2' or m['spec']['depths']!=[6] or m['spec']['revision']!='0576a1bc0ae53f21860e905e081807bd7ff4a4c7':
|
| 37 |
+
raise ValueError('Incompatible compiler architecture or backbone revision')
|
| 38 |
+
self.spec=m['spec']; self.dev=nc.device() if device=='auto' else torch.device(device)
|
| 39 |
+
if self.dev.type not in ('cpu','cuda'): raise ValueError('Only CPU and CUDA inference are supported')
|
| 40 |
+
if self.dev.type=='cuda' and not torch.cuda.is_available(): raise ValueError('CUDA requested but unavailable')
|
| 41 |
+
stages=[]
|
| 42 |
+
for name,factory,mode in zip(('ast','ssa','isel','regalloc','binary'),(ASTStage,IRStage,ISELStageV2,RegisterStageV2,BinaryStage),('deps','deps','discrete_copy','aligned_copy','copy')):
|
| 43 |
+
entry=m['stages'][name]; path=root/'weights'/f'{name}.safetensors'
|
| 44 |
+
if not path.is_file(): raise FileNotFoundError(f'Missing stage weights: {path}')
|
| 45 |
+
if hashlib.sha256(path.read_bytes()).hexdigest()!=entry['sha256']: raise ValueError(f'Weight integrity check failed: {name}')
|
| 46 |
+
if entry['config']['mode']!=mode or entry['config']['width']!=128: raise ValueError(f'Incompatible stage configuration: {name}')
|
| 47 |
+
stage=factory(entry['config']); stage.load_state_dict(load_file(str(path)),strict=True)
|
| 48 |
+
if sum(p.numel() for p in stage.parameters())!=entry['parameters']: raise ValueError(f'Parameter count mismatch: {name}')
|
| 49 |
+
stages.append(stage)
|
| 50 |
+
self.tokenizer=nc.tokenizer_for(self.spec)
|
| 51 |
+
bb=nc.Backbone(self.spec,self.dev)
|
| 52 |
+
self.model=Pipeline(bb,*stages,self.dev).to(self.dev).eval()
|
| 53 |
+
warnings.warn('Experimental neural compiler: generated machine code may be incorrect or unsafe. No native execution or formal verification is performed.',UserWarning,stacklevel=2)
|
| 54 |
+
return self
|
| 55 |
+
|
| 56 |
+
@torch.inference_mode()
|
| 57 |
+
def predict(self,sources):
|
| 58 |
+
"""Return raw byte IDs and stage tensors for reproducibility tools."""
|
| 59 |
+
if isinstance(sources,str): raise TypeError('Expected a sequence of source strings')
|
| 60 |
+
if not sources: raise ValueError('Empty batch')
|
| 61 |
+
for source in sources:
|
| 62 |
+
if not isinstance(source,str) or not source.strip(): raise ValueError('Source must be a nonempty string')
|
| 63 |
+
if len(source.encode('utf-8'))>192: raise ValueError('Source exceeds the trained 192-byte source capacity')
|
| 64 |
+
import re
|
| 65 |
+
if not re.fullmatch(r'[\x20-\x7e\r\n\t]+',source) or re.search(r'[/%=<>!~?:\[\]]|\b(if|while|for|goto|switch)\b',source):
|
| 66 |
+
raise ValueError('Unsupported source characters or control flow; see the trained grammar')
|
| 67 |
+
try: ids,mask=nc.tokenize(self.tokenizer,sources,self.spec['tokens'])
|
| 68 |
+
except RuntimeError as e: raise ValueError(f'Source exceeds the trained {self.spec["tokens"]}-token limit; no truncation performed') from e
|
| 69 |
+
return self.model.stages(ids.to(self.dev),mask.to(self.dev))
|
| 70 |
+
|
| 71 |
+
def compile_batch(self,sources,return_intermediates=False,batch_size=32):
|
| 72 |
+
if isinstance(sources,str): raise TypeError('Expected a sequence of source strings')
|
| 73 |
+
sources=list(sources)
|
| 74 |
+
if batch_size<1: raise ValueError('batch_size must be positive')
|
| 75 |
+
results=[]
|
| 76 |
+
for i in range(0,len(sources),batch_size):
|
| 77 |
+
bp,stages=self.predict(sources[i:i+batch_size]); a,h,ip,m,mp,r,rp=stages
|
| 78 |
+
nodes=self.model.ast.node(a.float()).argmax(-1) if return_intermediates else None
|
| 79 |
+
for j,row in enumerate(bp[-1]):
|
| 80 |
+
code=raw_bytes(row.cpu())
|
| 81 |
+
if code is None: raise ValueError(f'Malformed neural byte output at batch index {i+j}: invalid EOS, padding, or byte value')
|
| 82 |
+
results.append(CompilationResult(code,{'nodes':nodes[j].cpu(),'features':a[j].cpu()},tuple(x[j].cpu() for x in ip),tuple(x[j].cpu() for x in mp),tuple(x[j].cpu() for x in rp)) if return_intermediates else code)
|
| 83 |
+
return results
|
| 84 |
+
|
| 85 |
+
def compile(self,source,return_intermediates=False):
|
| 86 |
+
return self.compile_batch([source],return_intermediates=return_intermediates)[0]
|
neuro_compiler/neurocc.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from torch import nn
|
| 6 |
+
|
| 7 |
+
SRC, OUT, PAD, EOS = 192, 64, 256, 257
|
| 8 |
+
|
| 9 |
+
def device(): return torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 10 |
+
|
| 11 |
+
def amp(dev): return torch.autocast(dev.type,dtype=torch.float16,enabled=dev.type=='cuda')
|
| 12 |
+
|
| 13 |
+
def tokenizer_for(spec):
|
| 14 |
+
from transformers import AutoTokenizer
|
| 15 |
+
tok=AutoTokenizer.from_pretrained(spec['backbone'],revision=spec['revision'],trust_remote_code=False)
|
| 16 |
+
if tok.pad_token_id is None: tok.pad_token=tok.eos_token
|
| 17 |
+
tok.padding_side='right'; return tok
|
| 18 |
+
|
| 19 |
+
def tokenize(tok,sources,tokens):
|
| 20 |
+
result=tok(sources,add_special_tokens=False,padding='max_length',max_length=tokens,truncation=False,return_tensors=None)
|
| 21 |
+
# HF does not truncate; check before converting ragged lists into a tensor.
|
| 22 |
+
if any(len(row)!=tokens for row in result['input_ids']): raise RuntimeError(f'Source exceeds --tokens {tokens}; increase limit and rebuild cache')
|
| 23 |
+
return torch.tensor(result['input_ids'],dtype=torch.long),torch.tensor(result['attention_mask'],dtype=torch.bool)
|
| 24 |
+
|
| 25 |
+
class Backbone(nn.Module):
|
| 26 |
+
"""Use AutoModel (not AutoModelForCausalLM). Depth k = output of k blocks.
|
| 27 |
+
Intermediate features are raw block output; full depth has Qwen final norm.
|
| 28 |
+
Truncated inference uses identical features to full-model caching.
|
| 29 |
+
"""
|
| 30 |
+
def __init__(self,spec,dev):
|
| 31 |
+
super().__init__()
|
| 32 |
+
from transformers import AutoModel
|
| 33 |
+
self.net=AutoModel.from_pretrained(spec['backbone'],revision=spec['revision'],trust_remote_code=False,torch_dtype=torch.float16 if dev.type=='cuda' else torch.float32)
|
| 34 |
+
self.depths=sorted(spec['depths']); self.full_depth=len(self.net.layers); self.hidden=self.net.config.hidden_size
|
| 35 |
+
depth=max(self.depths)
|
| 36 |
+
if depth>self.full_depth: raise RuntimeError(f'Model only has {self.full_depth} blocks')
|
| 37 |
+
# Remove unused blocks physically, avoiding their computation and resident weights.
|
| 38 |
+
self.net.layers=nn.ModuleList(list(self.net.layers)[:depth])
|
| 39 |
+
self.net.config.num_hidden_layers=depth
|
| 40 |
+
if depth<self.full_depth: self.net.norm=nn.Identity()
|
| 41 |
+
self.net.requires_grad_(False); self.net.to(dev).eval()
|
| 42 |
+
def forward(self,ids,mask):
|
| 43 |
+
if max(self.depths)==0: return (self.net.get_input_embeddings()(ids),)
|
| 44 |
+
# HF returns input embeddings, intermediate block outputs, and final norm output.
|
| 45 |
+
if len(self.depths)==1:
|
| 46 |
+
return (self.net(input_ids=ids,attention_mask=mask,use_cache=False,return_dict=True).last_hidden_state,)
|
| 47 |
+
states=self.net(input_ids=ids,attention_mask=mask,use_cache=False,output_hidden_states=True,return_dict=True).hidden_states
|
| 48 |
+
return tuple(states[k] for k in self.depths)
|
neuro_compiler/neurocc_ast.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
CLASSES = ['absent', '+', '-', '*', '^', '&', '|', 'a', 'b', 'c', *[f'{i}u' for i in range(1,64)]]
|
| 10 |
+
|
| 11 |
+
SLOTS = 15
|
| 12 |
+
|
| 13 |
+
def tree_depth(i): return (i+1).bit_length()-1
|
| 14 |
+
|
| 15 |
+
def tree_paths():
|
| 16 |
+
return [bin(i+1)[3:] for i in range(SLOTS)]
|
| 17 |
+
|
| 18 |
+
def tree_relations():
|
| 19 |
+
"""Fixed, directed relations. No target-tree information enters attention."""
|
| 20 |
+
paths = tree_paths(); keys = []
|
| 21 |
+
for p in paths:
|
| 22 |
+
for q in paths:
|
| 23 |
+
k = 0
|
| 24 |
+
while k < min(len(p),len(q)) and p[k] == q[k]: k += 1
|
| 25 |
+
up, down = len(p)-k, len(q)-k
|
| 26 |
+
# Distinguish ancestor/descendant distances and left/right branches.
|
| 27 |
+
keys.append((up, down, p[k:k+1], q[k:k+1]))
|
| 28 |
+
vocab = {v:i for i,v in enumerate(sorted(set(keys)))}
|
| 29 |
+
return torch.tensor([vocab[k] for k in keys]).reshape(SLOTS,SLOTS), len(vocab)
|
| 30 |
+
|
| 31 |
+
class Block(nn.Module):
|
| 32 |
+
def __init__(self,d,heads,dropout,self_attention,tree=False):
|
| 33 |
+
super().__init__(); self.heads=heads
|
| 34 |
+
self.cross=nn.MultiheadAttention(d,heads,dropout=dropout,batch_first=True)
|
| 35 |
+
self.cn=nn.LayerNorm(d); self.sn=nn.LayerNorm(d); self.fn=nn.LayerNorm(d)
|
| 36 |
+
self.self_attn=nn.MultiheadAttention(d,heads,dropout=dropout,batch_first=True) if self_attention else None
|
| 37 |
+
if tree:
|
| 38 |
+
rel,n=tree_relations(); self.register_buffer('relations',rel,persistent=False)
|
| 39 |
+
self.bias=nn.Embedding(n,heads); nn.init.zeros_(self.bias.weight)
|
| 40 |
+
else: self.bias=None
|
| 41 |
+
self.ff=nn.Sequential(nn.Linear(d,4*d),nn.GELU(),nn.Dropout(dropout),nn.Linear(4*d,d))
|
| 42 |
+
self.drop=nn.Dropout(dropout)
|
| 43 |
+
def forward(self,q,m,mask):
|
| 44 |
+
z=self.cn(q); q=q+self.drop(self.cross(z,m,m,key_padding_mask=~mask,need_weights=False)[0])
|
| 45 |
+
if self.self_attn is not None:
|
| 46 |
+
z=self.sn(q); bias=None
|
| 47 |
+
if self.bias is not None:
|
| 48 |
+
bias=self.bias(self.relations).permute(2,0,1).unsqueeze(0).expand(len(q),-1,-1,-1).reshape(-1,SLOTS,SLOTS).to(z.dtype)
|
| 49 |
+
q=q+self.drop(self.self_attn(z,z,z,attn_mask=bias,need_weights=False)[0])
|
| 50 |
+
return q+self.drop(self.ff(self.fn(q)))
|
| 51 |
+
|
| 52 |
+
class ASTStage(nn.Module):
|
| 53 |
+
"""encode() is the reusable continuous compiler stage, independent of all labels."""
|
| 54 |
+
def __init__(self,cfg):
|
| 55 |
+
super().__init__(); self.cfg=dict(cfg); d=cfg['width']; mode=cfg['mode']; heads=cfg['heads']; drop=cfg['dropout']
|
| 56 |
+
self.project=nn.Sequential(nn.Linear(cfg['hidden'],d),nn.LayerNorm(d))
|
| 57 |
+
self.query=nn.Parameter(torch.randn(SLOTS,d)*.02)
|
| 58 |
+
self.tree=mode in ('tree','span','deps','recursive')
|
| 59 |
+
if self.tree:
|
| 60 |
+
self.depth_emb=nn.Embedding(4,d); self.path_emb=nn.Embedding(6,d)
|
| 61 |
+
nn.init.normal_(self.depth_emb.weight,std=.02); nn.init.normal_(self.path_emb.weight,std=.02)
|
| 62 |
+
p=torch.zeros(SLOTS,6)
|
| 63 |
+
for i,path in enumerate(tree_paths()):
|
| 64 |
+
for j,s in enumerate(path): p[i,2*j+int(s)]=1
|
| 65 |
+
self.register_buffer('paths',p,persistent=False)
|
| 66 |
+
self.register_buffer('depths',torch.tensor([tree_depth(i) for i in range(SLOTS)]),persistent=False)
|
| 67 |
+
if mode=='recursive':
|
| 68 |
+
self.blocks=nn.ModuleList([Block(d,heads,drop,True) for _ in range(cfg['layers'])])
|
| 69 |
+
self.child=nn.Sequential(nn.Linear(d,d),nn.GELU(),nn.LayerNorm(d))
|
| 70 |
+
self.side=nn.Embedding(2,d)
|
| 71 |
+
else:
|
| 72 |
+
self.blocks=nn.ModuleList([Block(d,heads,drop,mode!='cross',self.tree) for _ in range(1 if mode=='cross' else cfg['layers'])])
|
| 73 |
+
self.norm=nn.LayerNorm(d); self.node=nn.Linear(d,len(CLASSES))
|
| 74 |
+
if mode in ('span','deps'):
|
| 75 |
+
self.span_q=nn.ModuleList([nn.Linear(d,d,bias=False) for _ in range(2)])
|
| 76 |
+
self.span_k=nn.ModuleList([nn.Linear(d,d,bias=False) for _ in range(2)])
|
| 77 |
+
else: self.span_q=None
|
| 78 |
+
self.dep=nn.Linear(d,3) if mode=='deps' else None
|
| 79 |
+
def _encode(self,features,mask):
|
| 80 |
+
m=self.project(features.float()); mask=mask.bool(); base=self.query
|
| 81 |
+
if self.tree: base=base+self.depth_emb(self.depths)+self.paths@self.path_emb.weight
|
| 82 |
+
if self.cfg['mode']=='recursive':
|
| 83 |
+
levels=[]; q=base[:1].unsqueeze(0).expand(len(m),-1,-1)
|
| 84 |
+
for depth in range(4):
|
| 85 |
+
if depth:
|
| 86 |
+
n=2**depth; start=n-1
|
| 87 |
+
q=self.child(levels[-1]).repeat_interleave(2,dim=1)+self.side(torch.arange(n,device=m.device)%2)[None]+base[start:start+n][None]
|
| 88 |
+
for block in self.blocks: q=block(q,m,mask)
|
| 89 |
+
levels.append(q)
|
| 90 |
+
q=torch.cat(levels,dim=1)
|
| 91 |
+
else:
|
| 92 |
+
q=base.unsqueeze(0).expand(len(m),-1,-1)
|
| 93 |
+
for block in self.blocks: q=block(q,m,mask)
|
| 94 |
+
return self.norm(q),m
|
| 95 |
+
def encode(self,features,mask): return self._encode(features,mask)[0]
|
| 96 |
+
def forward(self,features,mask):
|
| 97 |
+
h,m=self._encode(features,mask); out={'nodes':self.node(h)}
|
| 98 |
+
if self.span_q is not None:
|
| 99 |
+
z=[(q(h)@k(m).transpose(1,2))/math.sqrt(h.shape[-1]) for q,k in zip(self.span_q,self.span_k)]
|
| 100 |
+
out['spans']=torch.stack(z,dim=2).masked_fill(~mask.bool()[:,None,None,:],-1e4)
|
| 101 |
+
if self.dep is not None: out['deps']=self.dep(h)
|
| 102 |
+
return out
|
neuro_compiler/neurocc_backend_trace.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
import struct
|
| 6 |
+
|
| 7 |
+
MASK=0xffffffff
|
| 8 |
+
|
| 9 |
+
def evaluate(op,args,values,x):
|
| 10 |
+
results=[]
|
| 11 |
+
for i,k in enumerate(op):
|
| 12 |
+
def get(j):
|
| 13 |
+
a=args[i][j]
|
| 14 |
+
return values[i][j] if a==12 else x[a-1] if 1<=a<=3 else results[a-4]
|
| 15 |
+
a=get(0)
|
| 16 |
+
if k==7: return a
|
| 17 |
+
b=get(1); results.append((a+b,a-b,a*b,a^b,a&b,a|b)[k-1]&MASK)
|
| 18 |
+
raise ValueError('no ret')
|
| 19 |
+
|
| 20 |
+
def samples(n):
|
| 21 |
+
edge=[(0,0,0),(1,1,1),(MASK,MASK,MASK),(0,MASK,1),(MASK,0,1),(1,0,MASK),(0x80000000,0x7fffffff,0x55555555),(0xaaaaaaaa,0x55555555,0x80000000)]
|
| 22 |
+
rng=random.Random(971); return edge[:n]+[tuple(rng.getrandbits(32) for _ in range(3)) for _ in range(max(0,n-len(edge)))]
|
| 23 |
+
|
| 24 |
+
def verify_binary(raw,row,xs):
|
| 25 |
+
from unicorn import Uc, UC_ARCH_X86, UC_MODE_64, UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC
|
| 26 |
+
from unicorn.x86_const import UC_X86_REG_RSP, UC_X86_REG_RIP, UC_X86_REG_EAX, UC_X86_REG_EDI, UC_X86_REG_ESI, UC_X86_REG_EDX, UC_X86_REG_RAX, UC_X86_REG_RBX, UC_X86_REG_RCX, UC_X86_REG_RBP, UC_X86_REG_R8, UC_X86_REG_R9, UC_X86_REG_R10, UC_X86_REG_R11, UC_X86_REG_R12, UC_X86_REG_R13, UC_X86_REG_R14, UC_X86_REG_R15, UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX, UC_X86_REG_EFLAGS
|
| 27 |
+
base=0x100000; stack=0x200000; size=0x10000; stop=base+0x1000
|
| 28 |
+
if len(raw)>=0x1000: raise ValueError('function exceeds emulator code page')
|
| 29 |
+
uc=Uc(UC_ARCH_X86,UC_MODE_64); uc.mem_map(base,0x2000,UC_PROT_READ|UC_PROT_WRITE|UC_PROT_EXEC); uc.mem_write(base,raw); uc.mem_protect(base,0x2000,UC_PROT_READ|UC_PROT_EXEC); uc.mem_map(stack,size,UC_PROT_READ|UC_PROT_WRITE)
|
| 30 |
+
rsp=stack+size//2-8
|
| 31 |
+
regs=(UC_X86_REG_RAX,UC_X86_REG_RBX,UC_X86_REG_RCX,UC_X86_REG_RBP,UC_X86_REG_R8,UC_X86_REG_R9,UC_X86_REG_R10,UC_X86_REG_R11,UC_X86_REG_R12,UC_X86_REG_R13,UC_X86_REG_R14,UC_X86_REG_R15,UC_X86_REG_RDI,UC_X86_REG_RSI,UC_X86_REG_RDX)
|
| 32 |
+
for x in xs:
|
| 33 |
+
for reg in regs: uc.reg_write(reg,0)
|
| 34 |
+
uc.reg_write(UC_X86_REG_EFLAGS,2); uc.mem_write(rsp-4096,b'\0'*8192); uc.mem_write(rsp,struct.pack('<Q',stop)); uc.reg_write(UC_X86_REG_RSP,rsp)
|
| 35 |
+
for reg,v in zip((UC_X86_REG_EDI,UC_X86_REG_ESI,UC_X86_REG_EDX),x): uc.reg_write(reg,v)
|
| 36 |
+
uc.emu_start(base,stop,count=512)
|
| 37 |
+
actual=uc.reg_read(UC_X86_REG_EAX); expected=evaluate(*row[1:],x)
|
| 38 |
+
if uc.reg_read(UC_X86_REG_RIP)!=stop or uc.reg_read(UC_X86_REG_RSP)!=rsp+8 or actual!=expected: raise ValueError(f'row {row[0]}: emulator mismatch on {x}, {actual} != {expected}')
|
neuro_compiler/neurocc_binary.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
from . import neurocc as nc
|
| 10 |
+
|
| 11 |
+
from . import neurocc_ast as ast
|
| 12 |
+
|
| 13 |
+
def tables(entries, p):
|
| 14 |
+
"""IDs 0/1 are reserved; validate training-derived template dictionary."""
|
| 15 |
+
n = len(entries) + 2
|
| 16 |
+
fixed = torch.zeros(n, 15, dtype=torch.long)
|
| 17 |
+
lengths = torch.zeros(n, dtype=torch.long)
|
| 18 |
+
positions = torch.zeros(n, 15, dtype=torch.long)
|
| 19 |
+
field = torch.zeros(n, p, dtype=torch.long)
|
| 20 |
+
rank = torch.zeros(n, p, dtype=torch.long)
|
| 21 |
+
for i, e in enumerate(entries, 2):
|
| 22 |
+
l, f, tags, pos = e['length'], e['fixed_bytes'], e['field_tags'], e['payload_positions']
|
| 23 |
+
if e['id'] != i or not 1 <= l <= 15 or len(f) != l or len(tags) != l or any(not 0 <= b <= 255 for b in f) or any(t not in (0, 1, 2) for t in tags) or pos != [j for j,t in enumerate(tags) if t] or len(pos) > p:
|
| 24 |
+
raise ValueError(f'invalid template {i}')
|
| 25 |
+
lengths[i] = l; fixed[i, :l] = torch.tensor(f)
|
| 26 |
+
counts = {1: 0, 2: 0}
|
| 27 |
+
for k, j in enumerate(pos):
|
| 28 |
+
tag = tags[j]; positions[i, j] = k + 1
|
| 29 |
+
field[i, k] = tag; rank[i, k] = counts[tag]; counts[tag] += 1
|
| 30 |
+
if counts[1] > 4: raise ValueError('immediates wider than 32 bits not supported')
|
| 31 |
+
return dict(fixed=fixed, lengths=lengths, positions=positions, field=field, rank=rank)
|
| 32 |
+
|
| 33 |
+
def materialize(tab, ids, payload, count, out):
|
| 34 |
+
"""Parallel lookup, exclusive prefix sum and scatter; no ISA rules."""
|
| 35 |
+
lengths = tab['lengths'][ids]
|
| 36 |
+
pos = tab['positions'][ids]
|
| 37 |
+
data = torch.cat((torch.zeros_like(payload[..., :1]), payload), -1)
|
| 38 |
+
values = torch.where(pos.ne(0), data.gather(-1, pos), tab['fixed'][ids])
|
| 39 |
+
active = torch.arange(ids.shape[1], device=ids.device)[None, :] < count[:, None]
|
| 40 |
+
lengths = lengths * active
|
| 41 |
+
offsets = lengths.cumsum(1) - lengths
|
| 42 |
+
j = torch.arange(15, device=ids.device)[None, None, :]
|
| 43 |
+
valid = j < lengths[..., None]
|
| 44 |
+
dst = offsets[..., None] + j
|
| 45 |
+
total = lengths.sum(1)
|
| 46 |
+
buf = torch.zeros((len(ids), out), dtype=torch.long, device=ids.device)
|
| 47 |
+
buf.scatter_add_(1, dst.clamp(0,out-1).flatten(1), torch.where(valid & dst.lt(out), values, 0).flatten(1))
|
| 48 |
+
index = torch.arange(out, device=ids.device)[None, :]
|
| 49 |
+
y = torch.where(index < total[:,None], buf, torch.where(index == total[:,None], nc.EOS, nc.PAD))
|
| 50 |
+
good = (count > 0) & (count <= ids.shape[1]) & (total < out) & ((ids >= 2) | ~active).all(1)
|
| 51 |
+
return torch.where(good[:,None], y, nc.PAD)
|
| 52 |
+
|
| 53 |
+
class BinaryStage(nn.Module):
|
| 54 |
+
"""Predict count, template IDs and template-conditioned payload bytes."""
|
| 55 |
+
def __init__(self,cfg):
|
| 56 |
+
super().__init__(); self.cfg=cfg; d=cfg['width']; self.d=d; self.s=cfg['slots']; self.p=cfg['payload_width']; self.mode=cfg['mode']; self.graph=self.mode in ('graph','copy','oracle_copy'); self.latent=self.mode!='oracle_copy'; self.copy=self.mode.endswith('copy'); self.nt=len(cfg['templates'])+2; self.ps=cfg['source_slots']; self.pw=cfg['source_operands']
|
| 57 |
+
self.proj=nn.Linear(cfg['input_width'],d) if self.latent else None
|
| 58 |
+
self.pos=nn.Parameter(torch.randn(self.ps,d)*.02); self.memnorm=nn.LayerNorm(d)
|
| 59 |
+
if self.graph:
|
| 60 |
+
self.source_sig=nn.Embedding(len(cfg['source_vocab']),d)
|
| 61 |
+
self.source_reg=nn.Embedding(len(cfg['register_vocab']),16)
|
| 62 |
+
self.source_num=nn.Embedding(len(cfg['immediate_vocab'])+1,16)
|
| 63 |
+
self.source_stack=nn.Embedding(len(cfg['stack_vocab'])+1,8)
|
| 64 |
+
self.source_operands=nn.Linear(self.pw*40,d)
|
| 65 |
+
self.query=nn.Parameter(torch.randn(self.s,d)*.02)
|
| 66 |
+
self.blocks=nn.ModuleList([ast.Block(d,cfg['heads'],cfg['dropout'],True) for _ in range(cfg['layers'])]); self.norm=nn.LayerNorm(d)
|
| 67 |
+
self.template=nn.Linear(d,self.nt); self.count=nn.Linear(d,self.s); self.template_emb=nn.Embedding(self.nt,d)
|
| 68 |
+
self.payload_head=nn.Sequential(nn.Linear(d,d),nn.GELU(),nn.Linear(d,self.p*256))
|
| 69 |
+
if self.copy:
|
| 70 |
+
self.copy_query=nn.Linear(d,d); self.copy_key=nn.Linear(d,d); self.copy_number=nn.Embedding(len(cfg['immediate_vocab'])+1,d); self.copy_pos=nn.Parameter(torch.randn(self.pw,d)*.02); self.gate=nn.Linear(d,1)
|
| 71 |
+
for k,v in tables(cfg['templates'],self.p).items(): self.register_buffer('tab_'+k,v,persistent=False)
|
| 72 |
+
for k in ('imm','stack'): self.register_buffer('src_'+k+'_mask',torch.tensor(cfg['source_'+k+'_mask'],dtype=torch.bool),persistent=False)
|
| 73 |
+
self.register_buffer('numbers',torch.tensor(cfg['immediate_vocab'],dtype=torch.long),persistent=False)
|
| 74 |
+
self.register_buffer('stacks',torch.tensor(cfg['stack_vocab'],dtype=torch.long),persistent=False)
|
| 75 |
+
def table(self): return {k:getattr(self,'tab_'+k) for k in ('fixed','lengths','positions','field','rank')}
|
| 76 |
+
@staticmethod
|
| 77 |
+
def ids(values,vocab,mask):
|
| 78 |
+
matches=values.unsqueeze(-1).eq(vocab); return (matches.long().argmax(-1)+1).masked_fill(~matches.any(-1)|~mask,0)
|
| 79 |
+
def encode(self,h,mask,sig,reg,imm,stack):
|
| 80 |
+
m=self.pos[None].expand(len(h),-1,-1)
|
| 81 |
+
if self.latent: m=m+self.proj(h.float())
|
| 82 |
+
ni=None; valid=None
|
| 83 |
+
if self.graph:
|
| 84 |
+
valid=self.src_imm_mask[sig]; ni=self.ids(imm,self.numbers,valid); si=self.ids(stack,self.stacks,self.src_stack_mask[sig]); valid=valid&ni.ne(0)
|
| 85 |
+
m=m+self.source_sig(sig)+self.source_operands(torch.cat((self.source_reg(reg),self.source_num(ni),self.source_stack(si)),-1).flatten(2))
|
| 86 |
+
m=self.memnorm(m); q=self.query[None].expand(len(h),-1,-1)
|
| 87 |
+
for block in self.blocks: q=block(q,m,mask)
|
| 88 |
+
return self.norm(q),m,ni,valid,imm
|
| 89 |
+
def forward(self,*inputs):
|
| 90 |
+
z,mem,ni,valid,imm=self.encode(*inputs)
|
| 91 |
+
logits=self.template(z); logits=logits.masked_fill(torch.arange(self.nt,device=z.device)<2,-1e4)
|
| 92 |
+
return z,mem,ni,valid,imm,logits,self.count(z.mean(1))
|
| 93 |
+
def payload_logits(self,out,ids):
|
| 94 |
+
z,m,ni,valid,imm,_,_=out; b,s,d=z.shape; q=z+self.template_emb(ids)
|
| 95 |
+
gen=self.payload_head(q).reshape(b,s,self.p,256)
|
| 96 |
+
if not self.copy: return gen
|
| 97 |
+
# One learned pointer distribution per instruction. Values are copied
|
| 98 |
+
# from predicted source operands; only serialization of bytes is exact.
|
| 99 |
+
# Displacements are always predicted, never calculated from stack slots.
|
| 100 |
+
keys=self.copy_key(m.unsqueeze(2)+self.copy_number(ni)+self.copy_pos).flatten(1,2)
|
| 101 |
+
valid=valid.flatten(1); score=torch.einsum('bsd,bkd->bsk',self.copy_query(q),keys)/math.sqrt(d)
|
| 102 |
+
prob=score.masked_fill(~valid[:,None,:],-1e4).softmax(-1)*valid[:,None,:]
|
| 103 |
+
vals=imm.flatten(1)[:,None,None,:]; rank=self.tab_rank[ids]; bytes_=((vals >> (8*rank.unsqueeze(-1))) & 255).expand(b,s,self.p,-1)
|
| 104 |
+
cp=torch.zeros_like(gen).scatter_add(-1,bytes_,prob.unsqueeze(2).expand_as(bytes_))
|
| 105 |
+
gate=self.gate(q).sigmoid().unsqueeze(-1)*self.tab_field[ids].eq(1).unsqueeze(-1)*valid.any(-1)[:,None,None,None]
|
| 106 |
+
return ((1-gate)*gen.softmax(-1)+gate*cp).clamp_min(1e-12).log()
|
| 107 |
+
def decode(self,out):
|
| 108 |
+
ids=out[-2].argmax(-1); count=out[-1].argmax(-1)+1
|
| 109 |
+
payload=self.payload_logits(out,ids).argmax(-1)
|
| 110 |
+
y=materialize(self.table(),ids,payload,count,self.cfg['out_bytes'])
|
| 111 |
+
active=torch.arange(self.s,device=ids.device)[None,:]<count[:,None]
|
| 112 |
+
ids=ids.masked_fill(~active,0); payload=payload.masked_fill(~self.tab_field[ids].ne(0),0)
|
| 113 |
+
return ids,count,payload,y
|
neuro_compiler/neurocc_ir_unfolded.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from torch import nn
|
| 6 |
+
|
| 7 |
+
from . import neurocc_ast as ast
|
| 8 |
+
|
| 9 |
+
SLOTS=8
|
| 10 |
+
|
| 11 |
+
OPS=('PAD','add','sub','mul','xor','and','or','ret')
|
| 12 |
+
|
| 13 |
+
REF=4
|
| 14 |
+
|
| 15 |
+
CONST=REF+SLOTS
|
| 16 |
+
|
| 17 |
+
NVAL=CONST+1
|
| 18 |
+
|
| 19 |
+
class IRStage(nn.Module):
|
| 20 |
+
"""Learned instruction queries -> SSA latent slots; no teacher forcing."""
|
| 21 |
+
def __init__(self,cfg):
|
| 22 |
+
super().__init__(); self.cfg=dict(cfg); d=cfg['width']; mode=cfg['mode']; self.mode=mode
|
| 23 |
+
self.ap=nn.Sequential(nn.Linear(cfg['ast_width'],d),nn.LayerNorm(d)) if mode in ('cross','standard','deps','ast_qwen') else None
|
| 24 |
+
self.qp=nn.Sequential(nn.Linear(cfg['qwen_width'],d),nn.LayerNorm(d)) if mode in ('qwen','ast_qwen') else None
|
| 25 |
+
self.discrete=nn.Embedding(73,d) if mode in ('oracle','discrete') else None
|
| 26 |
+
self.ast_pos=nn.Parameter(torch.randn(15,d)*.02) if mode!='qwen' else None
|
| 27 |
+
self.query=nn.Parameter(torch.randn(SLOTS,d)*.02)
|
| 28 |
+
self.blocks=nn.ModuleList([ast.Block(d,cfg['heads'],cfg['dropout'],True) for _ in range(cfg['layers'])]); self.norm=nn.LayerNorm(d)
|
| 29 |
+
self.op=nn.Linear(d,len(OPS)); self.args=nn.Linear(d,2*NVAL); self.const=nn.Linear(d,2*4*256)
|
| 30 |
+
def encode(self, a=None, q=None, mask=None):
|
| 31 |
+
mem=[]; valid=[]
|
| 32 |
+
if self.ap is not None or self.discrete is not None:
|
| 33 |
+
m=self.ap(a.float()) if self.ap is not None else self.discrete(a.long())
|
| 34 |
+
m=m+self.ast_pos; mem.append(m); valid.append(torch.ones(m.shape[:2],dtype=torch.bool,device=m.device))
|
| 35 |
+
if self.qp is not None:
|
| 36 |
+
m=self.qp(q.float()); mem.append(m); valid.append(mask.bool())
|
| 37 |
+
m=torch.cat(mem,1); keep=torch.cat(valid,1); h=self.query[None].expand(len(m),-1,-1)
|
| 38 |
+
for b in self.blocks: h=b(h,m,keep)
|
| 39 |
+
return self.norm(h)
|
| 40 |
+
def forward(self,a=None,q=None,mask=None):
|
| 41 |
+
h=self.encode(a,q,mask); return self.op(h),self.args(h).reshape(len(h),SLOTS,2,NVAL),self.const(h).reshape(len(h),SLOTS,2,4,256)
|
| 42 |
+
|
| 43 |
+
def decode(out):
|
| 44 |
+
op=out[0].argmax(-1); arg=out[1].argmax(-1)
|
| 45 |
+
arg=arg.masked_fill(op.eq(0).unsqueeze(-1),0); arg[:,:,1]=arg[:,:,1].masked_fill(op.eq(7),0)
|
| 46 |
+
c=(out[2].argmax(-1)<<torch.arange(0,32,8,device=arg.device)).sum(-1).masked_fill(arg.ne(CONST),0)
|
| 47 |
+
return op,arg,c
|
neuro_compiler/neurocc_isel.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
import torch.nn.functional as F
|
| 10 |
+
|
| 11 |
+
from . import neurocc_ast as ast
|
| 12 |
+
|
| 13 |
+
from . import neurocc_ir_unfolded as ir
|
| 14 |
+
|
| 15 |
+
class ISELStage(nn.Module):
|
| 16 |
+
def __init__(self,cfg):
|
| 17 |
+
super().__init__(); self.cfg=cfg; d=cfg['width']; s=cfg['slots']; w=cfg['operands']; self.s=s; self.w=w; self.mode=cfg['mode']; self.pointer=self.mode!='direct'; self.graph=self.mode in ('graph','oracle')
|
| 18 |
+
self.proj=nn.Linear(cfg['input_width'],d); self.pos=nn.Parameter(torch.randn(8,d)*.02); self.memnorm=nn.LayerNorm(d)
|
| 19 |
+
if self.graph: self.graph_proj=nn.Linear(len(ir.OPS)+2*ir.NVAL+64,d)
|
| 20 |
+
self.query=nn.Parameter(torch.randn(s,d)*.02); self.blocks=nn.ModuleList([ast.Block(d,cfg['heads'],cfg['dropout'],True) for _ in range(cfg['layers'])]); self.norm=nn.LayerNorm(d)
|
| 21 |
+
self.sig=nn.Linear(d,len(cfg['vocab'])); self.num=nn.Linear(d,w*(len(cfg['immediate_vocab'])+1))
|
| 22 |
+
if self.pointer: self.rq=nn.Linear(d,w*d); self.rk=nn.Linear(d,d)
|
| 23 |
+
else: self.ref=nn.Linear(d,w*s)
|
| 24 |
+
# Signature-specific operand roles are decoded by table lookup, not an instruction selector.
|
| 25 |
+
self.register_buffer('rm',torch.tensor(cfg['signature_ref_mask'],dtype=torch.bool),persistent=False); self.register_buffer('cm',torch.tensor(cfg['signature_imm_mask'],dtype=torch.bool),persistent=False)
|
| 26 |
+
self.register_buffer('numbers',torch.tensor([0]+cfg['immediate_vocab'],dtype=torch.long),persistent=False)
|
| 27 |
+
def encode(self,h,so,sa,sv):
|
| 28 |
+
m=self.proj(h.float())+self.pos
|
| 29 |
+
if self.graph:
|
| 30 |
+
f=torch.cat([F.one_hot(so,len(ir.OPS)),F.one_hot(sa,ir.NVAL).flatten(2),((sv.unsqueeze(-1)>>torch.arange(32,device=h.device))&1).flatten(2)],-1).float(); m=m+self.graph_proj(f)
|
| 31 |
+
m=self.memnorm(m); q=self.query.unsqueeze(0).expand(len(h),-1,-1); mask=torch.ones(m.shape[:2],dtype=torch.bool,device=m.device)
|
| 32 |
+
for block in self.blocks: q=block(q,m,mask)
|
| 33 |
+
return self.norm(q)
|
| 34 |
+
def heads(self,h):
|
| 35 |
+
b,s,d=h.shape; p=self.sig(h); num=self.num(h).reshape(b,s,self.w,-1); num=num.masked_fill(torch.arange(num.shape[-1],device=h.device)==0,-1e4)
|
| 36 |
+
if self.pointer: ref=torch.einsum('bswd,btd->bswt',self.rq(h).reshape(b,s,self.w,d),self.rk(h))/math.sqrt(d)
|
| 37 |
+
else: ref=self.ref(h).reshape(b,s,self.w,s)
|
| 38 |
+
# Index k references defining slot k; no forward/self references. Slot 0
|
| 39 |
+
# has no legal references; its logits never contribute to reference loss.
|
| 40 |
+
ix=torch.arange(s,device=h.device); ref=ref.masked_fill((ix[None,:]>=ix[:,None])[None,:,None,:],-1e4)
|
| 41 |
+
return p,ref,num
|
| 42 |
+
def forward(self,*x): return self.heads(self.encode(*x))
|
| 43 |
+
def decode(self,out):
|
| 44 |
+
p,r,c=out; sig=p.argmax(-1); ref=(r.argmax(-1)+1).masked_fill(~self.rm[sig],0); imm=self.numbers[c.argmax(-1)].masked_fill(~self.cm[sig],0); return sig,ref,imm
|
neuro_compiler/neurocc_isel_v2.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
from . import neurocc_ir_unfolded as ir
|
| 10 |
+
|
| 11 |
+
from . import neurocc_isel as v1
|
| 12 |
+
|
| 13 |
+
K=ir.SLOTS*2
|
| 14 |
+
|
| 15 |
+
class ISELStageV2(v1.ISELStage):
|
| 16 |
+
def __init__(self,cfg):
|
| 17 |
+
super().__init__({**cfg,'mode':'graph'}); self.cfg=cfg; self.mode=cfg['mode']; d=cfg['width']; self.use_latent=self.mode in ('copy','aligned_copy'); self.aligned=self.mode in ('aligned_copy','oracle_aligned')
|
| 18 |
+
self.src_op=nn.Embedding(len(ir.OPS),d); self.src_arg=nn.Embedding(ir.NVAL,d); self.src_bits=nn.Linear(32,d); self.src_slot=nn.Parameter(torch.randn(ir.SLOTS,d)*.02); self.src_role=nn.Parameter(torch.randn(2,d)*.02)
|
| 19 |
+
self.src_lat=nn.Linear(cfg['input_width'],d) if self.use_latent else None
|
| 20 |
+
self.src_norm=nn.LayerNorm(d); self.cq=nn.Linear(d,self.w*d); self.ck=nn.Linear(d,d); self.gate=nn.Linear(d,self.w); self.aq=nn.Linear(d,d); self.ak=nn.Linear(d,d)
|
| 21 |
+
def encode(self,h,so,sa,sv):
|
| 22 |
+
return super().encode(h if self.use_latent else torch.zeros_like(h),so,sa,sv)
|
| 23 |
+
def heads(self,h,source,so,sa,sv,details=False):
|
| 24 |
+
p,r,c=super().heads(h); b,s,d=h.shape
|
| 25 |
+
bits=((sv.unsqueeze(-1)>>torch.arange(32,device=h.device))&1).float()
|
| 26 |
+
keys=self.src_op(so).unsqueeze(2)+self.src_arg(sa)+self.src_bits(bits)+self.src_slot[:,None]+self.src_role
|
| 27 |
+
if self.use_latent: keys=keys+self.src_lat(source.float()).unsqueeze(2)
|
| 28 |
+
keys=self.src_norm(keys); q=self.cq(h).reshape(b,s,self.w,d)
|
| 29 |
+
logits=torch.einsum('bswd,bkd->bswk',q,self.ck(keys.flatten(1,2)))/math.sqrt(d)
|
| 30 |
+
# Only actual predicted IR constant operands with representable values.
|
| 31 |
+
flat=sv.flatten(1); matches=flat.unsqueeze(-1).eq(self.numbers[1:]); valid=sa.flatten(1).eq(ir.CONST)&matches.any(-1)&so.ne(0).unsqueeze(-1).expand(-1,-1,2).flatten(1)
|
| 32 |
+
ids=matches.long().argmax(-1)+1; ids=ids.masked_fill(~valid,0)
|
| 33 |
+
att=logits.masked_fill(~valid[:,None,None,:],-1e4).softmax(-1)*valid[:,None,None,:]
|
| 34 |
+
g=self.gate(h).sigmoid().unsqueeze(-1)*valid.any(-1)[:,None,None,None]
|
| 35 |
+
copy=torch.zeros_like(c).scatter_add(-1,ids[:,None,None,:].expand(b,s,self.w,K),att)
|
| 36 |
+
logp=((1-g)*c.softmax(-1)+g*copy).clamp_min(1e-12).log()
|
| 37 |
+
if not details: return p,r,logp
|
| 38 |
+
align=torch.einsum('bsd,btd->bst',self.aq(h),self.ak(keys.mean(2)))/math.sqrt(d)
|
| 39 |
+
align=align.masked_fill(~so.ne(0)[:,None,:],-1e4)
|
| 40 |
+
return (p,r,logp),g*att,align,valid
|
| 41 |
+
def forward(self,*x): return self.heads(self.encode(*x),*x)
|
neuro_compiler/neurocc_live_v2.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from torch import nn
|
| 10 |
+
|
| 11 |
+
from . import neurocc as nc
|
| 12 |
+
|
| 13 |
+
from . import neurocc_ir_unfolded as ir
|
| 14 |
+
|
| 15 |
+
from . import neurocc_backend_trace as bt
|
| 16 |
+
|
| 17 |
+
def require(condition, message):
|
| 18 |
+
if not condition:
|
| 19 |
+
raise ValueError(message)
|
| 20 |
+
|
| 21 |
+
class NeuralCompiler(nn.Module):
|
| 22 |
+
"""Exactly mirror the train/export interfaces, including FP16 boundaries."""
|
| 23 |
+
def __init__(self, backbone, ast_stage, ir_stage, isel_stage, regalloc_stage, binary_stage, dev):
|
| 24 |
+
super().__init__()
|
| 25 |
+
self.backbone = backbone
|
| 26 |
+
self.ast = ast_stage
|
| 27 |
+
self.ir = ir_stage
|
| 28 |
+
self.isel = isel_stage
|
| 29 |
+
self.regalloc = regalloc_stage
|
| 30 |
+
self.binary = binary_stage
|
| 31 |
+
self.dev = torch.device(dev)
|
| 32 |
+
self.eval().requires_grad_(False)
|
| 33 |
+
|
| 34 |
+
def isel_step(self, h, ip):
|
| 35 |
+
# V2 heads also consume the actual predicted SSA, including operand addresses.
|
| 36 |
+
m = self.isel.encode(h, *ip).half()
|
| 37 |
+
mp = self.isel.decode(self.isel.heads(m.float(), h, *ip))
|
| 38 |
+
return m, mp
|
| 39 |
+
|
| 40 |
+
def stages(self, ids, mask):
|
| 41 |
+
# Qwen cache was produced with CUDA FP16 autocast. Other stages were FP32.
|
| 42 |
+
with nc.amp(self.dev):
|
| 43 |
+
q = self.backbone(ids, mask)[0].half()
|
| 44 |
+
a = self.ast.encode(q, mask).half()
|
| 45 |
+
# The selected progressive IR chain is dependency AST -> unfolded IR.
|
| 46 |
+
h = self.ir.encode(a, None, None).half()
|
| 47 |
+
z = h.float()
|
| 48 |
+
n = len(z)
|
| 49 |
+
ip = ir.decode((self.ir.op(z), self.ir.args(z).reshape(n,ir.SLOTS,2,ir.NVAL),
|
| 50 |
+
self.ir.const(z).reshape(n,ir.SLOTS,2,4,256)))
|
| 51 |
+
m, mp = self.isel_step(h, ip)
|
| 52 |
+
r, mem, source_ids = self.regalloc.encode(m, *mp)
|
| 53 |
+
r = r.half()
|
| 54 |
+
rp = self.regalloc.decode(self.regalloc.heads(r.float(), mem, source_ids))
|
| 55 |
+
rm = torch.ones(r.shape[:2], dtype=torch.bool, device=r.device)
|
| 56 |
+
bp = self.binary.decode(self.binary(r, rm, *rp))
|
| 57 |
+
return bp, (a, h, ip, m, mp, r, rp)
|
| 58 |
+
|
| 59 |
+
def forward(self, ids, mask):
|
| 60 |
+
return self.stages(ids, mask)[0][-1]
|
| 61 |
+
|
| 62 |
+
def raw_bytes(row):
|
| 63 |
+
vals = row.tolist() if isinstance(row,torch.Tensor) else list(row)
|
| 64 |
+
if vals.count(nc.EOS)!=1:
|
| 65 |
+
return None
|
| 66 |
+
end=vals.index(nc.EOS)
|
| 67 |
+
if not end or any(not 0<=v<256 for v in vals[:end]) or any(v!=nc.PAD for v in vals[end+1:]):
|
| 68 |
+
return None
|
| 69 |
+
return bytes(vals[:end])
|
| 70 |
+
|
| 71 |
+
HEADER = re.compile(r'\s*unsigned\s+f\s*\(\s*unsigned\s+a\s*,\s*unsigned\s+b\s*,\s*unsigned\s+c\s*\)\s*\{\s*return\s+(.+?)\s*;\s*\}\s*',re.S)
|
| 72 |
+
|
| 73 |
+
TOKEN = re.compile(r'\s*(\d+u|[abc()+*^&|\-])')
|
| 74 |
+
|
| 75 |
+
OP = {'+':1,'-':2,'*':3,'^':4,'&':5,'|':6}
|
| 76 |
+
|
| 77 |
+
def evaluation_row(source, row_id):
|
| 78 |
+
m = HEADER.fullmatch(source)
|
| 79 |
+
if not m:
|
| 80 |
+
raise ValueError('Evaluation requires the original unsigned f(unsigned a,unsigned b,unsigned c) grammar.')
|
| 81 |
+
text=m.group(1).strip(); tokens=[]; p=0
|
| 82 |
+
while p<len(text):
|
| 83 |
+
t=TOKEN.match(text,p)
|
| 84 |
+
if not t: raise ValueError(f'Unsupported evaluation expression at offset {p}')
|
| 85 |
+
tokens.append(t.group(1)); p=t.end()
|
| 86 |
+
pos=0; op=[]; args=[]; vals=[]
|
| 87 |
+
def take():
|
| 88 |
+
nonlocal pos
|
| 89 |
+
if pos>=len(tokens): raise ValueError('Unexpected end of expression')
|
| 90 |
+
t=tokens[pos]; pos+=1; return t
|
| 91 |
+
def node(depth=0):
|
| 92 |
+
if depth>3: raise ValueError('Expression exceeds training depth 3')
|
| 93 |
+
t=take()
|
| 94 |
+
if t in ('a','b','c'): return ('abc'.index(t)+1,0)
|
| 95 |
+
if t.endswith('u') and t[:-1].isdigit():
|
| 96 |
+
v=int(t[:-1]); require(1<=v<=63,'Literal outside training range 1..63'); return (12,v)
|
| 97 |
+
require(t=='(','Expected fully parenthesized expression')
|
| 98 |
+
a=node(depth+1); k=take(); require(k in OP,'Expected binary operator'); b=node(depth+1); require(take()==')','Expected closing parenthesis')
|
| 99 |
+
j=len(op); op.append(OP[k]); args.append([a[0],b[0]]); vals.append([a[1],b[1]]); return (4+j,0)
|
| 100 |
+
a=node(); require(pos==len(tokens),'Trailing expression tokens')
|
| 101 |
+
op.append(7); args.append([a[0],0]); vals.append([a[1],0]); require(len(op)<=8,'Too many instructions')
|
| 102 |
+
while len(op)<8: op.append(0); args.append([0,0]); vals.append([0,0])
|
| 103 |
+
return row_id,op,args,vals
|
| 104 |
+
|
| 105 |
+
def verify_outputs(sources, ids, y, samples, seed):
|
| 106 |
+
import capstone
|
| 107 |
+
from unicorn import UcError
|
| 108 |
+
md=capstone.Cs(capstone.CS_ARCH_X86,capstone.CS_MODE_64)
|
| 109 |
+
allowed={'mov','or','sub','add','and','ret','imul','xor','shl','sal'}
|
| 110 |
+
# Include standard edge cases, then fresh reproducible random inputs.
|
| 111 |
+
xs=bt.samples(min(8,samples)); rng=random.Random(seed)
|
| 112 |
+
xs.extend(tuple(rng.getrandbits(32) for _ in range(3)) for _ in range(samples-len(xs)))
|
| 113 |
+
entries=[]
|
| 114 |
+
for s,i,v in zip(sources,ids,y):
|
| 115 |
+
row=evaluation_row(s,i); raw=raw_bytes(v); decoded=False; success=False; reason=None
|
| 116 |
+
try:
|
| 117 |
+
if raw is None: raise ValueError('Invalid byte serialization')
|
| 118 |
+
ins=list(md.disasm(raw,0))
|
| 119 |
+
if not ins or sum(x.size for x in ins)!=len(raw) or any(x.mnemonic not in allowed for x in ins) or ins[-1].mnemonic!='ret' or any(x.mnemonic=='ret' for x in ins[:-1]):
|
| 120 |
+
raise ValueError('Not a supported complete straight-line function')
|
| 121 |
+
decoded=True; bt.verify_binary(raw,row,xs); success=True
|
| 122 |
+
except (ValueError,UcError) as e:
|
| 123 |
+
reason=str(e)
|
| 124 |
+
entries.append(dict(row=i,source=s,hex=raw.hex(' ') if raw else None,disassembled=decoded,semantic=success,error=reason))
|
| 125 |
+
return entries
|
| 126 |
+
|
| 127 |
+
def summarize(entries):
|
| 128 |
+
n=len(entries)
|
| 129 |
+
return dict(functions=n,serializable=sum(x['hex'] is not None for x in entries)/n,fully_disassembled=sum(x['disassembled'] for x in entries)/n,semantic_accuracy=sum(x['semantic'] for x in entries)/n,semantic_correct=sum(x['semantic'] for x in entries))
|
neuro_compiler/neurocc_regalloc.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from torch import nn
|
| 8 |
+
|
| 9 |
+
from . import neurocc_ast as ast
|
| 10 |
+
|
| 11 |
+
class RegisterStage(nn.Module):
|
| 12 |
+
def __init__(self,cfg):
|
| 13 |
+
super().__init__(); self.cfg=cfg; d=cfg['width']; self.s=cfg['slots']; self.w=cfg['operands']; self.mode=cfg['mode']; self.use_graph=self.mode!='direct'; self.use_latent=self.mode not in ('discrete_copy','oracle_copy'); self.copy=self.mode.endswith('copy'); self.ps=cfg['pre_slots']; self.pw=cfg['pre_operands']; self.nnumbers=len(cfg['immediate_vocab'])+1
|
| 14 |
+
self.proj=nn.Linear(cfg['input_width'],d) if self.use_latent else None
|
| 15 |
+
self.pos=nn.Parameter(torch.randn(self.ps,d)*.02); self.memnorm=nn.LayerNorm(d)
|
| 16 |
+
if self.use_graph:
|
| 17 |
+
self.source_sig=nn.Embedding(len(cfg['pre_vocab']),d); self.source_ref=nn.Embedding(self.ps+1,16); self.source_num=nn.Embedding(self.nnumbers,16); self.source_operands=nn.Linear(self.pw*32,d)
|
| 18 |
+
self.query=nn.Parameter(torch.randn(self.s,d)*.02); self.blocks=nn.ModuleList([ast.Block(d,cfg['heads'],cfg['dropout'],True) for _ in range(cfg['layers'])]); self.norm=nn.LayerNorm(d)
|
| 19 |
+
self.sig=nn.Linear(d,len(cfg['vocab'])); self.reg=nn.Linear(d,self.w*len(cfg['register_vocab'])); self.num=nn.Linear(d,self.w*self.nnumbers); self.stack=nn.Linear(d,self.w*(len(cfg['stack_vocab'])+1))
|
| 20 |
+
if self.copy:
|
| 21 |
+
self.copy_q=nn.Linear(d,self.w*d); self.copy_k=nn.Linear(d,d); self.copy_num=nn.Embedding(self.nnumbers,d); self.copy_pos=nn.Parameter(torch.randn(self.pw,d)*.02); self.gate=nn.Linear(d,self.w)
|
| 22 |
+
for key in ('reg','imm','stack'):
|
| 23 |
+
self.register_buffer(key+'mask',torch.tensor(cfg['signature_'+key+'_mask'],dtype=torch.bool),persistent=False)
|
| 24 |
+
self.register_buffer('pre_cm',torch.tensor(cfg['pre_imm_mask'],dtype=torch.bool),persistent=False)
|
| 25 |
+
self.register_buffer('numbers',torch.tensor([0]+cfg['immediate_vocab'],dtype=torch.long),persistent=False)
|
| 26 |
+
self.register_buffer('stacks',torch.tensor([0]+cfg['stack_vocab'],dtype=torch.long),persistent=False)
|
| 27 |
+
def source_ids(self,sig,imm):
|
| 28 |
+
# The compact literal vocabulary is a representation lookup, not an ALU.
|
| 29 |
+
matches=imm.unsqueeze(-1).eq(self.numbers[1:]); ids=(matches.long().argmax(-1)+1).masked_fill(~matches.any(-1),0); return ids.masked_fill(~self.pre_cm[sig],0)
|
| 30 |
+
def encode(self,h,sig,ref,imm):
|
| 31 |
+
m=self.pos.unsqueeze(0).expand(len(h),-1,-1)
|
| 32 |
+
if self.use_latent: m=m+self.proj(h.float())
|
| 33 |
+
ids=self.source_ids(sig,imm)
|
| 34 |
+
if self.use_graph:
|
| 35 |
+
m=m+self.source_sig(sig)+self.source_operands(torch.cat((self.source_ref(ref),self.source_num(ids)),-1).flatten(2))
|
| 36 |
+
m=self.memnorm(m); q=self.query.unsqueeze(0).expand(len(h),-1,-1); mask=torch.ones(m.shape[:2],dtype=torch.bool,device=m.device)
|
| 37 |
+
for block in self.blocks: q=block(q,m,mask)
|
| 38 |
+
return self.norm(q),m,ids
|
| 39 |
+
def heads(self,z,m,ids):
|
| 40 |
+
b,s,d=z.shape; p=self.sig(z); r=self.reg(z).reshape(b,s,self.w,-1); c=self.num(z).reshape(b,s,self.w,-1); a=self.stack(z).reshape(b,s,self.w,-1)
|
| 41 |
+
r=r.masked_fill(torch.arange(r.shape[-1],device=z.device)<2,-1e4); c=c.masked_fill(torch.arange(c.shape[-1],device=z.device)==0,-1e4); a=a.masked_fill(torch.arange(a.shape[-1],device=z.device)==0,-1e4)
|
| 42 |
+
if self.copy:
|
| 43 |
+
keys=self.copy_k(m.unsqueeze(2)+self.copy_num(ids)+self.copy_pos).flatten(1,2); query=self.copy_q(z).reshape(b,s,self.w,d); flat=ids.flatten(1); valid=flat.ne(0)
|
| 44 |
+
attn=torch.einsum('bswd,bkd->bswk',query,keys)/math.sqrt(d); attn=attn.masked_fill(~valid[:,None,None,:],-1e4); probs=attn.softmax(-1)*valid[:,None,None,:]; copy_probs=torch.zeros_like(c).scatter_add(-1,flat[:,None,None,:].expand(b,s,self.w,-1),probs); gate=self.gate(z).sigmoid().unsqueeze(-1)*valid.any(-1)[:,None,None,None]; c=((1-gate)*c.softmax(-1)+gate*copy_probs).clamp_min(1e-12).log()
|
| 45 |
+
return p,r,c,a
|
| 46 |
+
def forward(self,*x): return self.heads(*self.encode(*x))
|
| 47 |
+
def decode(self,out):
|
| 48 |
+
p,r,c,a=out; s=p.argmax(-1); return s,r.argmax(-1).masked_fill(~self.regmask[s],0),self.numbers[c.argmax(-1)].masked_fill(~self.immmask[s],0),self.stacks[a.argmax(-1)].masked_fill(~self.stackmask[s],0)
|
neuro_compiler/neurocc_regalloc_v2.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import math
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from . import neurocc_regalloc as v1
|
| 8 |
+
|
| 9 |
+
class RegisterStageV2(v1.RegisterStage):
|
| 10 |
+
"""Identical v1 copy architecture, with optional supervised copy addresses.
|
| 11 |
+
Both discrete and hybrid modes share the same categorical fallback head.
|
| 12 |
+
"""
|
| 13 |
+
def __init__(self,cfg):
|
| 14 |
+
mode=cfg['mode']; base={'aligned_copy':'copy','discrete_aligned':'discrete_copy'}.get(mode,mode)
|
| 15 |
+
super().__init__({**cfg,'mode':base}); self.cfg=cfg; self.mode=mode; self.aligned=mode in ('aligned_copy','discrete_aligned')
|
| 16 |
+
def heads(self,z,m,ids,details=False):
|
| 17 |
+
b,s,d=z.shape; p=self.sig(z); r=self.reg(z).reshape(b,s,self.w,-1); c=self.num(z).reshape(b,s,self.w,-1); a=self.stack(z).reshape(b,s,self.w,-1)
|
| 18 |
+
r=r.masked_fill(torch.arange(r.shape[-1],device=z.device)<2,-1e4); c=c.masked_fill(torch.arange(c.shape[-1],device=z.device)==0,-1e4); a=a.masked_fill(torch.arange(a.shape[-1],device=z.device)==0,-1e4)
|
| 19 |
+
keys=self.copy_k(m.unsqueeze(2)+self.copy_num(ids)+self.copy_pos).flatten(1,2); query=self.copy_q(z).reshape(b,s,self.w,d); flat=ids.flatten(1); valid=flat.ne(0)
|
| 20 |
+
attn=torch.einsum('bswd,bkd->bswk',query,keys)/math.sqrt(d); attn=attn.masked_fill(~valid[:,None,None,:],-1e4); probs=attn.softmax(-1)*valid[:,None,None,:]
|
| 21 |
+
cp=torch.zeros_like(c).scatter_add(-1,flat[:,None,None,:].expand(b,s,self.w,-1),probs); gate=self.gate(z).sigmoid().unsqueeze(-1)*valid.any(-1)[:,None,None,None]; c=((1-gate)*c.softmax(-1)+gate*cp).clamp_min(1e-12).log()
|
| 22 |
+
out=(p,r,c,a)
|
| 23 |
+
return (out,gate*probs,flat) if details else out
|
neuro_compiler/verification.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Optional evaluation only: never repairs predictions or executes them natively."""
|
| 2 |
+
import torch
|
| 3 |
+
from .neurocc_live_v2 import verify_outputs
|
| 4 |
+
from . import neurocc as nc
|
| 5 |
+
|
| 6 |
+
def verify(source,machine_code,samples=32,seed=20261125):
|
| 7 |
+
if samples<1: raise ValueError('samples must be positive')
|
| 8 |
+
if not machine_code: raise ValueError('Empty machine code')
|
| 9 |
+
row=torch.tensor([*machine_code,nc.EOS],dtype=torch.long)
|
| 10 |
+
return verify_outputs([source],[0],[row],samples,seed)[0]
|
pyproject.toml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["setuptools>=70"]
|
| 3 |
+
build-backend = "setuptools.build_meta"
|
| 4 |
+
|
| 5 |
+
[project]
|
| 6 |
+
name = "neuro_compiler"
|
| 7 |
+
version = "0.1.0.dev0"
|
| 8 |
+
description = "Experimental non-autoregressive neural compiler for restricted unsigned expressions"
|
| 9 |
+
license = "Apache-2.0"
|
| 10 |
+
requires-python = ">=3.10"
|
| 11 |
+
dependencies = ["torch>=2.4", "transformers==4.57.6", "safetensors>=0.4", "huggingface-hub>=0.36,<1"]
|
| 12 |
+
|
| 13 |
+
[project.optional-dependencies]
|
| 14 |
+
evaluation = ["capstone==5.0.9", "unicorn==2.1.4"]
|
| 15 |
+
dev = ["pytest>=8", "build>=1"]
|
| 16 |
+
|
| 17 |
+
[project.scripts]
|
| 18 |
+
neuro-compiler = "neuro_compiler.cli:main"
|
| 19 |
+
|
| 20 |
+
[tool.setuptools.packages.find]
|
| 21 |
+
include = ["neuro_compiler*"]
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.4
|
| 2 |
+
transformers==4.57.6
|
| 3 |
+
safetensors>=0.4
|
| 4 |
+
huggingface-hub>=0.36,<1
|
tests/test_contract.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
import torch
|
| 3 |
+
from neuro_compiler import NeuralCompiler
|
| 4 |
+
from neuro_compiler.neurocc_live_v2 import raw_bytes
|
| 5 |
+
|
| 6 |
+
class Contracts(unittest.TestCase):
|
| 7 |
+
def test_serialization_rejects_malformed_output(self):
|
| 8 |
+
for row in ([195,257,257],[195,256],[257],[195,257,0],[999,257]):
|
| 9 |
+
self.assertIsNone(raw_bytes(torch.tensor(row)))
|
| 10 |
+
self.assertEqual(raw_bytes(torch.tensor([195,257,256])),b'\xc3')
|
| 11 |
+
|
| 12 |
+
def test_input_errors_before_model_execution(self):
|
| 13 |
+
compiler=NeuralCompiler(); compiler.spec={'tokens':96}
|
| 14 |
+
for source in ('', 'a'*193, 'while(a){}'):
|
| 15 |
+
with self.assertRaises(ValueError): compiler.predict([source])
|
| 16 |
+
with self.assertRaises(TypeError): compiler.compile_batch('source')
|
| 17 |
+
self.assertEqual(compiler.compile_batch([]),[])
|
| 18 |
+
|
| 19 |
+
if __name__=='__main__': unittest.main()
|
weights/ast.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dafa71eebb5df2a12d2e9e3e5e30f709d29f464216e6296cc90c14d523a0fbe5
|
| 3 |
+
size 2897832
|
weights/binary.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68ae6851185af7a5e5c065c5e63b3194238addf9112547c0db88e31e18a33298
|
| 3 |
+
size 3331152
|
weights/isel.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52aab4ecc660021293b31af0bbe83910e3d41d31ed6318dbec64663a1d5d9fb4
|
| 3 |
+
size 3228664
|
weights/regalloc.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f2b58158bfcc4c132136f3666960e4314cba0e7ba9b96a4bcf6e3ceec199790d
|
| 3 |
+
size 3029992
|
weights/ssa.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e0d0118568df34557704db780fb63e16b1682c2003a6e30b3fd8a42596155497
|
| 3 |
+
size 3275072
|