Commit ·
c5cfd97
0
Parent(s):
WebBrain Compass Tiny XS v3 release
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +36 -0
- FILES.sha256.json +304 -0
- LICENSE +202 -0
- NAMING.json +7 -0
- README.md +133 -0
- chat_template.jinja +110 -0
- config.json +77 -0
- generation_config.json +14 -0
- graph-abi.json +135 -0
- onnx/model_fp16.onnx +3 -0
- onnx/model_fp16.onnx_data +3 -0
- provenance/bf16-upload-verified.json +1 -0
- provenance/browser-validation.json +502 -0
- provenance/context-validation.json +95 -0
- provenance/contract.json +1 -0
- provenance/failed-candidates/onnx-v3-context-4096.json +44 -0
- provenance/failed-candidates/onnx-v3-context-8192.json +44 -0
- provenance/failed-candidates/onnx-v4-contexts.json +95 -0
- provenance/fixtures.json +1 -0
- provenance/gpu-identity.json +1 -0
- provenance/numerical-validation.json +1 -0
- provenance/precision-correction.json +237 -0
- provenance/scripts/export_spark.py +232 -0
- provenance/scripts/promote_attention.py +76 -0
- provenance/scripts/validate_browser.py +77 -0
- provenance/scripts/validate_context.py +71 -0
- provenance/scripts/validate_saved_context.py +46 -0
- runtime/browser_runtime.js +94 -0
- runtime/browser_service.py +186 -0
- runtime/compass_dxgi_5090.py +33 -0
- runtime/openai_server.py +186 -0
- runtime/vendor/LICENSE.onnxruntime.txt +21 -0
- runtime/vendor/LICENSE.transformers.txt +202 -0
- runtime/vendor/README.md +162 -0
- runtime/vendor/ThirdPartyNotices.onnxruntime.txt +0 -0
- runtime/vendor/onnxruntime-common/backend-impl.js +142 -0
- runtime/vendor/onnxruntime-common/backend.js +4 -0
- runtime/vendor/onnxruntime-common/env-impl.js +25 -0
- runtime/vendor/onnxruntime-common/env.js +8 -0
- runtime/vendor/onnxruntime-common/index.js +27 -0
- runtime/vendor/onnxruntime-common/inference-session-impl.js +208 -0
- runtime/vendor/onnxruntime-common/inference-session.js +6 -0
- runtime/vendor/onnxruntime-common/onnx-model.js +4 -0
- runtime/vendor/onnxruntime-common/onnx-value.js +4 -0
- runtime/vendor/onnxruntime-common/tensor-conversion-impl.js +195 -0
- runtime/vendor/onnxruntime-common/tensor-conversion.js +4 -0
- runtime/vendor/onnxruntime-common/tensor-factory-impl.js +265 -0
- runtime/vendor/onnxruntime-common/tensor-factory.js +4 -0
- runtime/vendor/onnxruntime-common/tensor-impl-type-mapping.js +58 -0
- runtime/vendor/onnxruntime-common/tensor-impl.js +366 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
+
onnx/model_fp16.onnx_data filter=lfs diff=lfs merge=lfs -text
|
FILES.sha256.json
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"files": [
|
| 3 |
+
{
|
| 4 |
+
"path": "chat_template.jinja",
|
| 5 |
+
"bytes": 4758,
|
| 6 |
+
"sha256": "f9ace5b72165a4d2abb486b73f07b279cbe38bf9e70e66500c095b270966d24f"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"path": "config.json",
|
| 10 |
+
"bytes": 1970,
|
| 11 |
+
"sha256": "708b5a8c5d64d57d1ae5ceb82c4fc1ca9f2e2769a02d7a7b95ef1e02a98b92c2"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"path": "generation_config.json",
|
| 15 |
+
"bytes": 296,
|
| 16 |
+
"sha256": "5b77f2b5603cd2e3950df71bce8a6d1493ad97e7b6cfbba171eade2e9503224c"
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"path": "graph-abi.json",
|
| 20 |
+
"bytes": 3544,
|
| 21 |
+
"sha256": "a3f88b1dca10b26478b0b83afaefbe5c984f5af475f916af24cf411224572980"
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "LICENSE",
|
| 25 |
+
"bytes": 11338,
|
| 26 |
+
"sha256": "525c465ab952779d2d360a9ff36f7f49ae018a23d80302ff839a850a77784c36"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"path": "onnx/model_fp16.onnx",
|
| 30 |
+
"bytes": 1454092,
|
| 31 |
+
"sha256": "7b3095d0b51cc8aecc0aea0eb82869efa16039d358548e61fc461b5622a73819"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"path": "onnx/model_fp16.onnx_data",
|
| 35 |
+
"bytes": 3952418816,
|
| 36 |
+
"sha256": "9abbd8c7e69fbdb9bb4fe6244c30b66a397a4f237dbfc75e95dd11062db3acdc"
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"path": "provenance/bf16-upload-verified.json",
|
| 40 |
+
"bytes": 312,
|
| 41 |
+
"sha256": "06e48338a8be6484e5f3b2deda1997f36bd76533124fc596586d28eac06f1a0d"
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"path": "provenance/browser-validation.json",
|
| 45 |
+
"bytes": 16000,
|
| 46 |
+
"sha256": "fb169075cfa3a63f550b7e322a30d0596f4f5c71012da1d5cf586ebc9859bf20"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"path": "provenance/context-validation.json",
|
| 50 |
+
"bytes": 2500,
|
| 51 |
+
"sha256": "0e16a6b217c2ffb89f5cabd70f560f05a307f753f2131fa9fb7d2097f214faa9"
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"path": "provenance/contract.json",
|
| 55 |
+
"bytes": 2004,
|
| 56 |
+
"sha256": "ec649239e8ef225665ee295858cb4fb60b30fc525a0de21d56957555c4edbbf4"
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"path": "provenance/failed-candidates/onnx-v3-context-4096.json",
|
| 60 |
+
"bytes": 939,
|
| 61 |
+
"sha256": "43a08c51cfa8a1cf2435a0d4d095455e0596e070902310e5f9e530ad9324fd9d"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"path": "provenance/failed-candidates/onnx-v3-context-8192.json",
|
| 65 |
+
"bytes": 939,
|
| 66 |
+
"sha256": "b9e9077d61d60a0e415aa193784f45ab210be17b527624d2bcdb380cbecf8edd"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"path": "provenance/failed-candidates/onnx-v4-contexts.json",
|
| 70 |
+
"bytes": 2503,
|
| 71 |
+
"sha256": "067776c171d58a258f34ea4b29e27b700593ded393c44328b3c3d1717abe4d32"
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"path": "provenance/fixtures.json",
|
| 75 |
+
"bytes": 7757,
|
| 76 |
+
"sha256": "1049d220412576e62af8b365ee072902717576c2407803b3ddbbb4fbd0b720af"
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
"path": "provenance/gpu-identity.json",
|
| 80 |
+
"bytes": 269,
|
| 81 |
+
"sha256": "c18ba6c02ac63f1ab4f27ceba8ef10839e63a1c64a22924c566ebf888a442376"
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"path": "provenance/numerical-validation.json",
|
| 85 |
+
"bytes": 2074,
|
| 86 |
+
"sha256": "52049a0e94ac0352bd2c27899f6cf8550d607b8227aaf37f2b98ca0f8d331434"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"path": "provenance/precision-correction.json",
|
| 90 |
+
"bytes": 9730,
|
| 91 |
+
"sha256": "8c5b8b0d5a1f902816167489f5b596e24b5d6a06d96f3a7a695bd81cdfa643df"
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"path": "provenance/scripts/export_spark.py",
|
| 95 |
+
"bytes": 12095,
|
| 96 |
+
"sha256": "d910e7633cbb84871e68fc9fdff7296a3f97a7db3669f696859f6f14886ad320"
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"path": "provenance/scripts/promote_attention.py",
|
| 100 |
+
"bytes": 3720,
|
| 101 |
+
"sha256": "452cb4d806625b384ce7f7053868788f94018a5d08dab97d34cc92f0035a51a6"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"path": "provenance/scripts/validate_browser.py",
|
| 105 |
+
"bytes": 4277,
|
| 106 |
+
"sha256": "b42f035eefe9591406ec30ad27ca8bf956d010998d390078a644e929b329bc7d"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"path": "provenance/scripts/validate_context.py",
|
| 110 |
+
"bytes": 4069,
|
| 111 |
+
"sha256": "b3f4f0e0e48b74a774234f5186301ded61286310e3d034eb7344adf57ec38748"
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"path": "provenance/scripts/validate_saved_context.py",
|
| 115 |
+
"bytes": 2375,
|
| 116 |
+
"sha256": "bd0682248c08aaed0d6b6e4b772af180c2471194a57b5f4c67f7d9c512f011f6"
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"path": "README.md",
|
| 120 |
+
"bytes": 6686,
|
| 121 |
+
"sha256": "c6e3af0346de371a46fa7a47c3921f74348a1420a5c76236c04fdc074de5ef22"
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"path": "runtime/browser_runtime.js",
|
| 125 |
+
"bytes": 4677,
|
| 126 |
+
"sha256": "9e4fab1aed1be7e0004b6bafaa6cc970abc5bc0be5df45500f0bc0d8479a5040"
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"path": "runtime/browser_service.py",
|
| 130 |
+
"bytes": 10269,
|
| 131 |
+
"sha256": "a777df7ad3062cad64e8bfe6de1a863b99cd359d34ef7e69141cbe382079f603"
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"path": "runtime/compass_dxgi_5090.py",
|
| 135 |
+
"bytes": 1939,
|
| 136 |
+
"sha256": "0e5f75a3e5aec9e3e4d97619c500d7fea7cc186db7fece3f4fb688a5ff487eb7"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"path": "runtime/openai_server.py",
|
| 140 |
+
"bytes": 8899,
|
| 141 |
+
"sha256": "318299640f01fcac32c6037d027eda0ddd523936c78dce24bbdedc60e2b8f099"
|
| 142 |
+
},
|
| 143 |
+
{
|
| 144 |
+
"path": "runtime/vendor/LICENSE.onnxruntime.txt",
|
| 145 |
+
"bytes": 1073,
|
| 146 |
+
"sha256": "2f07c72751aed99790b8a4869cf2311df85a860b22ded05fa22803587a48922c"
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"path": "runtime/vendor/LICENSE.transformers.txt",
|
| 150 |
+
"bytes": 11358,
|
| 151 |
+
"sha256": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"path": "runtime/vendor/onnxruntime-common/backend-impl.js",
|
| 155 |
+
"bytes": 5339,
|
| 156 |
+
"sha256": "97dd81b055a06f61120f09468fe59f046a9262b7b87bf5d05bceb085bf4f5558"
|
| 157 |
+
},
|
| 158 |
+
{
|
| 159 |
+
"path": "runtime/vendor/onnxruntime-common/backend.js",
|
| 160 |
+
"bytes": 184,
|
| 161 |
+
"sha256": "017ce2ec9dc2021ebc1ef2c4f04e1bc74276c65921b0297e7ed8cc16e640495b"
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
"path": "runtime/vendor/onnxruntime-common/env-impl.js",
|
| 165 |
+
"bytes": 848,
|
| 166 |
+
"sha256": "0da4c562a49fe147e19320a64cbb456184eb0e6242b1fe69c65c8368c55f3d97"
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
"path": "runtime/vendor/onnxruntime-common/env.js",
|
| 170 |
+
"bytes": 262,
|
| 171 |
+
"sha256": "b2bbd3d3b00a95765713c57cd0f5ef73718ae5b8322e07cb47a43e2accb21f15"
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"path": "runtime/vendor/onnxruntime-common/index.js",
|
| 175 |
+
"bytes": 1036,
|
| 176 |
+
"sha256": "ad23f6d6ce2c99c449031f24a5181f259516c64a9a67428c98a8539b857729bd"
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"path": "runtime/vendor/onnxruntime-common/inference-session-impl.js",
|
| 180 |
+
"bytes": 8703,
|
| 181 |
+
"sha256": "0446814a392c147b5c38ba242d9911ee54002b5d01a8e19fb4895fb8f8a0cdd3"
|
| 182 |
+
},
|
| 183 |
+
{
|
| 184 |
+
"path": "runtime/vendor/onnxruntime-common/inference-session.js",
|
| 185 |
+
"bytes": 348,
|
| 186 |
+
"sha256": "3ad4271a88edb3d242dc1e0e7bbf66510f9a56eff874c433b3b37f900ac007b1"
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"path": "runtime/vendor/onnxruntime-common/onnx-model.js",
|
| 190 |
+
"bytes": 145,
|
| 191 |
+
"sha256": "9e9dc8678be0ea04575a542894508db355a4f9f2155ac7f4c17a697c5f843382"
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"path": "runtime/vendor/onnxruntime-common/onnx-value.js",
|
| 195 |
+
"bytes": 145,
|
| 196 |
+
"sha256": "33dc232498753fc9026dfa44c99440cb1a6d29f3e53e1ad2fb8b696705158f06"
|
| 197 |
+
},
|
| 198 |
+
{
|
| 199 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-conversion-impl.js",
|
| 200 |
+
"bytes": 7852,
|
| 201 |
+
"sha256": "df6fa3cd1813c2d3e588cc07973cfe5ea2ab8647c957168200caa58e51440161"
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-conversion.js",
|
| 205 |
+
"bytes": 152,
|
| 206 |
+
"sha256": "8c43ec1d061ab71032a1b28f45d85ef95f8d7bd2d4cd71d059e96d83e3a8f422"
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-factory-impl.js",
|
| 210 |
+
"bytes": 11002,
|
| 211 |
+
"sha256": "cf5606fe23461e01bff59c2d72ac47d74e652548718f1e5fab07a22b441379b4"
|
| 212 |
+
},
|
| 213 |
+
{
|
| 214 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-factory.js",
|
| 215 |
+
"bytes": 149,
|
| 216 |
+
"sha256": "68b9f4f4573f25012ce8a4f73c9a2cee3a28db91de8bbb0a20ddb08bcba33c4b"
|
| 217 |
+
},
|
| 218 |
+
{
|
| 219 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-impl-type-mapping.js",
|
| 220 |
+
"bytes": 2706,
|
| 221 |
+
"sha256": "20bd5ddb858954cf071bace6c7a6628c8e311433798ec172f4c778bebd81d407"
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-impl.js",
|
| 225 |
+
"bytes": 16091,
|
| 226 |
+
"sha256": "6a749be63055f9d21069566b1515412484a3a03448ca20427c8f8d29328a2843"
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-utils-impl.js",
|
| 230 |
+
"bytes": 1920,
|
| 231 |
+
"sha256": "87d3e07c153616138c2f57846545eea9c47957c714d50c0264696bdc293e6732"
|
| 232 |
+
},
|
| 233 |
+
{
|
| 234 |
+
"path": "runtime/vendor/onnxruntime-common/tensor-utils.js",
|
| 235 |
+
"bytes": 147,
|
| 236 |
+
"sha256": "7acfdb2f8403ae84b7ae62d55d6eeb01519108be8874337b317b911ed60190cd"
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"path": "runtime/vendor/onnxruntime-common/tensor.js",
|
| 240 |
+
"bytes": 286,
|
| 241 |
+
"sha256": "721d24a538de5333057bfc423bc00c3453a1c483f4495c857d0a6f9b8f2d330e"
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"path": "runtime/vendor/onnxruntime-common/trace.js",
|
| 245 |
+
"bytes": 1891,
|
| 246 |
+
"sha256": "9b87e6309a1c502b03558aa94b0a65c8ea1e8eb59cb46090f54f6eacd191b841"
|
| 247 |
+
},
|
| 248 |
+
{
|
| 249 |
+
"path": "runtime/vendor/onnxruntime-common/type-helper.js",
|
| 250 |
+
"bytes": 146,
|
| 251 |
+
"sha256": "3e2588c6a5ee7b9755e199eef10c6aa2e777d0366ea47d27953657a5638deeae"
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"path": "runtime/vendor/onnxruntime-common/version.js",
|
| 255 |
+
"bytes": 263,
|
| 256 |
+
"sha256": "00a18ffb867b29a3855fe00e965797dba270849134f1e0ab2929fb2761c0fe44"
|
| 257 |
+
},
|
| 258 |
+
{
|
| 259 |
+
"path": "runtime/vendor/ort-wasm-simd-threaded.asyncify.mjs",
|
| 260 |
+
"bytes": 47507,
|
| 261 |
+
"sha256": "7236653b8565da4046e459cd0e274123419a1d9f1f8f18fd36c28058346ca655"
|
| 262 |
+
},
|
| 263 |
+
{
|
| 264 |
+
"path": "runtime/vendor/ort-wasm-simd-threaded.asyncify.wasm",
|
| 265 |
+
"bytes": 24254953,
|
| 266 |
+
"sha256": "7e83cd6cee77e478bc96a7e91b198144fb5e4126287daf1f9b54bb195ebcd55a"
|
| 267 |
+
},
|
| 268 |
+
{
|
| 269 |
+
"path": "runtime/vendor/ort.webgpu.mjs",
|
| 270 |
+
"bytes": 679694,
|
| 271 |
+
"sha256": "177cf67f3e6c25e951a76a981a857e6af53b1571016685cc2480e1e6e47b1d46"
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"path": "runtime/vendor/README.md",
|
| 275 |
+
"bytes": 8373,
|
| 276 |
+
"sha256": "a3b6d952b825a7382f16f89c1431e57090e6c3c2d1267ce1548069c802c103c7"
|
| 277 |
+
},
|
| 278 |
+
{
|
| 279 |
+
"path": "runtime/vendor/ThirdPartyNotices.onnxruntime.txt",
|
| 280 |
+
"bytes": 325054,
|
| 281 |
+
"sha256": "0e07b95f3a8d6230037707c5c4a2b554d12c4cb67369669ac255635528ffcee2"
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"path": "runtime/vendor/transformers.web.js",
|
| 285 |
+
"bytes": 1099925,
|
| 286 |
+
"sha256": "83e3edd00c98fef962da9bdc22fe4b63b3858743a76c1b7e46bee8e483033644"
|
| 287 |
+
},
|
| 288 |
+
{
|
| 289 |
+
"path": "tokenizer.json",
|
| 290 |
+
"bytes": 10115785,
|
| 291 |
+
"sha256": "f71f91ee1b2ac0b27e47bf49ee4859d322ab3d191217ec9964d0189b02454c49"
|
| 292 |
+
},
|
| 293 |
+
{
|
| 294 |
+
"path": "tokenizer_config.json",
|
| 295 |
+
"bytes": 402,
|
| 296 |
+
"sha256": "cf3dc83b97ec9c1d553a5e06045b8a5b627d4554018fa1abad5de95bc767a905"
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"path": "NAMING.json",
|
| 300 |
+
"bytes": 247,
|
| 301 |
+
"sha256": "a4f2ac63f48a4f3d6d5d1a04faaa0acfc0ebe7ffa5a175424cc9cd399eb2fb23"
|
| 302 |
+
}
|
| 303 |
+
]
|
| 304 |
+
}
|
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 2026 XHToken
|
| 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.
|
NAMING.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"displayName": "WebBrain Compass Tiny XS v3",
|
| 3 |
+
"previousRepoId": "webbrain-one/webbrain-compass-tiny-v3-onnx",
|
| 4 |
+
"repoId": "webbrain-one/webbrain-compass-tiny-xs-v3-onnx",
|
| 5 |
+
"metadataOnly": true,
|
| 6 |
+
"modelRuntimeAndTokenizerUnchanged": true
|
| 7 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: noncommercial-research-only
|
| 4 |
+
license_link: https://huggingface.co/webbrain-one/webbrain-compass-tiny-xs-v3-onnx/blob/main/README.md#license
|
| 5 |
+
base_model: webbrain-one/webbrain-compass-tiny-xs-v3
|
| 6 |
+
tags:
|
| 7 |
+
- onnx
|
| 8 |
+
- webgpu
|
| 9 |
+
- tool-calling
|
| 10 |
+
- spark
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# WebBrain Compass Tiny XS v3 — ONNX/WebGPU
|
| 14 |
+
|
| 15 |
+
WebBrain Compass Tiny XS v3 (ONNX/WebGPU) is a compact language model optimized for low-latency decision making, structured tool use, and in-browser agentic execution inside the WebBrain runtime.
|
| 16 |
+
|
| 17 |
+
Fine-tuned from **Spark-X2.5-1.7B (~1.7B parameters)** via `webbrain-one/webbrain-compass-tiny-xs-v3`, this release provides an export/runtime package delivering browser-native WebGPU execution with FP16 weights and FP32 matrix multiplication compute.
|
| 18 |
+
|
| 19 |
+
It unifies three core WebBrain behavioral modes:
|
| 20 |
+
|
| 21 |
+
1. **Ask & Clarify** — Answer directly or request missing information when execution is underspecified or unnecessary.
|
| 22 |
+
2. **Direct Compact Tool Execution** — Select exact browser tools and generate grounded arguments for low-latency accessibility-tree actions.
|
| 23 |
+
3. **Safe Escalation & Abstention** — Refuse, pause, or defer to higher execution tiers when actions lack adequate grounding or violate safety boundaries.
|
| 24 |
+
|
| 25 |
+
> **Note:** Display/repository name is **WebBrain Compass Tiny XS v3** (a metadata-only rename of the tested ONNX package). The bundled runtime exposes `webbrain-compass-tiny-v3-onnx-fp16` as its model ID.
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## Role in WebBrain
|
| 30 |
+
|
| 31 |
+
```text
|
| 32 |
+
User request
|
| 33 |
+
│
|
| 34 |
+
▼
|
| 35 |
+
WebBrain observation & policy layer
|
| 36 |
+
│
|
| 37 |
+
▼
|
| 38 |
+
WebBrain Compass Tiny XS v3 (WebGPU / ONNX)
|
| 39 |
+
├─ Clarify or answer directly
|
| 40 |
+
├─ Emit grounded browser tool call
|
| 41 |
+
└─ Abstain / safely escalate when execution is ungrounded
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
The outer WebBrain runtime enforces tool-schema validation, evidence and parameter grounding, destination URL verification, browser-state freshness, and sandboxed security policies. Model output is never proof that an external action succeeded.
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## Intended Capabilities
|
| 49 |
+
|
| 50 |
+
- **Browser Action Selection:** Grounded accessibility-tree interactions and structured function calling.
|
| 51 |
+
- **In-Browser WebGPU Inference:** Zero-cloud, client-side execution using ONNX Runtime Web.
|
| 52 |
+
- **Unified Ask and Compact Modes:** Asking for missing information before acting, answering direct questions, or choosing tools.
|
| 53 |
+
- **Safe Refusal & Escalation:** Refusing unsupported actions or escalating when Compact execution lacks evidence, avoiding invented URLs or fabricated success states.
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## Quickstart & Loading
|
| 58 |
+
|
| 59 |
+
Download the repository artifacts, including `onnx/*.onnx_data`, tokenizer, native `chat_template.jinja`, ABI, loader and pinned runtime files. Verify download hashes against `FILES.sha256.json`. Use the custom native Spark loader: this graph is **not** an AutoModelForCausalLM-compatible Llama remapping.
|
| 60 |
+
|
| 61 |
+
### 0. Download Model Artifacts
|
| 62 |
+
|
| 63 |
+
Using the Hugging Face CLI:
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
hf download webbrain-one/webbrain-compass-tiny-xs-v3-onnx --local-dir ./compass-tiny-xs-v3-onnx
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
Or in Python with `huggingface_hub`:
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
from huggingface_hub import snapshot_download
|
| 73 |
+
|
| 74 |
+
snapshot_download(
|
| 75 |
+
repo_id="webbrain-one/webbrain-compass-tiny-xs-v3-onnx",
|
| 76 |
+
local_dir="./compass-tiny-xs-v3-onnx"
|
| 77 |
+
)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### 1. Windows Loopback Launcher
|
| 81 |
+
|
| 82 |
+
The Windows loopback launcher requires Python 3.11 and Playwright 1.58.0:
|
| 83 |
+
|
| 84 |
+
```powershell
|
| 85 |
+
python -m pip install playwright==1.58.0
|
| 86 |
+
python runtime/browser_service.py --artifact-root C:/models/compass-v3-onnx --package-mode --run-tag local-test-1 --port 8561
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
The launcher expects Google Chrome under `C:/Program Files/Google/Chrome/Application/chrome.exe`.
|
| 90 |
+
Use a new `--run-tag` for each launch to retain startup/GPU-identity records.
|
| 91 |
+
|
| 92 |
+
### 2. OpenAI-Compatible Interface
|
| 93 |
+
|
| 94 |
+
```text
|
| 95 |
+
base_url: http://127.0.0.1:8561/v1
|
| 96 |
+
model: webbrain-compass-tiny-v3-onnx-fp16
|
| 97 |
+
temperature: 0
|
| 98 |
+
stream: false
|
| 99 |
+
max_tokens: 1..2048
|
| 100 |
+
input + output deployment cap: 4096 tokens
|
| 101 |
+
thinking: disabled
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
`GET /v1/models`, `GET /health`, `POST /v1/chat/completions` are available. Tools use standard OpenAI function schemas. Native Spark output is decoded to `tool_calls`; malformed output remains visible with `x_parser_error`, not repaired or retried. No helper model/cloud fallback is used. Unsupported sampling/streaming requests are rejected. Treat HTTP runtime errors as failures.
|
| 105 |
+
|
| 106 |
+
### 3. In-Browser Runtime Integration
|
| 107 |
+
|
| 108 |
+
Browser integrations should load `runtime/browser_runtime.js` and serve the package under `/model/`, `graph-abi.json` under `/abi`, and pinned vendor files under `/runtime/vendor/`. Use ORT external-data **URL streaming** as in the loader; Chrome cannot allocate a normal ~4GB ArrayBuffer for these weights.
|
| 109 |
+
|
| 110 |
+
KV buffers stay on the GPU and are disposed between requests. The native Jinja file is loaded explicitly and CRLF line endings normalized exactly as Python text-file loading does; supplied messages and tool order are not rewritten.
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## Technical Specifications & Precision
|
| 115 |
+
|
| 116 |
+
### Precision & Numerical Validation
|
| 117 |
+
This is **FP16 weight/cache storage with FP32 matrix multiplication compute**, plus FP32 residual, norm, RoPE and softmax. It is **not q4f16**.
|
| 118 |
+
|
| 119 |
+
CPU ONNX and actual Chrome/WebGPU prefill/cached-decode tests are recorded in `provenance/`.
|
| 120 |
+
- **Logit Gates:** Finite values, relative RMS <= 2%, cosine similarity >= 0.999.
|
| 121 |
+
- **Cache Boundary Checks:** Probes cover 4K and 8K cache boundaries. Native-template token IDs are checked against Python; plain generation and native tool-call parsing are tested. These are runtime/numerical checks, not task-quality benchmarks.
|
| 122 |
+
- **Candidate History:** Earlier FP16-compute candidates failed some long-context checks (up to 2.73% relative RMS). The attention-only FP32 correction still failed one 4K check. Both failures are preserved in `provenance/failed-candidates/`. The final graph promotes all matrix multiplication compute to FP32, without changing FP16 weight bytes or relaxing thresholds. This costs runtime VRAM and performance; it is a correctness-first browser export, not an optimized quantized release.
|
| 123 |
+
|
| 124 |
+
### Verified Hardware & Runtime
|
| 125 |
+
- **Hardware:** Windows, NVIDIA RTX 5090
|
| 126 |
+
- **Software:** Google Chrome 153.0.8010.50, ONNX Runtime Web 1.27.0, Transformers.js 4.2.0 tokenizer
|
| 127 |
+
- **Scope:** Other adapters and platforms have not been validated. The supplied launcher intentionally selects RTX 5090 and does not access the T400 or any cloud model.
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
## License
|
| 132 |
+
|
| 133 |
+
**Noncommercial research only.** This model and its fine-tuned weights are for noncommercial research purposes only. The upstream Spark model/code license is included in `LICENSE`; it does not change this release's usage restriction.
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{#- 0826版本 -#}
|
| 2 |
+
{%- if not messages %}
|
| 3 |
+
{{- raise_exception('No messages provided.') }}
|
| 4 |
+
{%- endif %}
|
| 5 |
+
{%- set enable_thinking = enable_thinking | default(true) %}
|
| 6 |
+
|
| 7 |
+
{#- Render a string or a list of text blocks. -#}
|
| 8 |
+
{%- macro render_content(content, context_name) %}
|
| 9 |
+
{%- if content is string %}
|
| 10 |
+
{{- content }}
|
| 11 |
+
{%- elif content is none or content is undefined %}
|
| 12 |
+
{{- '' }}
|
| 13 |
+
{%- elif content is iterable and content is not mapping %}
|
| 14 |
+
{%- for block in content %}
|
| 15 |
+
{%- if block.type == 'text' %}
|
| 16 |
+
{{- block.text }}
|
| 17 |
+
{%- else %}
|
| 18 |
+
{{- raise_exception('Unsupported ' ~ context_name ~ ' content block type: ' ~ (block.type | string)) }}
|
| 19 |
+
{%- endif %}
|
| 20 |
+
{%- endfor %}
|
| 21 |
+
{%- else %}
|
| 22 |
+
{{- raise_exception(context_name ~ ' content must be a string or a list of text blocks') }}
|
| 23 |
+
{%- endif %}
|
| 24 |
+
{%- endmacro %}
|
| 25 |
+
|
| 26 |
+
{#- Default system prompt -#}
|
| 27 |
+
{%- set default_system = "you are a helpful assistant." %}
|
| 28 |
+
|
| 29 |
+
{#- The first message-level system is placed in the initial system block. -#}
|
| 30 |
+
{%- set ns = namespace(initial_system='') %}
|
| 31 |
+
{%- if messages[0].role == "system" %}
|
| 32 |
+
{%- set ns.initial_system = render_content(messages[0].content, 'system') %}
|
| 33 |
+
{%- endif %}
|
| 34 |
+
|
| 35 |
+
{#- System block -#}
|
| 36 |
+
{{- '<|start▁of▁sentence|><|System|>' + '\n' + default_system }}
|
| 37 |
+
{%- if tools %}
|
| 38 |
+
{{- '## Tools' + '\n' + 'You have access to the following functions:' + '\n' + '<tools>' }}
|
| 39 |
+
{%- for tool in tools %}
|
| 40 |
+
{{- '\n' + tool.function | tojson}}
|
| 41 |
+
{%- endfor %}
|
| 42 |
+
{{- '\n' + '</tools>' }}
|
| 43 |
+
{%- endif %}
|
| 44 |
+
{%- if ns.initial_system %}
|
| 45 |
+
{{- '\n\n' + ns.initial_system }}
|
| 46 |
+
{%- endif %}
|
| 47 |
+
{{- '<|end▁of▁sentence|>'}}
|
| 48 |
+
|
| 49 |
+
{#- Conversation turns -#}
|
| 50 |
+
{%- for message in messages %}
|
| 51 |
+
{%- if message.role == "system" %}
|
| 52 |
+
{#- The first system message was consumed by the initial block. -#}
|
| 53 |
+
{%- if not loop.first %}
|
| 54 |
+
{{- '<|start▁of▁sentence|><|System|>\n' + render_content(message.content, 'system') + '<|end▁of▁sentence|>' }}
|
| 55 |
+
{%- endif %}
|
| 56 |
+
{%- elif message.role == "user" %}
|
| 57 |
+
{{- '<|start▁of▁sentence|><|User|>' + render_content(message.content, 'user') + '<|end▁of▁sentence|>' }}
|
| 58 |
+
{%- elif message.role == "assistant" %}
|
| 59 |
+
{%- set assistant_content = render_content(message.content, 'assistant') %}
|
| 60 |
+
{%- if message.reasoning_content is defined and message.reasoning_content %}
|
| 61 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 62 |
+
{%- else %}
|
| 63 |
+
{%- set reasoning_content = '' %}
|
| 64 |
+
{%- endif %}
|
| 65 |
+
{{- '<|start▁of▁sentence|><|Bot|>'}}
|
| 66 |
+
{%- if reasoning_content %}
|
| 67 |
+
{{- '<think>' + reasoning_content + '</think>'}}
|
| 68 |
+
{%- else %}
|
| 69 |
+
{{- '</think>' }}
|
| 70 |
+
{%- endif %}
|
| 71 |
+
{%- if assistant_content %}
|
| 72 |
+
{{- assistant_content }}
|
| 73 |
+
{%- endif %}
|
| 74 |
+
{%- if message.tool_calls is defined and message.tool_calls is not none %}
|
| 75 |
+
{%- for tool_call in message.tool_calls %}
|
| 76 |
+
{%- if tool_call.function.arguments is not mapping %}
|
| 77 |
+
{{- raise_exception('tool_call.function.arguments must be a dictionary; normalize JSON strings before apply_chat_template') }}
|
| 78 |
+
{%- endif %}
|
| 79 |
+
{%- set args = tool_call.function.arguments %}
|
| 80 |
+
{{- '<tool_call>' + tool_call.function.name }}
|
| 81 |
+
{%- for k, v in args.items() %}
|
| 82 |
+
{{- '<arg_key>' ~ k ~ '</arg_key><arg_value>' ~ (v if v is string else v | tojson) ~ '</arg_value>' }}
|
| 83 |
+
{%- endfor %}
|
| 84 |
+
{{- '</tool_call>' }}
|
| 85 |
+
{%- endfor %}
|
| 86 |
+
{%- endif %}
|
| 87 |
+
{{- '<|end▁of▁sentence|>' }}
|
| 88 |
+
{%- elif message.role == "tool" %}
|
| 89 |
+
{%- if loop.previtem is undefined or loop.previtem.role != "tool" %}
|
| 90 |
+
{{- '<|start▁of▁sentence|><|Tool|>' }}
|
| 91 |
+
{%- endif %}
|
| 92 |
+
{{- '<tool_response>' ~ message.content ~ '</tool_response>' }}
|
| 93 |
+
{%- if loop.nextitem is undefined or loop.nextitem.role != "tool" %}
|
| 94 |
+
{{- '<|end▁of▁sentence|>' }}
|
| 95 |
+
{%- endif %}
|
| 96 |
+
{%- else %}
|
| 97 |
+
{{- raise_exception('Unsupported message role: ' ~ message.role) }}
|
| 98 |
+
{%- endif %}
|
| 99 |
+
{%- endfor %}
|
| 100 |
+
|
| 101 |
+
{#- Generation prompt -#}
|
| 102 |
+
{%- if add_generation_prompt %}
|
| 103 |
+
{{- '<|start▁of▁sentence|><|Bot|>' }}
|
| 104 |
+
{%- if enable_thinking is defined and enable_thinking %}
|
| 105 |
+
{{- '<think>' }}
|
| 106 |
+
{%- endif %}
|
| 107 |
+
{%- if enable_thinking is defined and not enable_thinking %}
|
| 108 |
+
{{- '</think>' }}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- endif %}
|
config.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Spark2_5ForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoConfig": "configuration_spark.Spark2_5Config",
|
| 9 |
+
"AutoModel": "modeling_spark.Spark2_5Model",
|
| 10 |
+
"AutoModelForCausalLM": "modeling_spark.Spark2_5ForCausalLM"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 0,
|
| 13 |
+
"dtype": "bfloat16",
|
| 14 |
+
"eos_token_id": 1,
|
| 15 |
+
"gate_attn_act_mode": "sigmoid",
|
| 16 |
+
"head_dim": 256,
|
| 17 |
+
"headwise_attn_output_gate": true,
|
| 18 |
+
"hidden_act": "gelu",
|
| 19 |
+
"hidden_size": 2048,
|
| 20 |
+
"initializer_range": 0.0221,
|
| 21 |
+
"intermediate_size": 6656,
|
| 22 |
+
"layer_types": [
|
| 23 |
+
"sliding_attention",
|
| 24 |
+
"sliding_attention",
|
| 25 |
+
"sliding_attention",
|
| 26 |
+
"full_attention",
|
| 27 |
+
"sliding_attention",
|
| 28 |
+
"sliding_attention",
|
| 29 |
+
"sliding_attention",
|
| 30 |
+
"full_attention",
|
| 31 |
+
"sliding_attention",
|
| 32 |
+
"sliding_attention",
|
| 33 |
+
"sliding_attention",
|
| 34 |
+
"full_attention",
|
| 35 |
+
"sliding_attention",
|
| 36 |
+
"sliding_attention",
|
| 37 |
+
"sliding_attention",
|
| 38 |
+
"full_attention",
|
| 39 |
+
"sliding_attention",
|
| 40 |
+
"sliding_attention",
|
| 41 |
+
"sliding_attention",
|
| 42 |
+
"full_attention",
|
| 43 |
+
"sliding_attention",
|
| 44 |
+
"sliding_attention",
|
| 45 |
+
"sliding_attention",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"sliding_attention",
|
| 48 |
+
"sliding_attention",
|
| 49 |
+
"sliding_attention",
|
| 50 |
+
"full_attention"
|
| 51 |
+
],
|
| 52 |
+
"max_position_embeddings": 1048576,
|
| 53 |
+
"mlp_bias": false,
|
| 54 |
+
"model_type": "spark2_5",
|
| 55 |
+
"num_attention_heads": 8,
|
| 56 |
+
"num_hidden_layers": 28,
|
| 57 |
+
"num_key_value_heads": 2,
|
| 58 |
+
"pad_token_id": 2,
|
| 59 |
+
"rms_norm_eps": 1e-06,
|
| 60 |
+
"rope_parameters": {
|
| 61 |
+
"full_attention": {
|
| 62 |
+
"partial_rotary_factor": 0.25,
|
| 63 |
+
"rope_theta": 5000000
|
| 64 |
+
},
|
| 65 |
+
"rope_theta": 10000.0,
|
| 66 |
+
"rope_type": "default",
|
| 67 |
+
"sliding_attention": {
|
| 68 |
+
"partial_rotary_factor": 1.0,
|
| 69 |
+
"rope_theta": 10000
|
| 70 |
+
}
|
| 71 |
+
},
|
| 72 |
+
"sliding_window": 512,
|
| 73 |
+
"tie_word_embeddings": true,
|
| 74 |
+
"transformers_version": "5.16.1",
|
| 75 |
+
"use_cache": true,
|
| 76 |
+
"vocab_size": 131072
|
| 77 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 0,
|
| 3 |
+
"do_sample": true,
|
| 4 |
+
"eos_token_id": 1,
|
| 5 |
+
"frequency_penalty": 0,
|
| 6 |
+
"max_tokens": 1048576,
|
| 7 |
+
"pad_token_id": 2,
|
| 8 |
+
"presence_penalty": 0,
|
| 9 |
+
"repetition_penalty": 1.0,
|
| 10 |
+
"temperature": 1.0,
|
| 11 |
+
"top_k": -1,
|
| 12 |
+
"top_p": 0.95,
|
| 13 |
+
"transformers_version": "5.16.1"
|
| 14 |
+
}
|
graph-abi.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"contextTested": [
|
| 3 |
+
4096,
|
| 4 |
+
8192
|
| 5 |
+
],
|
| 6 |
+
"dtype": "float16",
|
| 7 |
+
"headDim": 256,
|
| 8 |
+
"inputs": [
|
| 9 |
+
"input_ids",
|
| 10 |
+
"position_ids",
|
| 11 |
+
"past_key_values.0.key",
|
| 12 |
+
"past_key_values.0.value",
|
| 13 |
+
"past_key_values.1.key",
|
| 14 |
+
"past_key_values.1.value",
|
| 15 |
+
"past_key_values.2.key",
|
| 16 |
+
"past_key_values.2.value",
|
| 17 |
+
"past_key_values.3.key",
|
| 18 |
+
"past_key_values.3.value",
|
| 19 |
+
"past_key_values.4.key",
|
| 20 |
+
"past_key_values.4.value",
|
| 21 |
+
"past_key_values.5.key",
|
| 22 |
+
"past_key_values.5.value",
|
| 23 |
+
"past_key_values.6.key",
|
| 24 |
+
"past_key_values.6.value",
|
| 25 |
+
"past_key_values.7.key",
|
| 26 |
+
"past_key_values.7.value",
|
| 27 |
+
"past_key_values.8.key",
|
| 28 |
+
"past_key_values.8.value",
|
| 29 |
+
"past_key_values.9.key",
|
| 30 |
+
"past_key_values.9.value",
|
| 31 |
+
"past_key_values.10.key",
|
| 32 |
+
"past_key_values.10.value",
|
| 33 |
+
"past_key_values.11.key",
|
| 34 |
+
"past_key_values.11.value",
|
| 35 |
+
"past_key_values.12.key",
|
| 36 |
+
"past_key_values.12.value",
|
| 37 |
+
"past_key_values.13.key",
|
| 38 |
+
"past_key_values.13.value",
|
| 39 |
+
"past_key_values.14.key",
|
| 40 |
+
"past_key_values.14.value",
|
| 41 |
+
"past_key_values.15.key",
|
| 42 |
+
"past_key_values.15.value",
|
| 43 |
+
"past_key_values.16.key",
|
| 44 |
+
"past_key_values.16.value",
|
| 45 |
+
"past_key_values.17.key",
|
| 46 |
+
"past_key_values.17.value",
|
| 47 |
+
"past_key_values.18.key",
|
| 48 |
+
"past_key_values.18.value",
|
| 49 |
+
"past_key_values.19.key",
|
| 50 |
+
"past_key_values.19.value",
|
| 51 |
+
"past_key_values.20.key",
|
| 52 |
+
"past_key_values.20.value",
|
| 53 |
+
"past_key_values.21.key",
|
| 54 |
+
"past_key_values.21.value",
|
| 55 |
+
"past_key_values.22.key",
|
| 56 |
+
"past_key_values.22.value",
|
| 57 |
+
"past_key_values.23.key",
|
| 58 |
+
"past_key_values.23.value",
|
| 59 |
+
"past_key_values.24.key",
|
| 60 |
+
"past_key_values.24.value",
|
| 61 |
+
"past_key_values.25.key",
|
| 62 |
+
"past_key_values.25.value",
|
| 63 |
+
"past_key_values.26.key",
|
| 64 |
+
"past_key_values.26.value",
|
| 65 |
+
"past_key_values.27.key",
|
| 66 |
+
"past_key_values.27.value"
|
| 67 |
+
],
|
| 68 |
+
"numKvHeads": 2,
|
| 69 |
+
"numLayers": 28,
|
| 70 |
+
"outputs": [
|
| 71 |
+
"logits",
|
| 72 |
+
"present.0.key",
|
| 73 |
+
"present.0.value",
|
| 74 |
+
"present.1.key",
|
| 75 |
+
"present.1.value",
|
| 76 |
+
"present.2.key",
|
| 77 |
+
"present.2.value",
|
| 78 |
+
"present.3.key",
|
| 79 |
+
"present.3.value",
|
| 80 |
+
"present.4.key",
|
| 81 |
+
"present.4.value",
|
| 82 |
+
"present.5.key",
|
| 83 |
+
"present.5.value",
|
| 84 |
+
"present.6.key",
|
| 85 |
+
"present.6.value",
|
| 86 |
+
"present.7.key",
|
| 87 |
+
"present.7.value",
|
| 88 |
+
"present.8.key",
|
| 89 |
+
"present.8.value",
|
| 90 |
+
"present.9.key",
|
| 91 |
+
"present.9.value",
|
| 92 |
+
"present.10.key",
|
| 93 |
+
"present.10.value",
|
| 94 |
+
"present.11.key",
|
| 95 |
+
"present.11.value",
|
| 96 |
+
"present.12.key",
|
| 97 |
+
"present.12.value",
|
| 98 |
+
"present.13.key",
|
| 99 |
+
"present.13.value",
|
| 100 |
+
"present.14.key",
|
| 101 |
+
"present.14.value",
|
| 102 |
+
"present.15.key",
|
| 103 |
+
"present.15.value",
|
| 104 |
+
"present.16.key",
|
| 105 |
+
"present.16.value",
|
| 106 |
+
"present.17.key",
|
| 107 |
+
"present.17.value",
|
| 108 |
+
"present.18.key",
|
| 109 |
+
"present.18.value",
|
| 110 |
+
"present.19.key",
|
| 111 |
+
"present.19.value",
|
| 112 |
+
"present.20.key",
|
| 113 |
+
"present.20.value",
|
| 114 |
+
"present.21.key",
|
| 115 |
+
"present.21.value",
|
| 116 |
+
"present.22.key",
|
| 117 |
+
"present.22.value",
|
| 118 |
+
"present.23.key",
|
| 119 |
+
"present.23.value",
|
| 120 |
+
"present.24.key",
|
| 121 |
+
"present.24.value",
|
| 122 |
+
"present.25.key",
|
| 123 |
+
"present.25.value",
|
| 124 |
+
"present.26.key",
|
| 125 |
+
"present.26.value",
|
| 126 |
+
"present.27.key",
|
| 127 |
+
"present.27.value"
|
| 128 |
+
],
|
| 129 |
+
"residualNormRopeSoftmax": "FP32",
|
| 130 |
+
"vocabSize": 131072,
|
| 131 |
+
"weights": "FP16",
|
| 132 |
+
"matmulCompute": "FP32",
|
| 133 |
+
"attentionMatmul": "FP32 compute, FP16 input/cache/output storage",
|
| 134 |
+
"deploymentContextTokens": 4096
|
| 135 |
+
}
|
onnx/model_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7b3095d0b51cc8aecc0aea0eb82869efa16039d358548e61fc461b5622a73819
|
| 3 |
+
size 1454092
|
onnx/model_fp16.onnx_data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9abbd8c7e69fbdb9bb4fe6244c30b66a397a4f237dbfc75e95dd11062db3acdc
|
| 3 |
+
size 3952418816
|
provenance/bf16-upload-verified.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"byteHashesVerified": true, "filesVerified": 36, "package": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\release-compat-v3", "precision": "BF16", "private": true, "repoId": "webbrain-one/webbrain-compass-tiny-v3", "revision": "d90debc5a54e3e4d7ca8a6cae88464bcba2d7597", "validationPassed": true}
|
provenance/browser-validation.json
ADDED
|
@@ -0,0 +1,502 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"passed": true,
|
| 3 |
+
"checks": [
|
| 4 |
+
{
|
| 5 |
+
"case": "plain",
|
| 6 |
+
"step": 0,
|
| 7 |
+
"relativeRms": 0.0031742489537124824,
|
| 8 |
+
"cosine": 0.9999982728469193,
|
| 9 |
+
"finite": true,
|
| 10 |
+
"bf16Argmax": 46,
|
| 11 |
+
"webgpuArgmax": 46
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"case": "plain",
|
| 15 |
+
"step": 1,
|
| 16 |
+
"relativeRms": 0.0024395676969367047,
|
| 17 |
+
"cosine": 0.9999987233296794,
|
| 18 |
+
"finite": true,
|
| 19 |
+
"bf16Argmax": 22968,
|
| 20 |
+
"webgpuArgmax": 22968
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"case": "plain",
|
| 24 |
+
"step": 2,
|
| 25 |
+
"relativeRms": 0.002517515988852247,
|
| 26 |
+
"cosine": 0.9999981622808539,
|
| 27 |
+
"finite": true,
|
| 28 |
+
"bf16Argmax": 390,
|
| 29 |
+
"webgpuArgmax": 390
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"case": "plain",
|
| 33 |
+
"step": 3,
|
| 34 |
+
"relativeRms": 0.0017153056976334541,
|
| 35 |
+
"cosine": 0.9999985356297056,
|
| 36 |
+
"finite": true,
|
| 37 |
+
"bf16Argmax": 259,
|
| 38 |
+
"webgpuArgmax": 259
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"case": "native_tool",
|
| 42 |
+
"step": 0,
|
| 43 |
+
"relativeRms": 0.00293264003821058,
|
| 44 |
+
"cosine": 0.9999977678489465,
|
| 45 |
+
"finite": true,
|
| 46 |
+
"bf16Argmax": 130977,
|
| 47 |
+
"webgpuArgmax": 130977
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"case": "native_tool",
|
| 51 |
+
"step": 1,
|
| 52 |
+
"relativeRms": 0.0026049875734034038,
|
| 53 |
+
"cosine": 0.9999976282430977,
|
| 54 |
+
"finite": true,
|
| 55 |
+
"bf16Argmax": 9026,
|
| 56 |
+
"webgpuArgmax": 9026
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"case": "native_tool",
|
| 60 |
+
"step": 2,
|
| 61 |
+
"relativeRms": 0.0027817357694231368,
|
| 62 |
+
"cosine": 0.9999976118703789,
|
| 63 |
+
"finite": true,
|
| 64 |
+
"bf16Argmax": 18672,
|
| 65 |
+
"webgpuArgmax": 18672
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"case": "native_tool",
|
| 69 |
+
"step": 3,
|
| 70 |
+
"relativeRms": 0.0024958189369430365,
|
| 71 |
+
"cosine": 0.9999978419231034,
|
| 72 |
+
"finite": true,
|
| 73 |
+
"bf16Argmax": 130980,
|
| 74 |
+
"webgpuArgmax": 130980
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"case": "sliding_boundary_513",
|
| 78 |
+
"step": 0,
|
| 79 |
+
"relativeRms": 0.007342586861562889,
|
| 80 |
+
"cosine": 0.9999953707207943,
|
| 81 |
+
"finite": true,
|
| 82 |
+
"bf16Argmax": 5722,
|
| 83 |
+
"webgpuArgmax": 5722
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"case": "sliding_boundary_513",
|
| 87 |
+
"step": 1,
|
| 88 |
+
"relativeRms": 0.0027534598715720326,
|
| 89 |
+
"cosine": 0.9999985373187525,
|
| 90 |
+
"finite": true,
|
| 91 |
+
"bf16Argmax": 27,
|
| 92 |
+
"webgpuArgmax": 27
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"case": "sliding_boundary_513",
|
| 96 |
+
"step": 2,
|
| 97 |
+
"relativeRms": 0.0019649190135327434,
|
| 98 |
+
"cosine": 0.9999981505547065,
|
| 99 |
+
"finite": true,
|
| 100 |
+
"bf16Argmax": 22968,
|
| 101 |
+
"webgpuArgmax": 22968
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"case": "sliding_boundary_513",
|
| 105 |
+
"step": 3,
|
| 106 |
+
"relativeRms": 0.0038859720368507266,
|
| 107 |
+
"cosine": 0.9999971867802836,
|
| 108 |
+
"finite": true,
|
| 109 |
+
"bf16Argmax": 7281,
|
| 110 |
+
"webgpuArgmax": 7281
|
| 111 |
+
}
|
| 112 |
+
],
|
| 113 |
+
"templates": [
|
| 114 |
+
{
|
| 115 |
+
"case": "plain",
|
| 116 |
+
"tokenIdsIdentical": true
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"case": "native_tool",
|
| 120 |
+
"tokenIdsIdentical": true
|
| 121 |
+
}
|
| 122 |
+
],
|
| 123 |
+
"generationSmoke": [
|
| 124 |
+
{
|
| 125 |
+
"case": "plain",
|
| 126 |
+
"seconds": 4.219000000040978,
|
| 127 |
+
"result": {
|
| 128 |
+
"id": "chatcmpl-34e30bcd64a0427aaefa6b33b54df3ab",
|
| 129 |
+
"object": "chat.completion",
|
| 130 |
+
"created": 1790427793,
|
| 131 |
+
"model": "webbrain-compass-tiny-v3-onnx-fp16",
|
| 132 |
+
"choices": [
|
| 133 |
+
{
|
| 134 |
+
"index": 0,
|
| 135 |
+
"message": {
|
| 136 |
+
"role": "assistant",
|
| 137 |
+
"content": "A browser is a software application that lets you access and view information on the internet."
|
| 138 |
+
},
|
| 139 |
+
"finish_reason": "stop"
|
| 140 |
+
}
|
| 141 |
+
],
|
| 142 |
+
"usage": {
|
| 143 |
+
"prompt_tokens": 26,
|
| 144 |
+
"completion_tokens": 18,
|
| 145 |
+
"total_tokens": 44
|
| 146 |
+
},
|
| 147 |
+
"x_runtime": {
|
| 148 |
+
"ready": true,
|
| 149 |
+
"model": "webbrain-compass-tiny-v3-onnx-fp16",
|
| 150 |
+
"precision": "FP16 ONNX; FP32 residual/norm/RoPE/softmax",
|
| 151 |
+
"runtime": {
|
| 152 |
+
"common": "1.27.0",
|
| 153 |
+
"web": "1.27.0"
|
| 154 |
+
},
|
| 155 |
+
"gpu": "RTX 5090",
|
| 156 |
+
"cloudFallback": false,
|
| 157 |
+
"maxContextTokens": 4096,
|
| 158 |
+
"temperature": "greedy-only benchmark endpoint",
|
| 159 |
+
"browser": "153.0.8010.50",
|
| 160 |
+
"gpuInfo": {
|
| 161 |
+
"vendor": "nvidia",
|
| 162 |
+
"architecture": "blackwell",
|
| 163 |
+
"description": ""
|
| 164 |
+
},
|
| 165 |
+
"abi": {
|
| 166 |
+
"contextTested": null,
|
| 167 |
+
"dtype": "float16",
|
| 168 |
+
"headDim": 256,
|
| 169 |
+
"inputs": [
|
| 170 |
+
"input_ids",
|
| 171 |
+
"position_ids",
|
| 172 |
+
"past_key_values.0.key",
|
| 173 |
+
"past_key_values.0.value",
|
| 174 |
+
"past_key_values.1.key",
|
| 175 |
+
"past_key_values.1.value",
|
| 176 |
+
"past_key_values.2.key",
|
| 177 |
+
"past_key_values.2.value",
|
| 178 |
+
"past_key_values.3.key",
|
| 179 |
+
"past_key_values.3.value",
|
| 180 |
+
"past_key_values.4.key",
|
| 181 |
+
"past_key_values.4.value",
|
| 182 |
+
"past_key_values.5.key",
|
| 183 |
+
"past_key_values.5.value",
|
| 184 |
+
"past_key_values.6.key",
|
| 185 |
+
"past_key_values.6.value",
|
| 186 |
+
"past_key_values.7.key",
|
| 187 |
+
"past_key_values.7.value",
|
| 188 |
+
"past_key_values.8.key",
|
| 189 |
+
"past_key_values.8.value",
|
| 190 |
+
"past_key_values.9.key",
|
| 191 |
+
"past_key_values.9.value",
|
| 192 |
+
"past_key_values.10.key",
|
| 193 |
+
"past_key_values.10.value",
|
| 194 |
+
"past_key_values.11.key",
|
| 195 |
+
"past_key_values.11.value",
|
| 196 |
+
"past_key_values.12.key",
|
| 197 |
+
"past_key_values.12.value",
|
| 198 |
+
"past_key_values.13.key",
|
| 199 |
+
"past_key_values.13.value",
|
| 200 |
+
"past_key_values.14.key",
|
| 201 |
+
"past_key_values.14.value",
|
| 202 |
+
"past_key_values.15.key",
|
| 203 |
+
"past_key_values.15.value",
|
| 204 |
+
"past_key_values.16.key",
|
| 205 |
+
"past_key_values.16.value",
|
| 206 |
+
"past_key_values.17.key",
|
| 207 |
+
"past_key_values.17.value",
|
| 208 |
+
"past_key_values.18.key",
|
| 209 |
+
"past_key_values.18.value",
|
| 210 |
+
"past_key_values.19.key",
|
| 211 |
+
"past_key_values.19.value",
|
| 212 |
+
"past_key_values.20.key",
|
| 213 |
+
"past_key_values.20.value",
|
| 214 |
+
"past_key_values.21.key",
|
| 215 |
+
"past_key_values.21.value",
|
| 216 |
+
"past_key_values.22.key",
|
| 217 |
+
"past_key_values.22.value",
|
| 218 |
+
"past_key_values.23.key",
|
| 219 |
+
"past_key_values.23.value",
|
| 220 |
+
"past_key_values.24.key",
|
| 221 |
+
"past_key_values.24.value",
|
| 222 |
+
"past_key_values.25.key",
|
| 223 |
+
"past_key_values.25.value",
|
| 224 |
+
"past_key_values.26.key",
|
| 225 |
+
"past_key_values.26.value",
|
| 226 |
+
"past_key_values.27.key",
|
| 227 |
+
"past_key_values.27.value"
|
| 228 |
+
],
|
| 229 |
+
"numKvHeads": 2,
|
| 230 |
+
"numLayers": 28,
|
| 231 |
+
"outputs": [
|
| 232 |
+
"logits",
|
| 233 |
+
"present.0.key",
|
| 234 |
+
"present.0.value",
|
| 235 |
+
"present.1.key",
|
| 236 |
+
"present.1.value",
|
| 237 |
+
"present.2.key",
|
| 238 |
+
"present.2.value",
|
| 239 |
+
"present.3.key",
|
| 240 |
+
"present.3.value",
|
| 241 |
+
"present.4.key",
|
| 242 |
+
"present.4.value",
|
| 243 |
+
"present.5.key",
|
| 244 |
+
"present.5.value",
|
| 245 |
+
"present.6.key",
|
| 246 |
+
"present.6.value",
|
| 247 |
+
"present.7.key",
|
| 248 |
+
"present.7.value",
|
| 249 |
+
"present.8.key",
|
| 250 |
+
"present.8.value",
|
| 251 |
+
"present.9.key",
|
| 252 |
+
"present.9.value",
|
| 253 |
+
"present.10.key",
|
| 254 |
+
"present.10.value",
|
| 255 |
+
"present.11.key",
|
| 256 |
+
"present.11.value",
|
| 257 |
+
"present.12.key",
|
| 258 |
+
"present.12.value",
|
| 259 |
+
"present.13.key",
|
| 260 |
+
"present.13.value",
|
| 261 |
+
"present.14.key",
|
| 262 |
+
"present.14.value",
|
| 263 |
+
"present.15.key",
|
| 264 |
+
"present.15.value",
|
| 265 |
+
"present.16.key",
|
| 266 |
+
"present.16.value",
|
| 267 |
+
"present.17.key",
|
| 268 |
+
"present.17.value",
|
| 269 |
+
"present.18.key",
|
| 270 |
+
"present.18.value",
|
| 271 |
+
"present.19.key",
|
| 272 |
+
"present.19.value",
|
| 273 |
+
"present.20.key",
|
| 274 |
+
"present.20.value",
|
| 275 |
+
"present.21.key",
|
| 276 |
+
"present.21.value",
|
| 277 |
+
"present.22.key",
|
| 278 |
+
"present.22.value",
|
| 279 |
+
"present.23.key",
|
| 280 |
+
"present.23.value",
|
| 281 |
+
"present.24.key",
|
| 282 |
+
"present.24.value",
|
| 283 |
+
"present.25.key",
|
| 284 |
+
"present.25.value",
|
| 285 |
+
"present.26.key",
|
| 286 |
+
"present.26.value",
|
| 287 |
+
"present.27.key",
|
| 288 |
+
"present.27.value"
|
| 289 |
+
],
|
| 290 |
+
"residualNormRopeSoftmax": "FP32",
|
| 291 |
+
"vocabSize": 131072,
|
| 292 |
+
"weights": "FP16",
|
| 293 |
+
"matmulCompute": "FP32",
|
| 294 |
+
"attentionMatmul": "FP32 compute, FP16 input/cache/output storage"
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"case": "native_tool",
|
| 301 |
+
"seconds": 3.1869999999180436,
|
| 302 |
+
"result": {
|
| 303 |
+
"id": "chatcmpl-f48b1cdad4334a71b81fdbfade013480",
|
| 304 |
+
"object": "chat.completion",
|
| 305 |
+
"created": 1790427796,
|
| 306 |
+
"model": "webbrain-compass-tiny-v3-onnx-fp16",
|
| 307 |
+
"choices": [
|
| 308 |
+
{
|
| 309 |
+
"index": 0,
|
| 310 |
+
"message": {
|
| 311 |
+
"role": "assistant",
|
| 312 |
+
"content": null,
|
| 313 |
+
"tool_calls": [
|
| 314 |
+
{
|
| 315 |
+
"id": "call_1ffcc8d111bf47be",
|
| 316 |
+
"type": "function",
|
| 317 |
+
"function": {
|
| 318 |
+
"name": "open_url",
|
| 319 |
+
"arguments": "{\"url\": \"https://example.com\"}"
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
]
|
| 323 |
+
},
|
| 324 |
+
"finish_reason": "tool_calls"
|
| 325 |
+
}
|
| 326 |
+
],
|
| 327 |
+
"usage": {
|
| 328 |
+
"prompt_tokens": 105,
|
| 329 |
+
"completion_tokens": 14,
|
| 330 |
+
"total_tokens": 119
|
| 331 |
+
},
|
| 332 |
+
"x_runtime": {
|
| 333 |
+
"ready": true,
|
| 334 |
+
"model": "webbrain-compass-tiny-v3-onnx-fp16",
|
| 335 |
+
"precision": "FP16 ONNX; FP32 residual/norm/RoPE/softmax",
|
| 336 |
+
"runtime": {
|
| 337 |
+
"common": "1.27.0",
|
| 338 |
+
"web": "1.27.0"
|
| 339 |
+
},
|
| 340 |
+
"gpu": "RTX 5090",
|
| 341 |
+
"cloudFallback": false,
|
| 342 |
+
"maxContextTokens": 4096,
|
| 343 |
+
"temperature": "greedy-only benchmark endpoint",
|
| 344 |
+
"browser": "153.0.8010.50",
|
| 345 |
+
"gpuInfo": {
|
| 346 |
+
"vendor": "nvidia",
|
| 347 |
+
"architecture": "blackwell",
|
| 348 |
+
"description": ""
|
| 349 |
+
},
|
| 350 |
+
"abi": {
|
| 351 |
+
"contextTested": null,
|
| 352 |
+
"dtype": "float16",
|
| 353 |
+
"headDim": 256,
|
| 354 |
+
"inputs": [
|
| 355 |
+
"input_ids",
|
| 356 |
+
"position_ids",
|
| 357 |
+
"past_key_values.0.key",
|
| 358 |
+
"past_key_values.0.value",
|
| 359 |
+
"past_key_values.1.key",
|
| 360 |
+
"past_key_values.1.value",
|
| 361 |
+
"past_key_values.2.key",
|
| 362 |
+
"past_key_values.2.value",
|
| 363 |
+
"past_key_values.3.key",
|
| 364 |
+
"past_key_values.3.value",
|
| 365 |
+
"past_key_values.4.key",
|
| 366 |
+
"past_key_values.4.value",
|
| 367 |
+
"past_key_values.5.key",
|
| 368 |
+
"past_key_values.5.value",
|
| 369 |
+
"past_key_values.6.key",
|
| 370 |
+
"past_key_values.6.value",
|
| 371 |
+
"past_key_values.7.key",
|
| 372 |
+
"past_key_values.7.value",
|
| 373 |
+
"past_key_values.8.key",
|
| 374 |
+
"past_key_values.8.value",
|
| 375 |
+
"past_key_values.9.key",
|
| 376 |
+
"past_key_values.9.value",
|
| 377 |
+
"past_key_values.10.key",
|
| 378 |
+
"past_key_values.10.value",
|
| 379 |
+
"past_key_values.11.key",
|
| 380 |
+
"past_key_values.11.value",
|
| 381 |
+
"past_key_values.12.key",
|
| 382 |
+
"past_key_values.12.value",
|
| 383 |
+
"past_key_values.13.key",
|
| 384 |
+
"past_key_values.13.value",
|
| 385 |
+
"past_key_values.14.key",
|
| 386 |
+
"past_key_values.14.value",
|
| 387 |
+
"past_key_values.15.key",
|
| 388 |
+
"past_key_values.15.value",
|
| 389 |
+
"past_key_values.16.key",
|
| 390 |
+
"past_key_values.16.value",
|
| 391 |
+
"past_key_values.17.key",
|
| 392 |
+
"past_key_values.17.value",
|
| 393 |
+
"past_key_values.18.key",
|
| 394 |
+
"past_key_values.18.value",
|
| 395 |
+
"past_key_values.19.key",
|
| 396 |
+
"past_key_values.19.value",
|
| 397 |
+
"past_key_values.20.key",
|
| 398 |
+
"past_key_values.20.value",
|
| 399 |
+
"past_key_values.21.key",
|
| 400 |
+
"past_key_values.21.value",
|
| 401 |
+
"past_key_values.22.key",
|
| 402 |
+
"past_key_values.22.value",
|
| 403 |
+
"past_key_values.23.key",
|
| 404 |
+
"past_key_values.23.value",
|
| 405 |
+
"past_key_values.24.key",
|
| 406 |
+
"past_key_values.24.value",
|
| 407 |
+
"past_key_values.25.key",
|
| 408 |
+
"past_key_values.25.value",
|
| 409 |
+
"past_key_values.26.key",
|
| 410 |
+
"past_key_values.26.value",
|
| 411 |
+
"past_key_values.27.key",
|
| 412 |
+
"past_key_values.27.value"
|
| 413 |
+
],
|
| 414 |
+
"numKvHeads": 2,
|
| 415 |
+
"numLayers": 28,
|
| 416 |
+
"outputs": [
|
| 417 |
+
"logits",
|
| 418 |
+
"present.0.key",
|
| 419 |
+
"present.0.value",
|
| 420 |
+
"present.1.key",
|
| 421 |
+
"present.1.value",
|
| 422 |
+
"present.2.key",
|
| 423 |
+
"present.2.value",
|
| 424 |
+
"present.3.key",
|
| 425 |
+
"present.3.value",
|
| 426 |
+
"present.4.key",
|
| 427 |
+
"present.4.value",
|
| 428 |
+
"present.5.key",
|
| 429 |
+
"present.5.value",
|
| 430 |
+
"present.6.key",
|
| 431 |
+
"present.6.value",
|
| 432 |
+
"present.7.key",
|
| 433 |
+
"present.7.value",
|
| 434 |
+
"present.8.key",
|
| 435 |
+
"present.8.value",
|
| 436 |
+
"present.9.key",
|
| 437 |
+
"present.9.value",
|
| 438 |
+
"present.10.key",
|
| 439 |
+
"present.10.value",
|
| 440 |
+
"present.11.key",
|
| 441 |
+
"present.11.value",
|
| 442 |
+
"present.12.key",
|
| 443 |
+
"present.12.value",
|
| 444 |
+
"present.13.key",
|
| 445 |
+
"present.13.value",
|
| 446 |
+
"present.14.key",
|
| 447 |
+
"present.14.value",
|
| 448 |
+
"present.15.key",
|
| 449 |
+
"present.15.value",
|
| 450 |
+
"present.16.key",
|
| 451 |
+
"present.16.value",
|
| 452 |
+
"present.17.key",
|
| 453 |
+
"present.17.value",
|
| 454 |
+
"present.18.key",
|
| 455 |
+
"present.18.value",
|
| 456 |
+
"present.19.key",
|
| 457 |
+
"present.19.value",
|
| 458 |
+
"present.20.key",
|
| 459 |
+
"present.20.value",
|
| 460 |
+
"present.21.key",
|
| 461 |
+
"present.21.value",
|
| 462 |
+
"present.22.key",
|
| 463 |
+
"present.22.value",
|
| 464 |
+
"present.23.key",
|
| 465 |
+
"present.23.value",
|
| 466 |
+
"present.24.key",
|
| 467 |
+
"present.24.value",
|
| 468 |
+
"present.25.key",
|
| 469 |
+
"present.25.value",
|
| 470 |
+
"present.26.key",
|
| 471 |
+
"present.26.value",
|
| 472 |
+
"present.27.key",
|
| 473 |
+
"present.27.value"
|
| 474 |
+
],
|
| 475 |
+
"residualNormRopeSoftmax": "FP32",
|
| 476 |
+
"vocabSize": 131072,
|
| 477 |
+
"weights": "FP16",
|
| 478 |
+
"matmulCompute": "FP32",
|
| 479 |
+
"attentionMatmul": "FP32 compute, FP16 input/cache/output storage"
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
],
|
| 485 |
+
"thresholds": {
|
| 486 |
+
"relativeRmsMax": 0.02,
|
| 487 |
+
"cosineMin": 0.999
|
| 488 |
+
},
|
| 489 |
+
"browser": "153.0.8010.50",
|
| 490 |
+
"runtime": {
|
| 491 |
+
"common": "1.27.0",
|
| 492 |
+
"web": "1.27.0"
|
| 493 |
+
},
|
| 494 |
+
"gpu": {
|
| 495 |
+
"vendor": "nvidia",
|
| 496 |
+
"architecture": "blackwell",
|
| 497 |
+
"description": ""
|
| 498 |
+
},
|
| 499 |
+
"precision": "FP16 ONNX; FP32 residual/norm/RoPE/softmax",
|
| 500 |
+
"cloudFallback": false,
|
| 501 |
+
"interpretation": "Runtime/numerical smoke only; not an agent benchmark"
|
| 502 |
+
}
|
provenance/context-validation.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"passed": true,
|
| 3 |
+
"contexts": [
|
| 4 |
+
{
|
| 5 |
+
"passed": true,
|
| 6 |
+
"prefillTokens": 4093,
|
| 7 |
+
"finalCacheTokens": 4096,
|
| 8 |
+
"checks": [
|
| 9 |
+
{
|
| 10 |
+
"step": 0,
|
| 11 |
+
"relativeRms": 0.008058232183718704,
|
| 12 |
+
"cosine": 0.999993236699056,
|
| 13 |
+
"finite": true,
|
| 14 |
+
"argmaxMatched": true
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"step": 1,
|
| 18 |
+
"relativeRms": 0.005292713628745938,
|
| 19 |
+
"cosine": 0.9999943298962085,
|
| 20 |
+
"finite": true,
|
| 21 |
+
"argmaxMatched": true
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"step": 2,
|
| 25 |
+
"relativeRms": 0.0070705227996230875,
|
| 26 |
+
"cosine": 0.9999872083248559,
|
| 27 |
+
"finite": true,
|
| 28 |
+
"argmaxMatched": true
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"step": 3,
|
| 32 |
+
"relativeRms": 0.0054854336462296,
|
| 33 |
+
"cosine": 0.9999947383547593,
|
| 34 |
+
"finite": true,
|
| 35 |
+
"argmaxMatched": true
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"bf16Reference": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\onnx-v3\\context-4096-v1",
|
| 39 |
+
"thresholds": {
|
| 40 |
+
"relativeRmsMax": 0.02,
|
| 41 |
+
"cosineMin": 0.999
|
| 42 |
+
},
|
| 43 |
+
"gpu": {
|
| 44 |
+
"vendor": "nvidia",
|
| 45 |
+
"architecture": "blackwell",
|
| 46 |
+
"description": ""
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"passed": true,
|
| 51 |
+
"prefillTokens": 8189,
|
| 52 |
+
"finalCacheTokens": 8192,
|
| 53 |
+
"checks": [
|
| 54 |
+
{
|
| 55 |
+
"step": 0,
|
| 56 |
+
"relativeRms": 0.004995578053810899,
|
| 57 |
+
"cosine": 0.9999959717640318,
|
| 58 |
+
"finite": true,
|
| 59 |
+
"argmaxMatched": true
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"step": 1,
|
| 63 |
+
"relativeRms": 0.004731235493711768,
|
| 64 |
+
"cosine": 0.9999963839464358,
|
| 65 |
+
"finite": true,
|
| 66 |
+
"argmaxMatched": true
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"step": 2,
|
| 70 |
+
"relativeRms": 0.0032514888728384437,
|
| 71 |
+
"cosine": 0.9999964013971677,
|
| 72 |
+
"finite": true,
|
| 73 |
+
"argmaxMatched": true
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"step": 3,
|
| 77 |
+
"relativeRms": 0.00272397268142406,
|
| 78 |
+
"cosine": 0.9999963520250271,
|
| 79 |
+
"finite": true,
|
| 80 |
+
"argmaxMatched": true
|
| 81 |
+
}
|
| 82 |
+
],
|
| 83 |
+
"bf16Reference": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\onnx-v3\\context-8192-v1",
|
| 84 |
+
"thresholds": {
|
| 85 |
+
"relativeRmsMax": 0.02,
|
| 86 |
+
"cosineMin": 0.999
|
| 87 |
+
},
|
| 88 |
+
"gpu": {
|
| 89 |
+
"vendor": "nvidia",
|
| 90 |
+
"architecture": "blackwell",
|
| 91 |
+
"description": ""
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
]
|
| 95 |
+
}
|
provenance/contract.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"cache": "28 pairs of [1,2,past_length,256] FP16 tensors; full storage, exact SW512 mask", "exportScriptSha256": "d910e7633cbb84871e68fc9fdff7296a3f97a7db3669f696859f6f14886ad320", "firstTarget": "FP16 ONNX, FP32 residual/norm/RoPE/softmax", "fixtureSelection": "Fixed plain, native-tool, and 513-token sliding-boundary prompts before ONNX results", "gates": {"browserWebgpuRequired": true, "cosineMin": 0.999, "finiteRequired": true, "prefillAndCachedDecodeRequired": true, "relativeRmsMax": 0.02}, "lastTokenLogitsOnly": true, "nativeArchitectureChanged": false, "source": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\release-compat-v3", "sourceFiles": [{"bytes": 4758, "path": "chat_template.jinja", "sha256": "f9ace5b72165a4d2abb486b73f07b279cbe38bf9e70e66500c095b270966d24f"}, {"bytes": 1970, "path": "config.json", "sha256": "708b5a8c5d64d57d1ae5ceb82c4fc1ca9f2e2769a02d7a7b95ef1e02a98b92c2"}, {"bytes": 4329, "path": "configuration_spark.py", "sha256": "02218597240490f490659b184052db940b08163ff9c3af7b7e59323f6f963722"}, {"bytes": 296, "path": "generation_config.json", "sha256": "5b77f2b5603cd2e3950df71bce8a6d1493ad97e7b6cfbba171eade2e9503224c"}, {"bytes": 1976107880, "path": "model-00001-of-00002.safetensors", "sha256": "885a0f7e30e565a722cd06329d92c580dfed3cfbf430aaa0f1a65073ab95b108"}, {"bytes": 1439232624, "path": "model-00002-of-00002.safetensors", "sha256": "37ae53c04f5c4e8ee6f344f6de4d4204f65da6870e48115633b5b5fd43150f73"}, {"bytes": 19040, "path": "model.safetensors.index.json", "sha256": "e0f06c8f5844f984848203a209da073f2a7abf4fb4c2b3a31b8083d6862960f2"}, {"bytes": 19895, "path": "modeling_spark.py", "sha256": "72310cf0459778878018df788d6ff7aee016cff4f5bb348d8ebd9402ff83fb00"}, {"bytes": 10115785, "path": "tokenizer.json", "sha256": "f71f91ee1b2ac0b27e47bf49ee4859d322ab3d191217ec9964d0189b02454c49"}, {"bytes": 402, "path": "tokenizer_config.json", "sha256": "cf3dc83b97ec9c1d553a5e06045b8a5b627d4554018fa1abad5de95bc767a905"}], "sourcePrecision": "BF16"}
|
provenance/failed-candidates/onnx-v3-context-4096.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"passed": false,
|
| 3 |
+
"prefillTokens": 4093,
|
| 4 |
+
"finalCacheTokens": 4096,
|
| 5 |
+
"checks": [
|
| 6 |
+
{
|
| 7 |
+
"step": 0,
|
| 8 |
+
"relativeRms": 0.009220233118234727,
|
| 9 |
+
"cosine": 0.9999637640549872,
|
| 10 |
+
"finite": true,
|
| 11 |
+
"argmaxMatched": true
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"step": 1,
|
| 15 |
+
"relativeRms": 0.026157863789100646,
|
| 16 |
+
"cosine": 0.9999386339420578,
|
| 17 |
+
"finite": true,
|
| 18 |
+
"argmaxMatched": true
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"step": 2,
|
| 22 |
+
"relativeRms": 0.023572238041187313,
|
| 23 |
+
"cosine": 0.9999520626790142,
|
| 24 |
+
"finite": true,
|
| 25 |
+
"argmaxMatched": true
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"step": 3,
|
| 29 |
+
"relativeRms": 0.01141530784826503,
|
| 30 |
+
"cosine": 0.9999635680247791,
|
| 31 |
+
"finite": true,
|
| 32 |
+
"argmaxMatched": true
|
| 33 |
+
}
|
| 34 |
+
],
|
| 35 |
+
"thresholds": {
|
| 36 |
+
"relativeRmsMax": 0.02,
|
| 37 |
+
"cosineMin": 0.999
|
| 38 |
+
},
|
| 39 |
+
"gpu": {
|
| 40 |
+
"vendor": "nvidia",
|
| 41 |
+
"architecture": "blackwell",
|
| 42 |
+
"description": ""
|
| 43 |
+
}
|
| 44 |
+
}
|
provenance/failed-candidates/onnx-v3-context-8192.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"passed": false,
|
| 3 |
+
"prefillTokens": 8189,
|
| 4 |
+
"finalCacheTokens": 8192,
|
| 5 |
+
"checks": [
|
| 6 |
+
{
|
| 7 |
+
"step": 0,
|
| 8 |
+
"relativeRms": 0.015051070839568784,
|
| 9 |
+
"cosine": 0.9999207051763643,
|
| 10 |
+
"finite": true,
|
| 11 |
+
"argmaxMatched": true
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"step": 1,
|
| 15 |
+
"relativeRms": 0.027335058674360993,
|
| 16 |
+
"cosine": 0.999917062195432,
|
| 17 |
+
"finite": true,
|
| 18 |
+
"argmaxMatched": true
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"step": 2,
|
| 22 |
+
"relativeRms": 0.014439858985928939,
|
| 23 |
+
"cosine": 0.9998961070831498,
|
| 24 |
+
"finite": true,
|
| 25 |
+
"argmaxMatched": true
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"step": 3,
|
| 29 |
+
"relativeRms": 0.015355270590063171,
|
| 30 |
+
"cosine": 0.9999122667865176,
|
| 31 |
+
"finite": true,
|
| 32 |
+
"argmaxMatched": true
|
| 33 |
+
}
|
| 34 |
+
],
|
| 35 |
+
"thresholds": {
|
| 36 |
+
"relativeRmsMax": 0.02,
|
| 37 |
+
"cosineMin": 0.999
|
| 38 |
+
},
|
| 39 |
+
"gpu": {
|
| 40 |
+
"vendor": "nvidia",
|
| 41 |
+
"architecture": "blackwell",
|
| 42 |
+
"description": ""
|
| 43 |
+
}
|
| 44 |
+
}
|
provenance/failed-candidates/onnx-v4-contexts.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"passed": false,
|
| 3 |
+
"contexts": [
|
| 4 |
+
{
|
| 5 |
+
"passed": false,
|
| 6 |
+
"prefillTokens": 4093,
|
| 7 |
+
"finalCacheTokens": 4096,
|
| 8 |
+
"checks": [
|
| 9 |
+
{
|
| 10 |
+
"step": 0,
|
| 11 |
+
"relativeRms": 0.020007230013974447,
|
| 12 |
+
"cosine": 0.9999656806869889,
|
| 13 |
+
"finite": true,
|
| 14 |
+
"argmaxMatched": true
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"step": 1,
|
| 18 |
+
"relativeRms": 0.008157499870038392,
|
| 19 |
+
"cosine": 0.9999743107220318,
|
| 20 |
+
"finite": true,
|
| 21 |
+
"argmaxMatched": true
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"step": 2,
|
| 25 |
+
"relativeRms": 0.015806139627476817,
|
| 26 |
+
"cosine": 0.9999596609042387,
|
| 27 |
+
"finite": true,
|
| 28 |
+
"argmaxMatched": true
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"step": 3,
|
| 32 |
+
"relativeRms": 0.007921036733072777,
|
| 33 |
+
"cosine": 0.999968629896532,
|
| 34 |
+
"finite": true,
|
| 35 |
+
"argmaxMatched": true
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"bf16Reference": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\onnx-v3\\context-4096-v1",
|
| 39 |
+
"thresholds": {
|
| 40 |
+
"relativeRmsMax": 0.02,
|
| 41 |
+
"cosineMin": 0.999
|
| 42 |
+
},
|
| 43 |
+
"gpu": {
|
| 44 |
+
"vendor": "nvidia",
|
| 45 |
+
"architecture": "blackwell",
|
| 46 |
+
"description": ""
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"passed": true,
|
| 51 |
+
"prefillTokens": 8189,
|
| 52 |
+
"finalCacheTokens": 8192,
|
| 53 |
+
"checks": [
|
| 54 |
+
{
|
| 55 |
+
"step": 0,
|
| 56 |
+
"relativeRms": 0.007033043927414726,
|
| 57 |
+
"cosine": 0.9999768772705387,
|
| 58 |
+
"finite": true,
|
| 59 |
+
"argmaxMatched": true
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"step": 1,
|
| 63 |
+
"relativeRms": 0.006613408012783018,
|
| 64 |
+
"cosine": 0.9999818022634543,
|
| 65 |
+
"finite": true,
|
| 66 |
+
"argmaxMatched": true
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"step": 2,
|
| 70 |
+
"relativeRms": 0.008671847675117958,
|
| 71 |
+
"cosine": 0.9999813470148041,
|
| 72 |
+
"finite": true,
|
| 73 |
+
"argmaxMatched": true
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"step": 3,
|
| 77 |
+
"relativeRms": 0.012292306035675759,
|
| 78 |
+
"cosine": 0.9999609656408943,
|
| 79 |
+
"finite": true,
|
| 80 |
+
"argmaxMatched": true
|
| 81 |
+
}
|
| 82 |
+
],
|
| 83 |
+
"bf16Reference": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\onnx-v3\\context-8192-v1",
|
| 84 |
+
"thresholds": {
|
| 85 |
+
"relativeRmsMax": 0.02,
|
| 86 |
+
"cosineMin": 0.999
|
| 87 |
+
},
|
| 88 |
+
"gpu": {
|
| 89 |
+
"vendor": "nvidia",
|
| 90 |
+
"architecture": "blackwell",
|
| 91 |
+
"description": ""
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
]
|
| 95 |
+
}
|
provenance/fixtures.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[{"inputIds": [0, 130972, 198, 18178, 599, 259, 18639, 31627, 27, 1, 0, 130973, 1099, 1135, 23612, 25, 1568, 2715, 259, 22968, 793, 44, 1, 0, 130976, 4], "messages": [{"content": "In one sentence, what does a browser do?", "role": "user"}], "name": "plain", "teacherTokens": [46, 22968, 390, 259], "tools": null}, {"inputIds": [0, 130972, 198, 18178, 599, 259, 18639, 31627, 27, 2257, 55260, 198, 3683, 760, 4561, 312, 275, 4305, 9928, 39, 198, 41, 37788, 43, 198, 23421, 2215, 4068, 518, 9026, 18672, 1078, 518, 21311, 4068, 518, 14623, 259, 19686, 304, 275, 22968, 34028, 518, 76248, 4068, 24254, 3097, 4068, 518, 9571, 1078, 518, 65263, 4068, 24254, 7062, 4068, 24254, 3097, 4068, 518, 2943, 15, 35951, 518, 40976, 4068, 21518, 7062, 7872, 6678, 198, 2717, 37788, 43, 198, 198, 21968, 275, 6702, 10156, 1430, 5509, 312, 3175, 259, 5722, 27, 1, 0, 130973, 14623, 9880, 3764, 30801, 2581, 478, 3175, 18672, 27, 1, 0, 130976, 4], "messages": [{"content": "Use the provided tool when asked to open a page.", "role": "system"}, {"content": "Open https://example.com with open_url.", "role": "user"}], "name": "native_tool", "teacherTokens": [130977, 9026, 18672, 130980], "tools": [{"function": {"description": "Open a URL in the browser.", "name": "open_url", "parameters": {"properties": {"url": {"type": "string"}}, "required": ["url"], "type": "object"}}, "type": "function"}]}, {"inputIds": [0, 130972, 198, 18178, 599, 259, 18639, 31627, 27, 1, 0, 130973, 19785, 23204, 39, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281, 5722, 27, 22968, 7281], "messages": [{"content": "Reference facts: browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. browser web page. Summarize briefly.", "role": "user"}], "name": "sliding_boundary_513", "teacherTokens": [5722, 27, 22968, 7281], "tools": null}]
|
provenance/gpu-identity.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"dxgi": {"name": "NVIDIA GeForce RTX 5090", "vendor": 4318, "device": 11141, "bytes": 33750515712, "low": 82094, "high": 0, "luidHex": "00000000000140ae"}, "renderer": "ANGLE (NVIDIA, NVIDIA GeForce RTX 5090 (0x00002B85) Direct3D11 vs_5_0 ps_5_0, D3D11-32.0.15.9621)"}
|
provenance/numerical-validation.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"checks": [{"bf16Argmax": 46, "case": "plain", "cosine": 0.9999983318679939, "finite": true, "onnxArgmax": 46, "relativeRms": 0.0023535529105786494, "step": 0}, {"bf16Argmax": 22968, "case": "plain", "cosine": 0.9999987535852, "finite": true, "onnxArgmax": 22968, "relativeRms": 0.0030139244059979877, "step": 1}, {"bf16Argmax": 390, "case": "plain", "cosine": 0.9999981596042267, "finite": true, "onnxArgmax": 390, "relativeRms": 0.002366490766130801, "step": 2}, {"bf16Argmax": 259, "case": "plain", "cosine": 0.999998556994053, "finite": true, "onnxArgmax": 259, "relativeRms": 0.0018329192679691832, "step": 3}, {"bf16Argmax": 130977, "case": "native_tool", "cosine": 0.9999978277641923, "finite": true, "onnxArgmax": 130977, "relativeRms": 0.0029435711629375023, "step": 0}, {"bf16Argmax": 9026, "case": "native_tool", "cosine": 0.9999977002591307, "finite": true, "onnxArgmax": 9026, "relativeRms": 0.0035400972498281697, "step": 1}, {"bf16Argmax": 18672, "case": "native_tool", "cosine": 0.9999976893894008, "finite": true, "onnxArgmax": 18672, "relativeRms": 0.0021608613620854662, "step": 2}, {"bf16Argmax": 130980, "case": "native_tool", "cosine": 0.9999978527693303, "finite": true, "onnxArgmax": 130980, "relativeRms": 0.0022944007951501534, "step": 3}, {"bf16Argmax": 5722, "case": "sliding_boundary_513", "cosine": 0.9999970619103299, "finite": true, "onnxArgmax": 5722, "relativeRms": 0.004931757085811373, "step": 0}, {"bf16Argmax": 27, "case": "sliding_boundary_513", "cosine": 0.9999985959699549, "finite": true, "onnxArgmax": 27, "relativeRms": 0.001820880042814343, "step": 1}, {"bf16Argmax": 22968, "case": "sliding_boundary_513", "cosine": 0.9999982844866637, "finite": true, "onnxArgmax": 22968, "relativeRms": 0.0018555670023478535, "step": 2}, {"bf16Argmax": 7281, "case": "sliding_boundary_513", "cosine": 0.9999971391883117, "finite": true, "onnxArgmax": 7281, "relativeRms": 0.002577718855276488, "step": 3}], "passed": true, "precision": "FP16 ONNX versus BF16", "runtime": "1.27.0", "thresholds": {"cosineMin": 0.999, "relativeRmsMax": 0.02}}
|
provenance/precision-correction.json
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"source": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\onnx-v3",
|
| 3 |
+
"candidate": "D:\\webbrain-training\\compass-tiny-v3-spark-x25-20260926\\onnx-v5",
|
| 4 |
+
"precisionOnlyChange": true,
|
| 5 |
+
"changedNodes": [
|
| 6 |
+
"/layers.0/self_attn/q_k_v_proj/MatMul",
|
| 7 |
+
"/layers.0/self_attn/g_proj/MatMul",
|
| 8 |
+
"/layers.0/self_attn/MatMul",
|
| 9 |
+
"/layers.0/self_attn/MatMul_1",
|
| 10 |
+
"/layers.0/self_attn/out_proj/MatMul",
|
| 11 |
+
"/layers.0/mlp/gate_proj/MatMul",
|
| 12 |
+
"/layers.0/mlp/up_proj/MatMul",
|
| 13 |
+
"/layers.0/mlp/down_proj/MatMul",
|
| 14 |
+
"/layers.1/self_attn/q_k_v_proj/MatMul",
|
| 15 |
+
"/layers.1/self_attn/g_proj/MatMul",
|
| 16 |
+
"/layers.1/self_attn/MatMul",
|
| 17 |
+
"/layers.1/self_attn/MatMul_1",
|
| 18 |
+
"/layers.1/self_attn/out_proj/MatMul",
|
| 19 |
+
"/layers.1/mlp/gate_proj/MatMul",
|
| 20 |
+
"/layers.1/mlp/up_proj/MatMul",
|
| 21 |
+
"/layers.1/mlp/down_proj/MatMul",
|
| 22 |
+
"/layers.2/self_attn/q_k_v_proj/MatMul",
|
| 23 |
+
"/layers.2/self_attn/g_proj/MatMul",
|
| 24 |
+
"/layers.2/self_attn/MatMul",
|
| 25 |
+
"/layers.2/self_attn/MatMul_1",
|
| 26 |
+
"/layers.2/self_attn/out_proj/MatMul",
|
| 27 |
+
"/layers.2/mlp/gate_proj/MatMul",
|
| 28 |
+
"/layers.2/mlp/up_proj/MatMul",
|
| 29 |
+
"/layers.2/mlp/down_proj/MatMul",
|
| 30 |
+
"/layers.3/self_attn/q_k_v_proj/MatMul",
|
| 31 |
+
"/layers.3/self_attn/g_proj/MatMul",
|
| 32 |
+
"/layers.3/self_attn/MatMul",
|
| 33 |
+
"/layers.3/self_attn/MatMul_1",
|
| 34 |
+
"/layers.3/self_attn/out_proj/MatMul",
|
| 35 |
+
"/layers.3/mlp/gate_proj/MatMul",
|
| 36 |
+
"/layers.3/mlp/up_proj/MatMul",
|
| 37 |
+
"/layers.3/mlp/down_proj/MatMul",
|
| 38 |
+
"/layers.4/self_attn/q_k_v_proj/MatMul",
|
| 39 |
+
"/layers.4/self_attn/g_proj/MatMul",
|
| 40 |
+
"/layers.4/self_attn/MatMul",
|
| 41 |
+
"/layers.4/self_attn/MatMul_1",
|
| 42 |
+
"/layers.4/self_attn/out_proj/MatMul",
|
| 43 |
+
"/layers.4/mlp/gate_proj/MatMul",
|
| 44 |
+
"/layers.4/mlp/up_proj/MatMul",
|
| 45 |
+
"/layers.4/mlp/down_proj/MatMul",
|
| 46 |
+
"/layers.5/self_attn/q_k_v_proj/MatMul",
|
| 47 |
+
"/layers.5/self_attn/g_proj/MatMul",
|
| 48 |
+
"/layers.5/self_attn/MatMul",
|
| 49 |
+
"/layers.5/self_attn/MatMul_1",
|
| 50 |
+
"/layers.5/self_attn/out_proj/MatMul",
|
| 51 |
+
"/layers.5/mlp/gate_proj/MatMul",
|
| 52 |
+
"/layers.5/mlp/up_proj/MatMul",
|
| 53 |
+
"/layers.5/mlp/down_proj/MatMul",
|
| 54 |
+
"/layers.6/self_attn/q_k_v_proj/MatMul",
|
| 55 |
+
"/layers.6/self_attn/g_proj/MatMul",
|
| 56 |
+
"/layers.6/self_attn/MatMul",
|
| 57 |
+
"/layers.6/self_attn/MatMul_1",
|
| 58 |
+
"/layers.6/self_attn/out_proj/MatMul",
|
| 59 |
+
"/layers.6/mlp/gate_proj/MatMul",
|
| 60 |
+
"/layers.6/mlp/up_proj/MatMul",
|
| 61 |
+
"/layers.6/mlp/down_proj/MatMul",
|
| 62 |
+
"/layers.7/self_attn/q_k_v_proj/MatMul",
|
| 63 |
+
"/layers.7/self_attn/g_proj/MatMul",
|
| 64 |
+
"/layers.7/self_attn/MatMul",
|
| 65 |
+
"/layers.7/self_attn/MatMul_1",
|
| 66 |
+
"/layers.7/self_attn/out_proj/MatMul",
|
| 67 |
+
"/layers.7/mlp/gate_proj/MatMul",
|
| 68 |
+
"/layers.7/mlp/up_proj/MatMul",
|
| 69 |
+
"/layers.7/mlp/down_proj/MatMul",
|
| 70 |
+
"/layers.8/self_attn/q_k_v_proj/MatMul",
|
| 71 |
+
"/layers.8/self_attn/g_proj/MatMul",
|
| 72 |
+
"/layers.8/self_attn/MatMul",
|
| 73 |
+
"/layers.8/self_attn/MatMul_1",
|
| 74 |
+
"/layers.8/self_attn/out_proj/MatMul",
|
| 75 |
+
"/layers.8/mlp/gate_proj/MatMul",
|
| 76 |
+
"/layers.8/mlp/up_proj/MatMul",
|
| 77 |
+
"/layers.8/mlp/down_proj/MatMul",
|
| 78 |
+
"/layers.9/self_attn/q_k_v_proj/MatMul",
|
| 79 |
+
"/layers.9/self_attn/g_proj/MatMul",
|
| 80 |
+
"/layers.9/self_attn/MatMul",
|
| 81 |
+
"/layers.9/self_attn/MatMul_1",
|
| 82 |
+
"/layers.9/self_attn/out_proj/MatMul",
|
| 83 |
+
"/layers.9/mlp/gate_proj/MatMul",
|
| 84 |
+
"/layers.9/mlp/up_proj/MatMul",
|
| 85 |
+
"/layers.9/mlp/down_proj/MatMul",
|
| 86 |
+
"/layers.10/self_attn/q_k_v_proj/MatMul",
|
| 87 |
+
"/layers.10/self_attn/g_proj/MatMul",
|
| 88 |
+
"/layers.10/self_attn/MatMul",
|
| 89 |
+
"/layers.10/self_attn/MatMul_1",
|
| 90 |
+
"/layers.10/self_attn/out_proj/MatMul",
|
| 91 |
+
"/layers.10/mlp/gate_proj/MatMul",
|
| 92 |
+
"/layers.10/mlp/up_proj/MatMul",
|
| 93 |
+
"/layers.10/mlp/down_proj/MatMul",
|
| 94 |
+
"/layers.11/self_attn/q_k_v_proj/MatMul",
|
| 95 |
+
"/layers.11/self_attn/g_proj/MatMul",
|
| 96 |
+
"/layers.11/self_attn/MatMul",
|
| 97 |
+
"/layers.11/self_attn/MatMul_1",
|
| 98 |
+
"/layers.11/self_attn/out_proj/MatMul",
|
| 99 |
+
"/layers.11/mlp/gate_proj/MatMul",
|
| 100 |
+
"/layers.11/mlp/up_proj/MatMul",
|
| 101 |
+
"/layers.11/mlp/down_proj/MatMul",
|
| 102 |
+
"/layers.12/self_attn/q_k_v_proj/MatMul",
|
| 103 |
+
"/layers.12/self_attn/g_proj/MatMul",
|
| 104 |
+
"/layers.12/self_attn/MatMul",
|
| 105 |
+
"/layers.12/self_attn/MatMul_1",
|
| 106 |
+
"/layers.12/self_attn/out_proj/MatMul",
|
| 107 |
+
"/layers.12/mlp/gate_proj/MatMul",
|
| 108 |
+
"/layers.12/mlp/up_proj/MatMul",
|
| 109 |
+
"/layers.12/mlp/down_proj/MatMul",
|
| 110 |
+
"/layers.13/self_attn/q_k_v_proj/MatMul",
|
| 111 |
+
"/layers.13/self_attn/g_proj/MatMul",
|
| 112 |
+
"/layers.13/self_attn/MatMul",
|
| 113 |
+
"/layers.13/self_attn/MatMul_1",
|
| 114 |
+
"/layers.13/self_attn/out_proj/MatMul",
|
| 115 |
+
"/layers.13/mlp/gate_proj/MatMul",
|
| 116 |
+
"/layers.13/mlp/up_proj/MatMul",
|
| 117 |
+
"/layers.13/mlp/down_proj/MatMul",
|
| 118 |
+
"/layers.14/self_attn/q_k_v_proj/MatMul",
|
| 119 |
+
"/layers.14/self_attn/g_proj/MatMul",
|
| 120 |
+
"/layers.14/self_attn/MatMul",
|
| 121 |
+
"/layers.14/self_attn/MatMul_1",
|
| 122 |
+
"/layers.14/self_attn/out_proj/MatMul",
|
| 123 |
+
"/layers.14/mlp/gate_proj/MatMul",
|
| 124 |
+
"/layers.14/mlp/up_proj/MatMul",
|
| 125 |
+
"/layers.14/mlp/down_proj/MatMul",
|
| 126 |
+
"/layers.15/self_attn/q_k_v_proj/MatMul",
|
| 127 |
+
"/layers.15/self_attn/g_proj/MatMul",
|
| 128 |
+
"/layers.15/self_attn/MatMul",
|
| 129 |
+
"/layers.15/self_attn/MatMul_1",
|
| 130 |
+
"/layers.15/self_attn/out_proj/MatMul",
|
| 131 |
+
"/layers.15/mlp/gate_proj/MatMul",
|
| 132 |
+
"/layers.15/mlp/up_proj/MatMul",
|
| 133 |
+
"/layers.15/mlp/down_proj/MatMul",
|
| 134 |
+
"/layers.16/self_attn/q_k_v_proj/MatMul",
|
| 135 |
+
"/layers.16/self_attn/g_proj/MatMul",
|
| 136 |
+
"/layers.16/self_attn/MatMul",
|
| 137 |
+
"/layers.16/self_attn/MatMul_1",
|
| 138 |
+
"/layers.16/self_attn/out_proj/MatMul",
|
| 139 |
+
"/layers.16/mlp/gate_proj/MatMul",
|
| 140 |
+
"/layers.16/mlp/up_proj/MatMul",
|
| 141 |
+
"/layers.16/mlp/down_proj/MatMul",
|
| 142 |
+
"/layers.17/self_attn/q_k_v_proj/MatMul",
|
| 143 |
+
"/layers.17/self_attn/g_proj/MatMul",
|
| 144 |
+
"/layers.17/self_attn/MatMul",
|
| 145 |
+
"/layers.17/self_attn/MatMul_1",
|
| 146 |
+
"/layers.17/self_attn/out_proj/MatMul",
|
| 147 |
+
"/layers.17/mlp/gate_proj/MatMul",
|
| 148 |
+
"/layers.17/mlp/up_proj/MatMul",
|
| 149 |
+
"/layers.17/mlp/down_proj/MatMul",
|
| 150 |
+
"/layers.18/self_attn/q_k_v_proj/MatMul",
|
| 151 |
+
"/layers.18/self_attn/g_proj/MatMul",
|
| 152 |
+
"/layers.18/self_attn/MatMul",
|
| 153 |
+
"/layers.18/self_attn/MatMul_1",
|
| 154 |
+
"/layers.18/self_attn/out_proj/MatMul",
|
| 155 |
+
"/layers.18/mlp/gate_proj/MatMul",
|
| 156 |
+
"/layers.18/mlp/up_proj/MatMul",
|
| 157 |
+
"/layers.18/mlp/down_proj/MatMul",
|
| 158 |
+
"/layers.19/self_attn/q_k_v_proj/MatMul",
|
| 159 |
+
"/layers.19/self_attn/g_proj/MatMul",
|
| 160 |
+
"/layers.19/self_attn/MatMul",
|
| 161 |
+
"/layers.19/self_attn/MatMul_1",
|
| 162 |
+
"/layers.19/self_attn/out_proj/MatMul",
|
| 163 |
+
"/layers.19/mlp/gate_proj/MatMul",
|
| 164 |
+
"/layers.19/mlp/up_proj/MatMul",
|
| 165 |
+
"/layers.19/mlp/down_proj/MatMul",
|
| 166 |
+
"/layers.20/self_attn/q_k_v_proj/MatMul",
|
| 167 |
+
"/layers.20/self_attn/g_proj/MatMul",
|
| 168 |
+
"/layers.20/self_attn/MatMul",
|
| 169 |
+
"/layers.20/self_attn/MatMul_1",
|
| 170 |
+
"/layers.20/self_attn/out_proj/MatMul",
|
| 171 |
+
"/layers.20/mlp/gate_proj/MatMul",
|
| 172 |
+
"/layers.20/mlp/up_proj/MatMul",
|
| 173 |
+
"/layers.20/mlp/down_proj/MatMul",
|
| 174 |
+
"/layers.21/self_attn/q_k_v_proj/MatMul",
|
| 175 |
+
"/layers.21/self_attn/g_proj/MatMul",
|
| 176 |
+
"/layers.21/self_attn/MatMul",
|
| 177 |
+
"/layers.21/self_attn/MatMul_1",
|
| 178 |
+
"/layers.21/self_attn/out_proj/MatMul",
|
| 179 |
+
"/layers.21/mlp/gate_proj/MatMul",
|
| 180 |
+
"/layers.21/mlp/up_proj/MatMul",
|
| 181 |
+
"/layers.21/mlp/down_proj/MatMul",
|
| 182 |
+
"/layers.22/self_attn/q_k_v_proj/MatMul",
|
| 183 |
+
"/layers.22/self_attn/g_proj/MatMul",
|
| 184 |
+
"/layers.22/self_attn/MatMul",
|
| 185 |
+
"/layers.22/self_attn/MatMul_1",
|
| 186 |
+
"/layers.22/self_attn/out_proj/MatMul",
|
| 187 |
+
"/layers.22/mlp/gate_proj/MatMul",
|
| 188 |
+
"/layers.22/mlp/up_proj/MatMul",
|
| 189 |
+
"/layers.22/mlp/down_proj/MatMul",
|
| 190 |
+
"/layers.23/self_attn/q_k_v_proj/MatMul",
|
| 191 |
+
"/layers.23/self_attn/g_proj/MatMul",
|
| 192 |
+
"/layers.23/self_attn/MatMul",
|
| 193 |
+
"/layers.23/self_attn/MatMul_1",
|
| 194 |
+
"/layers.23/self_attn/out_proj/MatMul",
|
| 195 |
+
"/layers.23/mlp/gate_proj/MatMul",
|
| 196 |
+
"/layers.23/mlp/up_proj/MatMul",
|
| 197 |
+
"/layers.23/mlp/down_proj/MatMul",
|
| 198 |
+
"/layers.24/self_attn/q_k_v_proj/MatMul",
|
| 199 |
+
"/layers.24/self_attn/g_proj/MatMul",
|
| 200 |
+
"/layers.24/self_attn/MatMul",
|
| 201 |
+
"/layers.24/self_attn/MatMul_1",
|
| 202 |
+
"/layers.24/self_attn/out_proj/MatMul",
|
| 203 |
+
"/layers.24/mlp/gate_proj/MatMul",
|
| 204 |
+
"/layers.24/mlp/up_proj/MatMul",
|
| 205 |
+
"/layers.24/mlp/down_proj/MatMul",
|
| 206 |
+
"/layers.25/self_attn/q_k_v_proj/MatMul",
|
| 207 |
+
"/layers.25/self_attn/g_proj/MatMul",
|
| 208 |
+
"/layers.25/self_attn/MatMul",
|
| 209 |
+
"/layers.25/self_attn/MatMul_1",
|
| 210 |
+
"/layers.25/self_attn/out_proj/MatMul",
|
| 211 |
+
"/layers.25/mlp/gate_proj/MatMul",
|
| 212 |
+
"/layers.25/mlp/up_proj/MatMul",
|
| 213 |
+
"/layers.25/mlp/down_proj/MatMul",
|
| 214 |
+
"/layers.26/self_attn/q_k_v_proj/MatMul",
|
| 215 |
+
"/layers.26/self_attn/g_proj/MatMul",
|
| 216 |
+
"/layers.26/self_attn/MatMul",
|
| 217 |
+
"/layers.26/self_attn/MatMul_1",
|
| 218 |
+
"/layers.26/self_attn/out_proj/MatMul",
|
| 219 |
+
"/layers.26/mlp/gate_proj/MatMul",
|
| 220 |
+
"/layers.26/mlp/up_proj/MatMul",
|
| 221 |
+
"/layers.26/mlp/down_proj/MatMul",
|
| 222 |
+
"/layers.27/self_attn/q_k_v_proj/MatMul",
|
| 223 |
+
"/layers.27/self_attn/g_proj/MatMul",
|
| 224 |
+
"/layers.27/self_attn/MatMul",
|
| 225 |
+
"/layers.27/self_attn/MatMul_1",
|
| 226 |
+
"/layers.27/self_attn/out_proj/MatMul",
|
| 227 |
+
"/layers.27/mlp/gate_proj/MatMul",
|
| 228 |
+
"/layers.27/mlp/up_proj/MatMul",
|
| 229 |
+
"/layers.27/mlp/down_proj/MatMul",
|
| 230 |
+
"/MatMul"
|
| 231 |
+
],
|
| 232 |
+
"fp16WeightSha256": "9abbd8c7e69fbdb9bb4fe6244c30b66a397a4f237dbfc75e95dd11062db3acdc",
|
| 233 |
+
"sourceWeightSha256": "9abbd8c7e69fbdb9bb4fe6244c30b66a397a4f237dbfc75e95dd11062db3acdc",
|
| 234 |
+
"reason": "ORT WebGPU FP16 MatMul accumulation drift on 4K/8K probes; promote GEMM compute to FP32 while retaining FP16 weight/cache storage",
|
| 235 |
+
"architectureOrSemanticMaskChanged": false,
|
| 236 |
+
"thresholdsChanged": false
|
| 237 |
+
}
|
provenance/scripts/export_spark.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Spark-native cached ONNX export; no architecture remapping or retraining."""
|
| 2 |
+
import argparse
|
| 3 |
+
import hashlib
|
| 4 |
+
import importlib
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import shutil
|
| 9 |
+
import sys
|
| 10 |
+
import time
|
| 11 |
+
|
| 12 |
+
SOURCE = Path(__file__).parents[1] / 'spark_x25_17b_webbrain_compass_v3'
|
| 13 |
+
sys.path.insert(0, str(SOURCE))
|
| 14 |
+
from prepare import sha, write_json
|
| 15 |
+
from train import gpu_guard
|
| 16 |
+
import torch
|
| 17 |
+
|
| 18 |
+
ROOT = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926\onnx-v3')
|
| 19 |
+
MODEL = ROOT.parent / 'release-compat-v3'
|
| 20 |
+
CFG = json.loads((SOURCE / 'train-config.json').read_text())
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def event(stage, **fields):
|
| 24 |
+
record = {'stage': stage, 'unixTime': time.time(), **fields}
|
| 25 |
+
with (ROOT / 'events.jsonl').open('a', encoding='utf-8') as f:
|
| 26 |
+
f.write(json.dumps(record) + '\n')
|
| 27 |
+
f.flush()
|
| 28 |
+
os.fsync(f.fileno())
|
| 29 |
+
print(json.dumps(record), flush=True)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class TensorCache:
|
| 33 |
+
def __init__(self, past):
|
| 34 |
+
self.past = past
|
| 35 |
+
self.present = []
|
| 36 |
+
|
| 37 |
+
def update(self, k, v, layer_idx, cache_kwargs):
|
| 38 |
+
k = torch.cat((self.past[2 * layer_idx], k), dim=2)
|
| 39 |
+
v = torch.cat((self.past[2 * layer_idx + 1], v), dim=2)
|
| 40 |
+
self.present.extend((k, v))
|
| 41 |
+
return k, v
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class CachedSpark(torch.nn.Module):
|
| 45 |
+
"""Use original decoder layers, norms, gates and RoPE; tensor-only cache."""
|
| 46 |
+
def __init__(self, model):
|
| 47 |
+
super().__init__()
|
| 48 |
+
self.native = model
|
| 49 |
+
self.helpers = importlib.import_module(model.__class__.__module__)
|
| 50 |
+
self.config = model.config
|
| 51 |
+
|
| 52 |
+
def forward(self, input_ids, position_ids, *past):
|
| 53 |
+
c = self.config
|
| 54 |
+
hidden = self.native.model.embedding(input_ids).float()
|
| 55 |
+
cache = TensorCache(past)
|
| 56 |
+
keys = torch.arange(past[0].shape[2] + input_ids.shape[1], device=input_ids.device)
|
| 57 |
+
queries = position_ids.reshape(-1)
|
| 58 |
+
causal = queries[:, None] >= keys[None, :]
|
| 59 |
+
sliding = causal & (keys[None, :] > queries[:, None] - c.sliding_window)
|
| 60 |
+
dtype = self.native.model.embedding.weight.dtype
|
| 61 |
+
masks = {name: torch.where(allowed, 0., torch.finfo(dtype).min).to(dtype)[None, None]
|
| 62 |
+
for name, allowed in [('full_attention', causal), ('sliding_attention', sliding)]}
|
| 63 |
+
ropes = {}
|
| 64 |
+
for layer_type in ['full_attention', 'sliding_attention']:
|
| 65 |
+
ropes[layer_type] = self.helpers.compute_rope_cos_sin(queries, c.head_dim, c.get_rope_theta(layer_type),
|
| 66 |
+
c.get_partial_rotary_factor(layer_type), device=input_ids.device)
|
| 67 |
+
for layer in self.native.model.layers:
|
| 68 |
+
hidden = layer(hidden, position_embeddings=ropes[layer.layer_type],
|
| 69 |
+
attention_mask=masks[layer.layer_type], past_key_values=cache,
|
| 70 |
+
cache_position=queries, position_ids=position_ids)
|
| 71 |
+
hidden = self.native.model.norm(hidden).to(dtype)[:, -1:, :]
|
| 72 |
+
logits = torch.nn.functional.linear(hidden, self.native.model.embedding.weight).float()
|
| 73 |
+
return (logits, *cache.present)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def empty_past(c, device='cpu'):
|
| 77 |
+
return [torch.empty(1, c.num_key_value_heads, 0, c.head_dim, dtype=torch.float16, device=device)
|
| 78 |
+
for _ in range(2 * c.num_hidden_layers)]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def make_contract():
|
| 82 |
+
ROOT.mkdir(exist_ok=True)
|
| 83 |
+
proof = json.loads((MODEL / 'provenance/release-validation.json').read_text())
|
| 84 |
+
assert proof['passed'] and proof['cachedGenerationPassed']
|
| 85 |
+
inventory = [{'path': p.relative_to(MODEL).as_posix(), 'sha256': sha(p), 'bytes': p.stat().st_size}
|
| 86 |
+
for p in MODEL.glob('*') if p.is_file() and p.suffix in ('.json', '.safetensors', '.py', '.jinja')]
|
| 87 |
+
plan = {'source': str(MODEL), 'sourceFiles': inventory, 'exportScriptSha256': sha(__file__),
|
| 88 |
+
'sourcePrecision': 'BF16', 'firstTarget': 'FP16 ONNX, FP32 residual/norm/RoPE/softmax',
|
| 89 |
+
'cache': '28 pairs of [1,2,past_length,256] FP16 tensors; full storage, exact SW512 mask',
|
| 90 |
+
'lastTokenLogitsOnly': True, 'nativeArchitectureChanged': False,
|
| 91 |
+
'gates': {'relativeRmsMax': .02, 'cosineMin': .999, 'finiteRequired': True,
|
| 92 |
+
'prefillAndCachedDecodeRequired': True, 'browserWebgpuRequired': True},
|
| 93 |
+
'fixtureSelection': 'Fixed plain, native-tool, and 513-token sliding-boundary prompts before ONNX results'}
|
| 94 |
+
target = ROOT / 'contract.json'
|
| 95 |
+
if target.exists():
|
| 96 |
+
assert json.loads(target.read_text()) == plan, 'Frozen ONNX contract drift'
|
| 97 |
+
else:
|
| 98 |
+
write_json(target, plan)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def reference():
|
| 102 |
+
make_contract()
|
| 103 |
+
gpu_guard(CFG)
|
| 104 |
+
from transformers import AutoTokenizer
|
| 105 |
+
import runtime
|
| 106 |
+
torch.set_num_threads(8)
|
| 107 |
+
torch.backends.cuda.matmul.allow_tf32 = False
|
| 108 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL, local_files_only=True)
|
| 109 |
+
model = runtime.load_native(str(MODEL), dtype=torch.bfloat16, device_map={'': 0}).eval()
|
| 110 |
+
tools = [{'type': 'function', 'function': {'name': 'open_url', 'description': 'Open a URL in the browser.',
|
| 111 |
+
'parameters': {'type': 'object', 'properties': {'url': {'type': 'string'}}, 'required': ['url']}}}]
|
| 112 |
+
prompts = [
|
| 113 |
+
{'name': 'plain', 'messages': [{'role': 'user', 'content': 'In one sentence, what does a browser do?'}], 'tools': None},
|
| 114 |
+
{'name': 'native_tool', 'messages': [{'role': 'system', 'content': 'Use the provided tool when asked to open a page.'},
|
| 115 |
+
{'role': 'user', 'content': 'Open https://example.com with open_url.'}], 'tools': tools},
|
| 116 |
+
{'name': 'sliding_boundary_513', 'messages': [{'role': 'user', 'content': 'Reference facts: ' + 'browser web page. ' * 180 + ' Summarize briefly.'}], 'tools': None},
|
| 117 |
+
]
|
| 118 |
+
fixtures = []
|
| 119 |
+
(ROOT / 'reference').mkdir(exist_ok=True)
|
| 120 |
+
import numpy as np
|
| 121 |
+
for case in prompts:
|
| 122 |
+
encoded = tokenizer.apply_chat_template(case['messages'], tools=case['tools'], enable_thinking=False,
|
| 123 |
+
add_generation_prompt=True, tokenize=True, return_tensors='pt', return_dict=True)
|
| 124 |
+
ids = encoded['input_ids'][0].tolist()
|
| 125 |
+
if case['name'] == 'sliding_boundary_513':
|
| 126 |
+
ids = ids[:513]
|
| 127 |
+
assert len(ids) > 0
|
| 128 |
+
tensors = torch.tensor([ids], device='cuda')
|
| 129 |
+
# Full-storage cache preserves simple ABI; native mask semantics unchanged.
|
| 130 |
+
from transformers.cache_utils import DynamicCache
|
| 131 |
+
cache = DynamicCache(config=None)
|
| 132 |
+
chosen = []
|
| 133 |
+
for step in range(4):
|
| 134 |
+
with torch.no_grad():
|
| 135 |
+
result = model(input_ids=tensors, past_key_values=cache, use_cache=True, logits_to_keep=1)
|
| 136 |
+
logits = result.logits[0, -1].float().cpu().numpy()
|
| 137 |
+
np.save(ROOT / 'reference' / f'{case["name"]}-{step}.npy', logits)
|
| 138 |
+
token = int(logits.argmax())
|
| 139 |
+
chosen.append(token)
|
| 140 |
+
tensors = torch.tensor([[token]], device='cuda')
|
| 141 |
+
fixtures.append({**case, 'inputIds': ids, 'teacherTokens': chosen})
|
| 142 |
+
event('bf16_fixture_recorded', name=case['name'], promptTokens=len(ids))
|
| 143 |
+
write_json(ROOT / 'fixtures.json', fixtures)
|
| 144 |
+
event('reference_complete', fixtures=len(fixtures))
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def export():
|
| 148 |
+
make_contract()
|
| 149 |
+
import runtime
|
| 150 |
+
import onnx
|
| 151 |
+
torch.set_num_threads(8)
|
| 152 |
+
model = runtime.load_native(str(MODEL), dtype=torch.float16, device_map={'': 'cpu'}).eval()
|
| 153 |
+
wrapper = CachedSpark(model).eval()
|
| 154 |
+
c = model.config
|
| 155 |
+
ids = torch.tensor([[1, 321, 765, 24, 44, 2, 23, 26]], dtype=torch.int64)
|
| 156 |
+
pos = torch.arange(2, 10)[None]
|
| 157 |
+
past = [torch.zeros(1, c.num_key_value_heads, 2, c.head_dim, dtype=torch.float16)
|
| 158 |
+
for _ in range(2 * c.num_hidden_layers)]
|
| 159 |
+
inputs = ['input_ids', 'position_ids'] + [f'past_key_values.{i}.{kind}' for i in range(c.num_hidden_layers) for kind in ('key', 'value')]
|
| 160 |
+
outputs = ['logits'] + [f'present.{i}.{kind}' for i in range(c.num_hidden_layers) for kind in ('key', 'value')]
|
| 161 |
+
axes = {'input_ids': {1: 'sequence_length'}, 'position_ids': {1: 'sequence_length'}}
|
| 162 |
+
axes.update({n: {2: 'past_sequence_length'} for n in inputs[2:]})
|
| 163 |
+
axes.update({n: {2: 'total_sequence_length'} for n in outputs[1:]})
|
| 164 |
+
raw = ROOT / 'raw'
|
| 165 |
+
raw.mkdir(exist_ok=False)
|
| 166 |
+
event('torch_onnx_export_started')
|
| 167 |
+
with torch.no_grad():
|
| 168 |
+
torch.onnx.export(wrapper, (ids, pos, *past), str(raw / 'model.onnx'), input_names=inputs,
|
| 169 |
+
output_names=outputs, dynamic_axes=axes, opset_version=17, dynamo=False,
|
| 170 |
+
do_constant_folding=True, external_data=True)
|
| 171 |
+
event('torch_onnx_export_finished')
|
| 172 |
+
bundle = ROOT / 'bundle'
|
| 173 |
+
graph_dir = bundle / 'onnx'
|
| 174 |
+
graph_dir.mkdir(parents=True)
|
| 175 |
+
graph = onnx.load(raw / 'model.onnx')
|
| 176 |
+
onnx.save_model(graph, graph_dir / 'model_fp16.onnx', save_as_external_data=True,
|
| 177 |
+
all_tensors_to_one_file=True, location='model_fp16.onnx_data', size_threshold=1024)
|
| 178 |
+
onnx.checker.check_model(str(graph_dir / 'model_fp16.onnx'))
|
| 179 |
+
for name in ['config.json', 'tokenizer.json', 'tokenizer_config.json', 'generation_config.json',
|
| 180 |
+
'special_tokens_map.json', 'chat_template.jinja', 'LICENSE']:
|
| 181 |
+
if (MODEL / name).exists():
|
| 182 |
+
shutil.copy2(MODEL / name, bundle / name)
|
| 183 |
+
write_json(ROOT / 'graph-abi.json', {'inputs': inputs, 'outputs': outputs, 'numLayers': c.num_hidden_layers,
|
| 184 |
+
'numKvHeads': c.num_key_value_heads, 'headDim': c.head_dim, 'vocabSize': c.vocab_size,
|
| 185 |
+
'dtype': 'float16', 'weights': 'FP16', 'residualNormRopeSoftmax': 'FP32', 'contextTested': None})
|
| 186 |
+
event('export_complete', graphBytes=(graph_dir / 'model_fp16.onnx').stat().st_size,
|
| 187 |
+
weightsBytes=(graph_dir / 'model_fp16.onnx_data').stat().st_size)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def validate():
|
| 191 |
+
import numpy as np
|
| 192 |
+
import onnxruntime as ort
|
| 193 |
+
make_contract()
|
| 194 |
+
options = ort.SessionOptions()
|
| 195 |
+
options.intra_op_num_threads = 8
|
| 196 |
+
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
|
| 197 |
+
session = ort.InferenceSession(str(ROOT / 'bundle/onnx/model_fp16.onnx'), options, providers=['CPUExecutionProvider'])
|
| 198 |
+
abi = json.loads((ROOT / 'graph-abi.json').read_text())
|
| 199 |
+
checks = []
|
| 200 |
+
for case in json.loads((ROOT / 'fixtures.json').read_text()):
|
| 201 |
+
ids = case['inputIds']
|
| 202 |
+
past = [np.empty((1, abi['numKvHeads'], 0, abi['headDim']), dtype=np.float16) for _ in range(2 * abi['numLayers'])]
|
| 203 |
+
seen = 0
|
| 204 |
+
for step in range(4):
|
| 205 |
+
feeds = {'input_ids': np.array([ids], dtype=np.int64), 'position_ids': np.arange(seen, seen + len(ids), dtype=np.int64)[None]}
|
| 206 |
+
feeds.update(dict(zip(abi['inputs'][2:], past)))
|
| 207 |
+
result = session.run(None, feeds)
|
| 208 |
+
got = result[0][0, -1].astype(np.float64)
|
| 209 |
+
expected = np.load(ROOT / 'reference' / f'{case["name"]}-{step}.npy').astype(np.float64)
|
| 210 |
+
relative = float(np.linalg.norm(got - expected) / np.linalg.norm(expected))
|
| 211 |
+
cosine = float(np.dot(got, expected) / (np.linalg.norm(got) * np.linalg.norm(expected)))
|
| 212 |
+
finite = bool(np.isfinite(got).all() and all(np.isfinite(p).all() for p in result[1:]))
|
| 213 |
+
record = {'case': case['name'], 'step': step, 'relativeRms': relative, 'cosine': cosine,
|
| 214 |
+
'finite': finite, 'bf16Argmax': int(expected.argmax()), 'onnxArgmax': int(got.argmax())}
|
| 215 |
+
checks.append(record)
|
| 216 |
+
event('onnx_numerical_case', **record)
|
| 217 |
+
seen += len(ids)
|
| 218 |
+
ids = [case['teacherTokens'][step]]
|
| 219 |
+
past = result[1:]
|
| 220 |
+
passed = all(c['finite'] and c['relativeRms'] <= .02 and c['cosine'] >= .999 for c in checks)
|
| 221 |
+
write_json(ROOT / 'numerical-validation.json', {'passed': passed, 'checks': checks, 'precision': 'FP16 ONNX versus BF16',
|
| 222 |
+
'thresholds': {'relativeRmsMax': .02, 'cosineMin': .999}, 'runtime': ort.__version__})
|
| 223 |
+
if not passed:
|
| 224 |
+
raise RuntimeError('ONNX numerical validation failed; do not publish')
|
| 225 |
+
event('numerical_validation_passed')
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
if __name__ == '__main__':
|
| 229 |
+
parser = argparse.ArgumentParser()
|
| 230 |
+
parser.add_argument('stage', choices=['reference', 'export', 'validate'])
|
| 231 |
+
args = parser.parse_args()
|
| 232 |
+
{'reference': reference, 'export': export, 'validate': validate}[args.stage]()
|
provenance/scripts/promote_attention.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Versioned attention-GEMM precision correction; identical FP16 weight bytes."""
|
| 2 |
+
import hashlib
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import re
|
| 8 |
+
import shutil
|
| 9 |
+
import onnx
|
| 10 |
+
from onnx import helper, TensorProto
|
| 11 |
+
|
| 12 |
+
ROOT = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926')
|
| 13 |
+
source, target = ROOT / 'onnx-v3', ROOT / 'onnx-v4'
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def sha(path):
|
| 17 |
+
digest = hashlib.sha256()
|
| 18 |
+
with path.open('rb') as f:
|
| 19 |
+
for block in iter(lambda: f.read(8 * 1024 * 1024), b''):
|
| 20 |
+
digest.update(block)
|
| 21 |
+
return digest.hexdigest()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
global target
|
| 26 |
+
parser = argparse.ArgumentParser()
|
| 27 |
+
parser.add_argument('--all-matmuls', action='store_true')
|
| 28 |
+
args = parser.parse_args()
|
| 29 |
+
if args.all_matmuls:
|
| 30 |
+
target = ROOT / 'onnx-v5'
|
| 31 |
+
target.mkdir(exist_ok=False)
|
| 32 |
+
shutil.copytree(source / 'reference', target / 'reference')
|
| 33 |
+
shutil.copytree(source / 'runtime', target / 'runtime')
|
| 34 |
+
shutil.copy2(source / 'fixtures.json', target / 'fixtures.json')
|
| 35 |
+
for path in (source / 'bundle').iterdir():
|
| 36 |
+
if path.is_file():
|
| 37 |
+
(target / 'bundle').mkdir(exist_ok=True)
|
| 38 |
+
shutil.copy2(path, target / 'bundle' / path.name)
|
| 39 |
+
graph_dir = target / 'bundle/onnx'
|
| 40 |
+
graph_dir.mkdir()
|
| 41 |
+
weights = graph_dir / 'model_fp16.onnx_data'
|
| 42 |
+
os.link(source / 'bundle/onnx/model_fp16.onnx_data', weights)
|
| 43 |
+
model = onnx.load(source / 'bundle/onnx/model_fp16.onnx', load_external_data=False)
|
| 44 |
+
nodes, changed = [], []
|
| 45 |
+
for node in model.graph.node:
|
| 46 |
+
if node.op_type == 'MatMul' and (args.all_matmuls or re.fullmatch(r'/layers\.\d+/self_attn/MatMul(?:_1)?', node.name)):
|
| 47 |
+
original_output = node.output[0]
|
| 48 |
+
for index, value in enumerate(list(node.input)):
|
| 49 |
+
cast = value + '__attention_f32_' + node.name.replace('/', '_')
|
| 50 |
+
nodes.append(helper.make_node('Cast', [value], [cast], name=node.name + f'/input{index}_f32', to=TensorProto.FLOAT))
|
| 51 |
+
node.input[index] = cast
|
| 52 |
+
node.output[0] = original_output + '__attention_f32'
|
| 53 |
+
nodes.append(node)
|
| 54 |
+
nodes.append(helper.make_node('Cast', [node.output[0]], [original_output], name=node.name + '/output_f16', to=TensorProto.FLOAT16))
|
| 55 |
+
changed.append(node.name)
|
| 56 |
+
else:
|
| 57 |
+
nodes.append(node)
|
| 58 |
+
assert len(changed) == (225 if args.all_matmuls else 56)
|
| 59 |
+
model.graph.ClearField('node')
|
| 60 |
+
model.graph.node.extend(nodes)
|
| 61 |
+
onnx.save(model, graph_dir / 'model_fp16.onnx')
|
| 62 |
+
onnx.checker.check_model(str(graph_dir / 'model_fp16.onnx'))
|
| 63 |
+
abi = json.loads((source / 'graph-abi.json').read_text())
|
| 64 |
+
abi.update(matmulCompute='FP32' if args.all_matmuls else 'FP16 except attention FP32', attentionMatmul='FP32 compute, FP16 input/cache/output storage', contextTested=None)
|
| 65 |
+
(target / 'graph-abi.json').write_text(json.dumps(abi, indent=2), encoding='utf-8')
|
| 66 |
+
proof = {'source': str(source), 'candidate': str(target), 'precisionOnlyChange': True, 'changedNodes': changed,
|
| 67 |
+
'fp16WeightSha256': sha(weights), 'sourceWeightSha256': sha(source / 'bundle/onnx/model_fp16.onnx_data'),
|
| 68 |
+
'reason': 'ORT WebGPU FP16 MatMul accumulation drift on 4K/8K probes; promote GEMM compute to FP32 while retaining FP16 weight/cache storage',
|
| 69 |
+
'architectureOrSemanticMaskChanged': False, 'thresholdsChanged': False}
|
| 70 |
+
assert proof['fp16WeightSha256'] == proof['sourceWeightSha256']
|
| 71 |
+
(target / 'precision-correction.json').write_text(json.dumps(proof, indent=2), encoding='utf-8')
|
| 72 |
+
print(json.dumps({'candidate': str(target), 'changedNodes': len(changed), 'weightBytesIdentical': True}), flush=True)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
if __name__ == '__main__':
|
| 76 |
+
main()
|
provenance/scripts/validate_browser.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Same frozen logit thresholds in real Chrome/WebGPU; exact tokenizer check."""
|
| 2 |
+
import hashlib
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import time
|
| 7 |
+
import urllib.request
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
ROOT = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926\onnx-v3')
|
| 11 |
+
URL = 'http://127.0.0.1:8561'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def post(route, payload):
|
| 15 |
+
request = urllib.request.Request(URL + route, data=json.dumps(payload).encode(), headers={'Content-Type': 'application/json'})
|
| 16 |
+
with urllib.request.urlopen(request, timeout=600) as response:
|
| 17 |
+
return json.load(response)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
global ROOT
|
| 22 |
+
parser = argparse.ArgumentParser()
|
| 23 |
+
parser.add_argument('--root', type=Path, default=ROOT)
|
| 24 |
+
parser.add_argument('--run-tag', default='browser-v5')
|
| 25 |
+
args = parser.parse_args()
|
| 26 |
+
ROOT = args.root
|
| 27 |
+
assert json.loads((ROOT / 'numerical-validation.json').read_text())['passed']
|
| 28 |
+
ready = json.loads((ROOT / args.run_tag / 'ready.json').read_text())
|
| 29 |
+
assert ready['ready'] and ready['gpuInfo']['architecture'] == 'blackwell'
|
| 30 |
+
checks, templates, smoke = [], [], []
|
| 31 |
+
cases = json.loads((ROOT / 'fixtures.json').read_text())
|
| 32 |
+
# The reference recorder used insertion-ordered tools, but write_json sorted
|
| 33 |
+
# all dictionary keys on disk. Restore the declared original fixture order;
|
| 34 |
+
# never modify saved token IDs or model outputs to obtain a match.
|
| 35 |
+
for case in cases:
|
| 36 |
+
if case['name'] == 'native_tool':
|
| 37 |
+
original = {'type': 'function', 'function': {'name': 'open_url', 'description': 'Open a URL in the browser.',
|
| 38 |
+
'parameters': {'type': 'object', 'properties': {'url': {'type': 'string'}}, 'required': ['url']}}}
|
| 39 |
+
assert original == case['tools'][0]
|
| 40 |
+
case['tools'] = [original]
|
| 41 |
+
for case in cases:
|
| 42 |
+
if case['name'] != 'sliding_boundary_513':
|
| 43 |
+
template = post('/template', {'messages': case['messages'], 'tools': case['tools']})
|
| 44 |
+
same = template['ids'] == case['inputIds']
|
| 45 |
+
templates.append({'case': case['name'], 'tokenIdsIdentical': same})
|
| 46 |
+
if not same:
|
| 47 |
+
raise RuntimeError('JS/Python native-tokenizer mismatch')
|
| 48 |
+
result = post('/infer', case)
|
| 49 |
+
for step, values in enumerate(result['logits']):
|
| 50 |
+
got = np.array(values, dtype=np.float64)
|
| 51 |
+
expected = np.load(ROOT / 'reference' / f'{case["name"]}-{step}.npy').astype(np.float64)
|
| 52 |
+
relative = float(np.linalg.norm(got - expected) / np.linalg.norm(expected))
|
| 53 |
+
cosine = float(np.dot(got, expected) / (np.linalg.norm(got) * np.linalg.norm(expected)))
|
| 54 |
+
check = {'case': case['name'], 'step': step, 'relativeRms': relative, 'cosine': cosine,
|
| 55 |
+
'finite': bool(np.isfinite(got).all()), 'bf16Argmax': int(expected.argmax()), 'webgpuArgmax': int(got.argmax())}
|
| 56 |
+
checks.append(check)
|
| 57 |
+
print(json.dumps(check), flush=True)
|
| 58 |
+
for case in cases[:2]:
|
| 59 |
+
start = time.monotonic()
|
| 60 |
+
output = post('/v1/chat/completions', {'model': 'webbrain-compass-tiny-v3-onnx-fp16', 'messages': case['messages'],
|
| 61 |
+
'tools': case['tools'], 'max_tokens': 96, 'temperature': 0, 'stream': False})
|
| 62 |
+
smoke.append({'case': case['name'], 'seconds': time.monotonic() - start, 'result': output})
|
| 63 |
+
print(json.dumps({'generationSmoke': smoke[-1]}), flush=True)
|
| 64 |
+
passed = all(c['finite'] and c['relativeRms'] <= .02 and c['cosine'] >= .999 for c in checks)
|
| 65 |
+
report = {'passed': passed, 'checks': checks, 'templates': templates, 'generationSmoke': smoke,
|
| 66 |
+
'thresholds': {'relativeRmsMax': .02, 'cosineMin': .999}, 'browser': ready['browser'],
|
| 67 |
+
'runtime': ready['runtime'], 'gpu': ready['gpuInfo'], 'precision': ready['precision'],
|
| 68 |
+
'cloudFallback': False, 'interpretation': 'Runtime/numerical smoke only; not an agent benchmark'}
|
| 69 |
+
with (ROOT / 'browser-validation.json').open('x', encoding='utf-8') as f:
|
| 70 |
+
json.dump(report, f, indent=2)
|
| 71 |
+
if not passed:
|
| 72 |
+
raise RuntimeError('Real WebGPU numerical validation failed; do not publish')
|
| 73 |
+
print(json.dumps({'passed': True, 'cases': len(checks), 'maximumRelativeRms': max(c['relativeRms'] for c in checks)}), flush=True)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == '__main__':
|
| 77 |
+
main()
|
provenance/scripts/validate_context.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Additional fixed 8192-token cache-boundary test; independent BF16 reference."""
|
| 2 |
+
import json
|
| 3 |
+
import argparse
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
import urllib.request
|
| 9 |
+
import numpy as np
|
| 10 |
+
import torch
|
| 11 |
+
|
| 12 |
+
ROOT = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926\onnx-v3')
|
| 13 |
+
sys.path.insert(0, str(Path(__file__).parents[1] / 'spark_x25_17b_webbrain_compass_v3'))
|
| 14 |
+
import runtime
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
parser = argparse.ArgumentParser()
|
| 19 |
+
parser.add_argument('--length', type=int, default=8192)
|
| 20 |
+
args = parser.parse_args()
|
| 21 |
+
assert args.length in (4096, 8192)
|
| 22 |
+
uuid = 'GPU-6d908ed7-d2e6-1c70-8a1e-28754a8cbfae'
|
| 23 |
+
assert os.environ.get('CUDA_VISIBLE_DEVICES') == uuid
|
| 24 |
+
free = int(subprocess.check_output(['nvidia-smi', '-i', uuid, '--query-gpu=memory.free', '--format=csv,noheader,nounits'], text=True).strip())
|
| 25 |
+
assert free > 20000, 'Not enough GPU0 headroom; leave other processes untouched'
|
| 26 |
+
folder = ROOT / f'context-{args.length}-v1'
|
| 27 |
+
folder.mkdir(exist_ok=False)
|
| 28 |
+
from transformers import AutoTokenizer
|
| 29 |
+
from transformers.cache_utils import DynamicCache
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(ROOT.parent / 'release-compat-v3', local_files_only=True)
|
| 31 |
+
# Artificial numerical probe, not a selected/modified training or benchmark row.
|
| 32 |
+
ids = tokenizer('Browser reference facts: ' + 'website tab navigation page content. ' * 3000, add_special_tokens=False)['input_ids'][:args.length-3]
|
| 33 |
+
assert len(ids) == args.length-3
|
| 34 |
+
fixture = {'name': f'context_{args.length}', 'inputIds': ids, 'teacherTokens': []}
|
| 35 |
+
(folder / 'selection.json').write_text(json.dumps({'inputIds': ids, 'rule': f'Fixed synthetic {args.length-3}-token prefill plus three decode tokens, chosen before results; 4K is a separately tested deployment cap, not removal of the failed 8K check'}), encoding='utf-8')
|
| 36 |
+
torch.set_num_threads(8)
|
| 37 |
+
torch.backends.cuda.matmul.allow_tf32 = False
|
| 38 |
+
model = runtime.load_native(str(ROOT.parent / 'release-compat-v3'), dtype=torch.bfloat16, device_map={'': 0}).eval()
|
| 39 |
+
cache = DynamicCache(config=None)
|
| 40 |
+
tensors = torch.tensor([ids], device='cuda')
|
| 41 |
+
for step in range(4):
|
| 42 |
+
with torch.no_grad():
|
| 43 |
+
result = model(input_ids=tensors, past_key_values=cache, use_cache=True, logits_to_keep=1)
|
| 44 |
+
logits = result.logits[0, -1].float().cpu().numpy()
|
| 45 |
+
np.save(folder / f'bf16-{step}.npy', logits)
|
| 46 |
+
token = int(logits.argmax())
|
| 47 |
+
fixture['teacherTokens'].append(token)
|
| 48 |
+
tensors = torch.tensor([[token]], device='cuda')
|
| 49 |
+
print(json.dumps({'referenceStep': step, 'finite': bool(np.isfinite(logits).all())}), flush=True)
|
| 50 |
+
del model, cache, result
|
| 51 |
+
torch.cuda.empty_cache()
|
| 52 |
+
request = urllib.request.Request('http://127.0.0.1:8561/infer', data=json.dumps(fixture).encode(), headers={'Content-Type': 'application/json'})
|
| 53 |
+
with urllib.request.urlopen(request, timeout=600) as response:
|
| 54 |
+
actual = json.load(response)
|
| 55 |
+
checks = []
|
| 56 |
+
for step, values in enumerate(actual['logits']):
|
| 57 |
+
expected = np.load(folder / f'bf16-{step}.npy').astype(np.float64)
|
| 58 |
+
got = np.array(values, dtype=np.float64)
|
| 59 |
+
checks.append({'step': step, 'relativeRms': float(np.linalg.norm(got-expected)/np.linalg.norm(expected)),
|
| 60 |
+
'cosine': float(np.dot(got, expected)/(np.linalg.norm(got)*np.linalg.norm(expected))),
|
| 61 |
+
'finite': bool(np.isfinite(got).all()), 'argmaxMatched': bool(got.argmax()==expected.argmax())})
|
| 62 |
+
passed = all(c['finite'] and c['relativeRms'] <= .02 and c['cosine'] >= .999 for c in checks)
|
| 63 |
+
report = {'passed': passed, 'prefillTokens': args.length-3, 'finalCacheTokens': args.length, 'checks': checks,
|
| 64 |
+
'thresholds': {'relativeRmsMax': .02, 'cosineMin': .999}, 'gpu': actual['gpuInfo']}
|
| 65 |
+
(folder / 'validation.json').write_text(json.dumps(report, indent=2), encoding='utf-8')
|
| 66 |
+
print(json.dumps(report), flush=True)
|
| 67 |
+
assert passed, 'Long-context WebGPU numerical validation failed'
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
if __name__ == '__main__':
|
| 71 |
+
main()
|
provenance/scripts/validate_saved_context.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Retest a new graph against immutable long-context BF16 reference bytes."""
|
| 2 |
+
import json
|
| 3 |
+
import argparse
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import urllib.request
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
RUN = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926')
|
| 9 |
+
SOURCE = RUN / 'onnx-v3'
|
| 10 |
+
TARGET = RUN / 'onnx-v4'
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def main():
|
| 14 |
+
global TARGET
|
| 15 |
+
parser = argparse.ArgumentParser()
|
| 16 |
+
parser.add_argument('--root', type=Path, default=TARGET)
|
| 17 |
+
args = parser.parse_args()
|
| 18 |
+
TARGET = args.root
|
| 19 |
+
reports = []
|
| 20 |
+
for length in (4096, 8192):
|
| 21 |
+
source = SOURCE / f'context-{length}-v1'
|
| 22 |
+
ids = json.loads((source / 'selection.json').read_text())['inputIds']
|
| 23 |
+
reference = [np.load(source / f'bf16-{step}.npy').astype(np.float64) for step in range(4)]
|
| 24 |
+
fixture = {'inputIds': ids, 'teacherTokens': [int(v.argmax()) for v in reference]}
|
| 25 |
+
request = urllib.request.Request('http://127.0.0.1:8561/infer', data=json.dumps(fixture).encode(), headers={'Content-Type': 'application/json'})
|
| 26 |
+
with urllib.request.urlopen(request, timeout=600) as response:
|
| 27 |
+
actual = json.load(response)
|
| 28 |
+
checks = []
|
| 29 |
+
for step, values in enumerate(actual['logits']):
|
| 30 |
+
got, expected = np.array(values, dtype=np.float64), reference[step]
|
| 31 |
+
checks.append({'step': step, 'relativeRms': float(np.linalg.norm(got-expected)/np.linalg.norm(expected)),
|
| 32 |
+
'cosine': float(np.dot(got, expected)/(np.linalg.norm(got)*np.linalg.norm(expected))),
|
| 33 |
+
'finite': bool(np.isfinite(got).all()), 'argmaxMatched': bool(got.argmax()==expected.argmax())})
|
| 34 |
+
passed = all(c['finite'] and c['relativeRms'] <= .02 and c['cosine'] >= .999 for c in checks)
|
| 35 |
+
report = {'passed': passed, 'prefillTokens': length-3, 'finalCacheTokens': length, 'checks': checks,
|
| 36 |
+
'bf16Reference': str(source), 'thresholds': {'relativeRmsMax': .02, 'cosineMin': .999}, 'gpu': actual['gpuInfo']}
|
| 37 |
+
reports.append(report)
|
| 38 |
+
print(json.dumps(report), flush=True)
|
| 39 |
+
target = TARGET / 'context-validation.json'
|
| 40 |
+
with target.open('x', encoding='utf-8') as f:
|
| 41 |
+
json.dump({'passed': all(r['passed'] for r in reports), 'contexts': reports}, f, indent=2)
|
| 42 |
+
assert all(r['passed'] for r in reports), 'Long-context precision validation still fails'
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
if __name__ == '__main__':
|
| 46 |
+
main()
|
runtime/browser_runtime.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as ort from '/runtime/vendor/ort.webgpu.mjs';
|
| 2 |
+
import {AutoTokenizer, env} from '/runtime/vendor/transformers.web.js';
|
| 3 |
+
|
| 4 |
+
let session, tokenizer, abi, gpuInfo, eos;
|
| 5 |
+
function emptyCache() {
|
| 6 |
+
return abi.inputs.slice(2).map(() => new ort.Tensor('float16', new Uint16Array(0), [1, abi.numKvHeads, 0, abi.headDim]));
|
| 7 |
+
}
|
| 8 |
+
function dispose(tensors) { for (const t of tensors) if (t.location === 'gpu-buffer') t.dispose(); }
|
| 9 |
+
function argmax(values) { let best = 0; for (let i=1;i<values.length;i++) if(values[i]>values[best]) best=i; return best; }
|
| 10 |
+
|
| 11 |
+
window.initializeSpark = async () => {
|
| 12 |
+
console.log('spark-stage: adapter');
|
| 13 |
+
const adapter = await navigator.gpu.requestAdapter({powerPreference: 'high-performance'});
|
| 14 |
+
if (!adapter || !adapter.features.has('shader-f16')) throw Error('Hardware WebGPU/shader-f16 required');
|
| 15 |
+
const info = adapter.info;
|
| 16 |
+
if (info.vendor !== 'nvidia' || info.architecture !== 'blackwell') throw Error('Wrong WebGPU adapter');
|
| 17 |
+
gpuInfo = {vendor: info.vendor, architecture: info.architecture, description: info.description};
|
| 18 |
+
ort.env.webgpu.adapter = adapter;
|
| 19 |
+
ort.env.wasm.numThreads = 1;
|
| 20 |
+
ort.env.wasm.wasmPaths = '/runtime/vendor/';
|
| 21 |
+
env.allowRemoteModels = false;
|
| 22 |
+
env.allowLocalModels = true;
|
| 23 |
+
env.localModelPath = '/';
|
| 24 |
+
console.log('spark-stage: tokenizer');
|
| 25 |
+
tokenizer = await AutoTokenizer.from_pretrained('model', {local_files_only: true});
|
| 26 |
+
// Transformers.js 4.2 does not load the separate Jinja file automatically.
|
| 27 |
+
const templateResponse = await fetch('/model/chat_template.jinja');
|
| 28 |
+
if (!templateResponse.ok) throw Error('Missing native Spark chat template');
|
| 29 |
+
tokenizer.chat_template = (await templateResponse.text()).replace(/\r\n/g, '\n');
|
| 30 |
+
abi = await (await fetch('/abi')).json();
|
| 31 |
+
const config = await (await fetch('/model/generation_config.json')).json();
|
| 32 |
+
eos = new Set(Array.isArray(config.eos_token_id) ? config.eos_token_id : [config.eos_token_id]);
|
| 33 |
+
// Let ORT's streaming large-file loader bypass Chrome's 2GB arrayBuffer cap.
|
| 34 |
+
console.log('spark-stage: creating session');
|
| 35 |
+
session = await ort.InferenceSession.create('/model/onnx/model_fp16.onnx', {
|
| 36 |
+
executionProviders: ['webgpu'], graphOptimizationLevel: 'disabled',
|
| 37 |
+
preferredOutputLocation: 'gpu-buffer',
|
| 38 |
+
externalData: [{path: 'model_fp16.onnx_data', data: '/model/onnx/model_fp16.onnx_data'}],
|
| 39 |
+
});
|
| 40 |
+
return {gpuInfo, runtime: ort.env.versions, abi};
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
async function step(ids, past, seen) {
|
| 44 |
+
const feeds = {
|
| 45 |
+
input_ids: new ort.Tensor('int64', BigInt64Array.from(ids, BigInt), [1, ids.length]),
|
| 46 |
+
position_ids: new ort.Tensor('int64', BigInt64Array.from(ids.map((_,i)=>seen+i), BigInt), [1,ids.length]),
|
| 47 |
+
};
|
| 48 |
+
abi.inputs.slice(2).forEach((key,i)=>feeds[key]=past[i]);
|
| 49 |
+
const result = await session.run(feeds);
|
| 50 |
+
const logits = await result.logits.getData();
|
| 51 |
+
if (![...logits].every(Number.isFinite)) throw Error('Nonfinite WebGPU logits');
|
| 52 |
+
const present = abi.outputs.slice(1).map(key=>result[key]);
|
| 53 |
+
if (!present.every(t=>t.dims[2]===seen+ids.length)) throw Error('Cache-length mismatch');
|
| 54 |
+
result.logits.dispose();
|
| 55 |
+
dispose(past);
|
| 56 |
+
return {logits, present};
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
window.sparkNumerics = async (fixture) => {
|
| 60 |
+
let ids=fixture.inputIds, past=emptyCache(), seen=0;
|
| 61 |
+
const logits=[];
|
| 62 |
+
for(let n=0;n<4;n++) {
|
| 63 |
+
const result=await step(ids,past,seen);
|
| 64 |
+
logits.push(Array.from(result.logits));
|
| 65 |
+
seen+=ids.length; ids=[fixture.teacherTokens[n]]; past=result.present;
|
| 66 |
+
}
|
| 67 |
+
dispose(past);
|
| 68 |
+
return {logits,finite:true,gpuInfo};
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
window.sparkTemplate = ({messages,tools}) => {
|
| 72 |
+
const rendered=tokenizer.apply_chat_template(messages,{tools:tools||undefined,tokenize:false,
|
| 73 |
+
enable_thinking:false,add_generation_prompt:true});
|
| 74 |
+
return {text:rendered,ids:Array.from(tokenizer(rendered,{add_special_tokens:false}).input_ids.data,Number)};
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
window.sparkGenerate = async ({messages,tools,maxTokens=512}) => {
|
| 78 |
+
const prompt=window.sparkTemplate({messages,tools});
|
| 79 |
+
if(prompt.ids.length+maxTokens>4096) throw Error('This deployed WebGPU endpoint supports at most 4096 input+output tokens');
|
| 80 |
+
let ids=prompt.ids,past=emptyCache(),seen=0,output=[],reason='length';
|
| 81 |
+
const started=performance.now();
|
| 82 |
+
try {
|
| 83 |
+
for(let n=0;n<maxTokens;n++) {
|
| 84 |
+
const result=await step(ids,past,seen);
|
| 85 |
+
past=result.present;seen+=ids.length;
|
| 86 |
+
const token=argmax(result.logits);
|
| 87 |
+
output.push(token);
|
| 88 |
+
if(eos.has(token)){reason='stop';break;}
|
| 89 |
+
ids=[token];
|
| 90 |
+
}
|
| 91 |
+
return {content:tokenizer.decode(output,{skip_special_tokens:true}),promptTokens:prompt.ids.length,
|
| 92 |
+
completionTokens:output.length,finishReason:reason,seconds:(performance.now()-started)/1000};
|
| 93 |
+
} finally {dispose(past);}
|
| 94 |
+
};
|
runtime/browser_service.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Isolated Chrome WebGPU service and OpenAI bridge; no cloud/model fallback."""
|
| 2 |
+
import asyncio
|
| 3 |
+
import argparse
|
| 4 |
+
import importlib.util
|
| 5 |
+
import json
|
| 6 |
+
import mimetypes
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
import shutil
|
| 9 |
+
import threading
|
| 10 |
+
import time
|
| 11 |
+
import uuid
|
| 12 |
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
| 13 |
+
|
| 14 |
+
from openai_server import normalize_messages, parse_tools
|
| 15 |
+
from playwright.async_api import async_playwright
|
| 16 |
+
|
| 17 |
+
ROOT = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926\onnx-v3')
|
| 18 |
+
SOURCE = Path(__file__).parent
|
| 19 |
+
MODEL_ID = 'webbrain-compass-tiny-v3-onnx-fp16'
|
| 20 |
+
PORT = 8561
|
| 21 |
+
VENDOR = Path(r'F:\webbrain-data\compass-tiny-v2-webgpu-recovery-v24\runtime\vendor')
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
async def main():
|
| 25 |
+
global ROOT, PORT
|
| 26 |
+
parser = argparse.ArgumentParser()
|
| 27 |
+
parser.add_argument('--run-tag', default='browser-v5')
|
| 28 |
+
parser.add_argument('--artifact-root', type=Path, default=ROOT)
|
| 29 |
+
parser.add_argument('--package-mode', action='store_true', help='Root is the published package, not the export work directory')
|
| 30 |
+
parser.add_argument('--port', type=int, default=PORT)
|
| 31 |
+
args = parser.parse_args()
|
| 32 |
+
ROOT, PORT = args.artifact_root.resolve(), args.port
|
| 33 |
+
model_dir = ROOT if args.package_mode else ROOT / 'bundle'
|
| 34 |
+
run = ROOT / args.run_tag
|
| 35 |
+
run.mkdir(exist_ok=False)
|
| 36 |
+
runtime = ROOT / 'runtime'
|
| 37 |
+
runtime.mkdir(exist_ok=True)
|
| 38 |
+
if not (runtime / 'vendor').exists():
|
| 39 |
+
if not VENDOR.is_dir():
|
| 40 |
+
raise RuntimeError('Missing pinned runtime/vendor files; download the complete package')
|
| 41 |
+
shutil.copytree(VENDOR, runtime / 'vendor')
|
| 42 |
+
dxgi_source = SOURCE / 'compass_dxgi_5090.py'
|
| 43 |
+
if not dxgi_source.is_file():
|
| 44 |
+
dxgi_source = Path(r'F:\webbrain-data\webbrain-data\scripts\hf\compass_dxgi_5090.py')
|
| 45 |
+
module_spec = importlib.util.spec_from_file_location('dxgi', dxgi_source)
|
| 46 |
+
dxgi = importlib.util.module_from_spec(module_spec)
|
| 47 |
+
module_spec.loader.exec_module(dxgi)
|
| 48 |
+
adapter = dxgi.discover()
|
| 49 |
+
loop = asyncio.get_running_loop()
|
| 50 |
+
lock = asyncio.Lock()
|
| 51 |
+
state = {'ready': False, 'model': MODEL_ID, 'precision': 'FP16 ONNX; FP32 residual/norm/RoPE/softmax',
|
| 52 |
+
'runtime': 'ONNX Runtime WebGPU', 'gpu': 'RTX 5090', 'cloudFallback': False,
|
| 53 |
+
'maxContextTokens': 4096, 'temperature': 'greedy-only benchmark endpoint'}
|
| 54 |
+
page = None
|
| 55 |
+
|
| 56 |
+
async def rpc(method, payload):
|
| 57 |
+
async with lock:
|
| 58 |
+
return await page.evaluate('async ({method,payload})=>window[method](payload)', {'method': method, 'payload': payload})
|
| 59 |
+
|
| 60 |
+
class Handler(BaseHTTPRequestHandler):
|
| 61 |
+
def log_message(self, fmt, *args):
|
| 62 |
+
if self.path.startswith(('/v1/', '/infer', '/template', '/health')):
|
| 63 |
+
print(json.dumps({'http': fmt % args, 'time': time.time()}), flush=True)
|
| 64 |
+
|
| 65 |
+
def json(self, status, value):
|
| 66 |
+
data = json.dumps(value, ensure_ascii=False).encode()
|
| 67 |
+
self.send_response(status)
|
| 68 |
+
self.send_header('Content-Type', 'application/json')
|
| 69 |
+
self.send_header('Content-Length', str(len(data)))
|
| 70 |
+
self.end_headers()
|
| 71 |
+
self.wfile.write(data)
|
| 72 |
+
|
| 73 |
+
def do_GET(self):
|
| 74 |
+
if self.path == '/health':
|
| 75 |
+
return self.json(200, state)
|
| 76 |
+
if self.path == '/v1/models':
|
| 77 |
+
return self.json(200, {'object': 'list', 'data': [{'id': MODEL_ID, 'object': 'model', 'owned_by': 'webbrain-one', **state}]})
|
| 78 |
+
if self.path == '/abi':
|
| 79 |
+
return self.json(200, json.loads((ROOT / 'graph-abi.json').read_text()))
|
| 80 |
+
if self.path == '/':
|
| 81 |
+
data = b'<html><script type="module" src="/browser_runtime.js"></script></html>'
|
| 82 |
+
self.send_response(200)
|
| 83 |
+
self.send_header('Content-Type', 'text/html')
|
| 84 |
+
self.send_header('Content-Length', str(len(data)))
|
| 85 |
+
self.end_headers()
|
| 86 |
+
return self.wfile.write(data)
|
| 87 |
+
if self.path == '/browser_runtime.js':
|
| 88 |
+
target = SOURCE / 'browser_runtime.js'
|
| 89 |
+
elif self.path.startswith('/model/'):
|
| 90 |
+
target = model_dir / self.path[len('/model/'):]
|
| 91 |
+
elif self.path.startswith('/runtime/'):
|
| 92 |
+
target = ROOT / self.path.lstrip('/')
|
| 93 |
+
else:
|
| 94 |
+
return self.json(404, {'error': 'Not found'})
|
| 95 |
+
target = target.resolve()
|
| 96 |
+
allowed = [ROOT.resolve(), SOURCE.resolve()]
|
| 97 |
+
if not any(target.is_relative_to(p) for p in allowed) or not target.is_file():
|
| 98 |
+
return self.json(404, {'error': 'Not found'})
|
| 99 |
+
self.send_response(200)
|
| 100 |
+
suffix = target.suffix
|
| 101 |
+
self.send_header('Content-Type', {'mjs': 'text/javascript', 'js': 'text/javascript', 'wasm': 'application/wasm'}.get(suffix[1:], mimetypes.guess_type(str(target))[0] or 'application/octet-stream'))
|
| 102 |
+
self.send_header('Content-Length', str(target.stat().st_size))
|
| 103 |
+
self.end_headers()
|
| 104 |
+
with target.open('rb') as f:
|
| 105 |
+
shutil.copyfileobj(f, self.wfile, length=4 * 1024 * 1024)
|
| 106 |
+
|
| 107 |
+
def do_POST(self):
|
| 108 |
+
try:
|
| 109 |
+
length = int(self.headers.get('Content-Length', '0'))
|
| 110 |
+
if not 0 < length <= 4 * 1024 * 1024:
|
| 111 |
+
raise ValueError('Invalid body size')
|
| 112 |
+
body = json.loads(self.rfile.read(length))
|
| 113 |
+
if not state['ready']:
|
| 114 |
+
return self.json(503, {'error': 'WebGPU model not ready'})
|
| 115 |
+
if self.path == '/infer':
|
| 116 |
+
method, payload = 'sparkNumerics', body
|
| 117 |
+
elif self.path == '/template':
|
| 118 |
+
method, payload = 'sparkTemplate', body
|
| 119 |
+
elif self.path == '/v1/chat/completions':
|
| 120 |
+
if body.get('model') != MODEL_ID or body.get('stream', False) or float(body.get('temperature', 0)) != 0:
|
| 121 |
+
raise ValueError('Use exact ONNX model id, stream=false, temperature=0')
|
| 122 |
+
maximum = int(body.get('max_completion_tokens', body.get('max_tokens', 512)))
|
| 123 |
+
if not 1 <= maximum <= 2048:
|
| 124 |
+
raise ValueError('max_tokens must be 1..2048')
|
| 125 |
+
method, payload = 'sparkGenerate', {'messages': normalize_messages(body['messages']),
|
| 126 |
+
'tools': body.get('tools'), 'maxTokens': maximum}
|
| 127 |
+
else:
|
| 128 |
+
return self.json(404, {'error': 'Not found'})
|
| 129 |
+
result = asyncio.run_coroutine_threadsafe(rpc(method, payload), loop).result(timeout=600)
|
| 130 |
+
if self.path == '/v1/chat/completions':
|
| 131 |
+
raw = result['content']
|
| 132 |
+
parser_error = None
|
| 133 |
+
try:
|
| 134 |
+
calls, content = parse_tools(raw, body.get('tools'))
|
| 135 |
+
except Exception as exc:
|
| 136 |
+
calls, content, parser_error = [], raw, str(exc)
|
| 137 |
+
message = {'role': 'assistant', 'content': content or None}
|
| 138 |
+
finish = result['finishReason']
|
| 139 |
+
if calls:
|
| 140 |
+
message['tool_calls'] = calls
|
| 141 |
+
finish = 'tool_calls'
|
| 142 |
+
result = {'id': 'chatcmpl-' + uuid.uuid4().hex, 'object': 'chat.completion', 'created': int(time.time()),
|
| 143 |
+
'model': MODEL_ID, 'choices': [{'index': 0, 'message': message, 'finish_reason': finish}],
|
| 144 |
+
'usage': {'prompt_tokens': result['promptTokens'], 'completion_tokens': result['completionTokens'],
|
| 145 |
+
'total_tokens': result['promptTokens'] + result['completionTokens']}, 'x_runtime': state}
|
| 146 |
+
if parser_error:
|
| 147 |
+
result['x_parser_error'] = parser_error
|
| 148 |
+
self.json(200, result)
|
| 149 |
+
except (ValueError, KeyError, TypeError) as exc:
|
| 150 |
+
self.json(400, {'error': {'message': str(exc), 'type': 'invalid_request_error'}})
|
| 151 |
+
except Exception as exc:
|
| 152 |
+
self.json(500, {'error': {'message': str(exc), 'type': 'runtime_error'}})
|
| 153 |
+
|
| 154 |
+
server = ThreadingHTTPServer(('127.0.0.1', PORT), Handler)
|
| 155 |
+
threading.Thread(target=server.serve_forever, daemon=True).start()
|
| 156 |
+
async with async_playwright() as p:
|
| 157 |
+
browser = await p.chromium.launch(executable_path=r'C:\Program Files\Google\Chrome\Application\chrome.exe', headless=True,
|
| 158 |
+
args=['--enable-unsafe-webgpu', '--ignore-gpu-blocklist', '--use-angle=d3d11',
|
| 159 |
+
f'--use-adapter-luid={adapter["high"]},{adapter["low"]}', '--force_high_performance_gpu',
|
| 160 |
+
'--enable-features=EGLDualGPURendering', '--enable-dawn-features=allow_unsafe_apis',
|
| 161 |
+
'--js-flags=--max-old-space-size=16384'])
|
| 162 |
+
try:
|
| 163 |
+
cdp = await browser.new_browser_cdp_session()
|
| 164 |
+
info = await cdp.send('SystemInfo.getInfo')
|
| 165 |
+
renderer = info['gpu']['auxAttributes']['glRenderer']
|
| 166 |
+
if 'RTX 5090' not in renderer:
|
| 167 |
+
raise RuntimeError('Chrome selected the wrong GPU')
|
| 168 |
+
(run / 'gpu-identity.json').write_text(json.dumps({'dxgi': adapter, 'renderer': renderer}), encoding='utf-8')
|
| 169 |
+
page = await browser.new_page()
|
| 170 |
+
page.on('requestfailed', lambda request: print(json.dumps({'requestFailed': request.url.split('?')[0], 'reason': request.failure}), flush=True))
|
| 171 |
+
page.on('console', lambda message: print(json.dumps({'console': message.type, 'text': message.text[:1500]}), flush=True))
|
| 172 |
+
page.on('pageerror', lambda error: print(json.dumps({'pageError': str(error)}), flush=True))
|
| 173 |
+
await page.goto(f'http://127.0.0.1:{PORT}/')
|
| 174 |
+
await page.wait_for_function('typeof window.initializeSpark === "function"')
|
| 175 |
+
ready = await page.evaluate('window.initializeSpark()')
|
| 176 |
+
state.update(ready=True, browser=browser.version, **ready)
|
| 177 |
+
(run / 'ready.json').write_text(json.dumps(state), encoding='utf-8')
|
| 178 |
+
print(json.dumps({'ready': True, 'baseUrl': f'http://127.0.0.1:{PORT}/v1', **state}), flush=True)
|
| 179 |
+
await asyncio.Event().wait()
|
| 180 |
+
finally:
|
| 181 |
+
server.shutdown()
|
| 182 |
+
await browser.close()
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
if __name__ == '__main__':
|
| 186 |
+
asyncio.run(main())
|
runtime/compass_dxgi_5090.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read-only DXGI adapter discovery for exact Chromium GPU selection."""
|
| 2 |
+
import ctypes as c
|
| 3 |
+
import json
|
| 4 |
+
import uuid
|
| 5 |
+
class GUID(c.Structure):_fields_=[('bytes',c.c_ubyte*16)]
|
| 6 |
+
class LUID(c.Structure):_fields_=[('LowPart',c.c_uint32),('HighPart',c.c_int32)]
|
| 7 |
+
class DESC(c.Structure):
|
| 8 |
+
_fields_=[('Description',c.c_wchar*128),('VendorId',c.c_uint),('DeviceId',c.c_uint),('SubSysId',c.c_uint),('Revision',c.c_uint),('DedicatedVideoMemory',c.c_size_t),('DedicatedSystemMemory',c.c_size_t),('SharedSystemMemory',c.c_size_t),('AdapterLuid',LUID),('Flags',c.c_uint)]
|
| 9 |
+
def method(obj,i,restype,*args):
|
| 10 |
+
table=c.cast(obj,c.POINTER(c.POINTER(c.c_void_p))).contents
|
| 11 |
+
return c.WINFUNCTYPE(restype,c.c_void_p,*args)(table[i])
|
| 12 |
+
def discover():
|
| 13 |
+
iid=GUID((c.c_ubyte*16).from_buffer_copy(uuid.UUID('770aae78-f26f-4dba-a829-253c83d1b387').bytes_le))
|
| 14 |
+
factory=c.c_void_p();f=c.WinDLL('dxgi').CreateDXGIFactory1
|
| 15 |
+
f.argtypes=[c.POINTER(GUID),c.POINTER(c.c_void_p)];f.restype=c.c_long
|
| 16 |
+
assert f(c.byref(iid),c.byref(factory))==0
|
| 17 |
+
rows=[]
|
| 18 |
+
try:
|
| 19 |
+
for i in range(16):
|
| 20 |
+
adapter=c.c_void_p()
|
| 21 |
+
hr=method(factory,12,c.c_long,c.c_uint,c.POINTER(c.c_void_p))(factory,i,c.byref(adapter))
|
| 22 |
+
if hr<0:break
|
| 23 |
+
try:
|
| 24 |
+
desc=DESC();assert method(adapter,10,c.c_long,c.POINTER(DESC))(adapter,c.byref(desc))==0
|
| 25 |
+
if 'RTX 5090' in desc.Description:
|
| 26 |
+
rows.append(dict(name=desc.Description,vendor=desc.VendorId,device=desc.DeviceId,
|
| 27 |
+
bytes=desc.DedicatedVideoMemory,low=desc.AdapterLuid.LowPart,high=desc.AdapterLuid.HighPart,
|
| 28 |
+
luidHex=f'{desc.AdapterLuid.HighPart&0xffffffff:08x}{desc.AdapterLuid.LowPart:08x}'))
|
| 29 |
+
finally:method(adapter,2,c.c_ulong)(adapter)
|
| 30 |
+
finally:method(factory,2,c.c_ulong)(factory)
|
| 31 |
+
assert len(rows)==1
|
| 32 |
+
return rows[0]
|
| 33 |
+
if __name__=='__main__':print(json.dumps(discover()))
|
runtime/openai_server.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Loopback OpenAI chat adapter. Native Spark tool calls are parsed, not repaired."""
|
| 2 |
+
import argparse
|
| 3 |
+
import copy
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import threading
|
| 7 |
+
import time
|
| 8 |
+
import uuid
|
| 9 |
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
ROOT = Path(r'D:\webbrain-training\compass-tiny-v3-spark-x25-20260926')
|
| 13 |
+
MODEL_ID = 'webbrain-compass-tiny-v3-bf16'
|
| 14 |
+
PACKAGE = ROOT / 'release-compat-v3'
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def parse_tools(text, tools):
|
| 18 |
+
"""Only lossless native-format/schema decoding; errors stay visible."""
|
| 19 |
+
definitions = {t['function']['name']: t['function'] for t in tools or []}
|
| 20 |
+
calls = []
|
| 21 |
+
pattern = re.compile(r'<tool_call>(.*?)</tool_call>', re.S)
|
| 22 |
+
spans = list(pattern.finditer(text))
|
| 23 |
+
if text.count('<tool_call>') != len(spans) or text.count('</tool_call>') != len(spans):
|
| 24 |
+
raise ValueError('Incomplete native tool call')
|
| 25 |
+
for span in spans:
|
| 26 |
+
body = span.group(1)
|
| 27 |
+
name = body.split('<arg_key>', 1)[0].strip()
|
| 28 |
+
if name not in definitions:
|
| 29 |
+
raise ValueError(f'Unknown model-emitted function: {name}')
|
| 30 |
+
tail = body[len(body.split('<arg_key>', 1)[0]):]
|
| 31 |
+
arg_pattern = re.compile(r'<arg_key>(.*?)</arg_key><arg_value>(.*?)</arg_value>', re.S)
|
| 32 |
+
args = {}
|
| 33 |
+
cursor = 0
|
| 34 |
+
schema = definitions[name].get('parameters', {})
|
| 35 |
+
for arg in arg_pattern.finditer(tail):
|
| 36 |
+
if tail[cursor:arg.start()].strip():
|
| 37 |
+
raise ValueError('Malformed native argument sequence')
|
| 38 |
+
key, raw = arg.group(1), arg.group(2)
|
| 39 |
+
if key in args:
|
| 40 |
+
raise ValueError('Duplicate native argument key')
|
| 41 |
+
prop = schema.get('properties', {}).get(key, {})
|
| 42 |
+
args[key] = raw if prop.get('type') == 'string' else json.loads(raw)
|
| 43 |
+
cursor = arg.end()
|
| 44 |
+
if tail[cursor:].strip() or any(k not in args for k in schema.get('required', [])):
|
| 45 |
+
raise ValueError('Malformed or incomplete native arguments')
|
| 46 |
+
calls.append({'id': 'call_' + uuid.uuid4().hex[:16], 'type': 'function',
|
| 47 |
+
'function': {'name': name, 'arguments': json.dumps(args, ensure_ascii=False)}})
|
| 48 |
+
return calls, pattern.sub('', text).strip()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def normalize_messages(messages):
|
| 52 |
+
messages = copy.deepcopy(messages)
|
| 53 |
+
for message in messages:
|
| 54 |
+
for tool in message.get('tool_calls', []):
|
| 55 |
+
arguments = tool['function']['arguments']
|
| 56 |
+
if isinstance(arguments, str):
|
| 57 |
+
tool['function']['arguments'] = json.loads(arguments)
|
| 58 |
+
if not isinstance(tool['function']['arguments'], dict):
|
| 59 |
+
raise ValueError('Tool arguments must decode to an object')
|
| 60 |
+
return messages
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class Bf16Backend:
|
| 64 |
+
def __init__(self):
|
| 65 |
+
import os
|
| 66 |
+
import sys
|
| 67 |
+
source = Path(__file__).parents[1] / 'spark_x25_17b_webbrain_compass_v3'
|
| 68 |
+
sys.path.insert(0, str(source))
|
| 69 |
+
from train import gpu_guard
|
| 70 |
+
cfg = json.loads((source / 'train-config.json').read_text())
|
| 71 |
+
gpu_guard(cfg)
|
| 72 |
+
import torch
|
| 73 |
+
import runtime
|
| 74 |
+
from transformers import AutoTokenizer
|
| 75 |
+
torch.set_num_threads(8)
|
| 76 |
+
self.torch = torch
|
| 77 |
+
self.tokenizer = AutoTokenizer.from_pretrained(PACKAGE, local_files_only=True)
|
| 78 |
+
self.model = runtime.load_native(str(PACKAGE), dtype=torch.bfloat16, device_map={'': 0}).eval()
|
| 79 |
+
self.lock = threading.Lock()
|
| 80 |
+
uploaded = json.loads((ROOT / 'upload-verified.json').read_text())
|
| 81 |
+
self.info = {'id': MODEL_ID, 'precision': 'BF16', 'runtime': 'Transformers/PyTorch CUDA',
|
| 82 |
+
'hardware': 'NVIDIA GeForce RTX 5090', 'revision': uploaded['revision'],
|
| 83 |
+
'max_context_tokens': 16384, 'thinking_default': False,
|
| 84 |
+
'onnx': False, 'webgpu': False, 'cloud_fallback': False}
|
| 85 |
+
|
| 86 |
+
def generate(self, request):
|
| 87 |
+
if request.get('model') != MODEL_ID:
|
| 88 |
+
raise ValueError(f'Use exact model id {MODEL_ID}')
|
| 89 |
+
tools = request.get('tools')
|
| 90 |
+
messages = normalize_messages(request['messages'])
|
| 91 |
+
options = request.get('chat_template_kwargs', {})
|
| 92 |
+
if options.get('enable_thinking', False):
|
| 93 |
+
raise ValueError('This benchmark endpoint serves thinking-disabled Compass')
|
| 94 |
+
inputs = self.tokenizer.apply_chat_template(messages, tools=tools, enable_thinking=False,
|
| 95 |
+
add_generation_prompt=True, return_tensors='pt', return_dict=True).to('cuda')
|
| 96 |
+
tokens = int(inputs.input_ids.shape[1])
|
| 97 |
+
maximum = int(request.get('max_completion_tokens', request.get('max_tokens', 512)))
|
| 98 |
+
if maximum < 1 or maximum > 4096 or tokens + maximum > self.info['max_context_tokens']:
|
| 99 |
+
raise ValueError('Requested input/output exceeds the deployed 16K context limit')
|
| 100 |
+
temperature = float(request.get('temperature', 0))
|
| 101 |
+
if temperature < 0:
|
| 102 |
+
raise ValueError('Negative temperature')
|
| 103 |
+
kwargs = {'max_new_tokens': maximum, 'do_sample': temperature > 0,
|
| 104 |
+
'pad_token_id': self.tokenizer.pad_token_id, 'use_cache': True}
|
| 105 |
+
if temperature > 0:
|
| 106 |
+
kwargs.update(temperature=temperature, top_p=float(request.get('top_p', 1.0)))
|
| 107 |
+
with self.lock, self.torch.no_grad():
|
| 108 |
+
output = self.model.generate(**inputs, **kwargs)
|
| 109 |
+
tail = output[0, tokens:]
|
| 110 |
+
raw = self.tokenizer.decode(tail, skip_special_tokens=True)
|
| 111 |
+
finish = 'length' if len(tail) == maximum else 'stop'
|
| 112 |
+
stop = request.get('stop') or []
|
| 113 |
+
if isinstance(stop, str):
|
| 114 |
+
stop = [stop]
|
| 115 |
+
for marker in stop:
|
| 116 |
+
if marker in raw:
|
| 117 |
+
raw = raw.split(marker, 1)[0]
|
| 118 |
+
finish = 'stop'
|
| 119 |
+
parser_error = None
|
| 120 |
+
try:
|
| 121 |
+
calls, content = parse_tools(raw, tools)
|
| 122 |
+
except (ValueError, KeyError, TypeError, json.JSONDecodeError) as exc:
|
| 123 |
+
calls, content, parser_error = [], raw, str(exc)
|
| 124 |
+
message = {'role': 'assistant', 'content': content or None}
|
| 125 |
+
if calls:
|
| 126 |
+
message['tool_calls'] = calls
|
| 127 |
+
finish = 'tool_calls'
|
| 128 |
+
result = {'id': 'chatcmpl-' + uuid.uuid4().hex, 'object': 'chat.completion', 'created': int(time.time()),
|
| 129 |
+
'model': MODEL_ID, 'choices': [{'index': 0, 'message': message, 'finish_reason': finish}],
|
| 130 |
+
'usage': {'prompt_tokens': tokens, 'completion_tokens': len(tail), 'total_tokens': tokens + len(tail)},
|
| 131 |
+
'x_runtime': self.info}
|
| 132 |
+
if parser_error:
|
| 133 |
+
result['x_parser_error'] = parser_error
|
| 134 |
+
return result
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def main():
|
| 138 |
+
parser = argparse.ArgumentParser()
|
| 139 |
+
parser.add_argument('--port', type=int, default=8560)
|
| 140 |
+
args = parser.parse_args()
|
| 141 |
+
backend = Bf16Backend()
|
| 142 |
+
|
| 143 |
+
class Handler(BaseHTTPRequestHandler):
|
| 144 |
+
def log_message(self, fmt, *args):
|
| 145 |
+
# No prompts, cookies or credentials are logged.
|
| 146 |
+
print(json.dumps({'http': fmt % args, 'time': time.time()}), flush=True)
|
| 147 |
+
|
| 148 |
+
def send_json(self, status, data):
|
| 149 |
+
body = json.dumps(data, ensure_ascii=False).encode()
|
| 150 |
+
self.send_response(status)
|
| 151 |
+
self.send_header('Content-Type', 'application/json')
|
| 152 |
+
self.send_header('Content-Length', str(len(body)))
|
| 153 |
+
self.end_headers()
|
| 154 |
+
self.wfile.write(body)
|
| 155 |
+
|
| 156 |
+
def do_GET(self):
|
| 157 |
+
if self.path == '/v1/models':
|
| 158 |
+
self.send_json(200, {'object': 'list', 'data': [{**backend.info, 'object': 'model', 'owned_by': 'webbrain-one'}]})
|
| 159 |
+
elif self.path == '/health':
|
| 160 |
+
self.send_json(200, {'ready': True, **backend.info})
|
| 161 |
+
else:
|
| 162 |
+
self.send_json(404, {'error': 'Unknown route'})
|
| 163 |
+
|
| 164 |
+
def do_POST(self):
|
| 165 |
+
if self.path != '/v1/chat/completions':
|
| 166 |
+
return self.send_json(404, {'error': 'Unknown route'})
|
| 167 |
+
try:
|
| 168 |
+
length = int(self.headers.get('Content-Length', '0'))
|
| 169 |
+
if not 0 < length <= 4 * 1024 * 1024:
|
| 170 |
+
raise ValueError('Invalid body length')
|
| 171 |
+
request = json.loads(self.rfile.read(length))
|
| 172 |
+
if request.get('stream', False):
|
| 173 |
+
raise ValueError('Use stream=false on this benchmark endpoint')
|
| 174 |
+
result = backend.generate(request)
|
| 175 |
+
self.send_json(200, result)
|
| 176 |
+
except (ValueError, KeyError, TypeError) as exc:
|
| 177 |
+
self.send_json(400, {'error': {'message': str(exc), 'type': 'invalid_request_error'}})
|
| 178 |
+
except Exception as exc:
|
| 179 |
+
self.send_json(500, {'error': {'message': str(exc), 'type': 'runtime_error'}})
|
| 180 |
+
|
| 181 |
+
print(json.dumps({'ready': True, 'baseUrl': f'http://127.0.0.1:{args.port}/v1', **backend.info}), flush=True)
|
| 182 |
+
ThreadingHTTPServer(('127.0.0.1', args.port), Handler).serve_forever()
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
if __name__ == '__main__':
|
| 186 |
+
main()
|
runtime/vendor/LICENSE.onnxruntime.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) Microsoft Corporation
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
runtime/vendor/LICENSE.transformers.txt
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.
|
runtime/vendor/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Vendored Transformers.js WebGPU runtime
|
| 2 |
+
|
| 3 |
+
This directory packages the JavaScript and WASM runtime used by two local
|
| 4 |
+
WebGPU paths in Chrome and by offline RAG's CPU/WASM semantic reranker:
|
| 5 |
+
|
| 6 |
+
- **Apocalypse Mode -> local WebGPU chat** downloads the selected LFM2.5 text
|
| 7 |
+
or vision-language preset, or the Nanbeige4.2-3B ONNX export, used by the
|
| 8 |
+
standalone-chat nuclear override. An opt-in Bonsai 27B preset uses a separate
|
| 9 |
+
vendored bitgpu worker, not this Transformers.js runtime; see
|
| 10 |
+
`src/chrome/vendor/bitgpu/README.webbrain.md`.
|
| 11 |
+
- **Settings -> Multimodal -> Vision -> LFM2.5-VL local fallback** runs
|
| 12 |
+
`LiquidAI/LFM2.5-VL-450M-ONNX` as the dedicated screenshot sidecar.
|
| 13 |
+
- **Apocalypse Mode -> Offline RAG** runs the explicitly downloaded, pinned
|
| 14 |
+
`Xenova/multilingual-e5-small` q8 model in a separate CPU/WASM worker. Model
|
| 15 |
+
weights remain optional and are never bundled or downloaded by a question.
|
| 16 |
+
|
| 17 |
+
Model weights are not bundled. Transformers.js downloads each selected WebGPU
|
| 18 |
+
model on first use and stores it in the browser cache. The shipped ONNX chat
|
| 19 |
+
presets are LFM2.5 2.6B, 1.2B Instruct, 1.2B Thinking, VL 1.6B, VL 3B, and
|
| 20 |
+
Nanbeige4.2-3B.
|
| 21 |
+
They are available through the nuclear control in standalone chat and can also
|
| 22 |
+
be selected as the normal provider after download. The reasoning presets keep
|
| 23 |
+
completed thinking out of visible answers. Current LFM2.5-VL layouts use:
|
| 24 |
+
|
| 25 |
+
- `embed_tokens`: FP16
|
| 26 |
+
- `vision_encoder`: FP16
|
| 27 |
+
- `decoder_model_merged`: Q4
|
| 28 |
+
|
| 29 |
+
`Michionlion/Nanbeige4.2-3B-ONNX-WebGPU` needs no bundle patch, but it does
|
| 30 |
+
need two things from this runtime. It publishes one WebGPU-fused graph named
|
| 31 |
+
`onnx/model_webgpu_mlp_q4f16.onnx` instead of the default `model_q4f16.onnx`,
|
| 32 |
+
so the worker passes `model_file_name: 'model_webgpu_mlp'`; the two external
|
| 33 |
+
data shards are declared by the repository's own
|
| 34 |
+
`transformers.js_config.use_external_data_format`. Its graph also uses the
|
| 35 |
+
`com.microsoft::MatMulNBitsMlp` WebGPU kernel, which is compiled into the
|
| 36 |
+
vendored `ort-wasm-simd-threaded.asyncify.wasm`. Do not replace the ONNX
|
| 37 |
+
Runtime artifacts with a build that drops that kernel; a test asserts it is
|
| 38 |
+
present because its absence only shows up as an opaque session-creation
|
| 39 |
+
failure at runtime.
|
| 40 |
+
|
| 41 |
+
The dedicated 450M vision sidecar uses the same component layout and is
|
| 42 |
+
approximately 810 MB. The VL 1.6B chat export instead names its vision and
|
| 43 |
+
decoder components `embed_images` and `decoder`; the compatibility patch below
|
| 44 |
+
maps those files into the standard image-text session names.
|
| 45 |
+
|
| 46 |
+
## Packaged files
|
| 47 |
+
|
| 48 |
+
| File / directory | Source | Purpose |
|
| 49 |
+
| --- | --- | --- |
|
| 50 |
+
| `transformers.web.js` | `@huggingface/transformers` 4.2.0 | Browser ESM model/processor APIs |
|
| 51 |
+
| `ort.webgpu.mjs` | `onnxruntime-web` 1.27.0 | WebGPU execution provider |
|
| 52 |
+
| `onnxruntime-common/` | matching `onnxruntime-common` dependency | Tensor and session types |
|
| 53 |
+
| `ort-wasm-simd-threaded.asyncify.*` | `onnxruntime-web` 1.27.0 | The only WASM bridge; carries the WebGPU/JSEP runtime |
|
| 54 |
+
| `LICENSE.transformers.txt` | `@huggingface/transformers` 4.2.0 | Apache-2.0 license |
|
| 55 |
+
| `LICENSE.onnxruntime.txt` | ONNX Runtime 1.27.0 | MIT license |
|
| 56 |
+
| `ThirdPartyNotices.onnxruntime.txt` | ONNX Runtime 1.27.0 | Notices for incorporated third-party software |
|
| 57 |
+
|
| 58 |
+
The readable, unminified browser builds are committed so a fresh checkout is a
|
| 59 |
+
complete, Chrome Web Store-reviewable extension. Remote executable code is not
|
| 60 |
+
allowed by Manifest V3 CSP; only model/config/tokenizer data is fetched from
|
| 61 |
+
Hugging Face.
|
| 62 |
+
|
| 63 |
+
Only the asyncify variant is vendored. `ort.webgpu.mjs` resolves its WASM
|
| 64 |
+
filename from flags fixed at ONNX Runtime build time, and in this build the jsep
|
| 65 |
+
and jspi branches are compiled out, so `ort-wasm-simd-threaded.asyncify.*` is the
|
| 66 |
+
only bridge that can ever load. The WebGPU/JSEP execution provider lives inside
|
| 67 |
+
that artifact; it is not a separate download. Copying the `jsep` or `jspi` pair
|
| 68 |
+
adds tens of megabytes of unreachable binary to the reviewed package, so do not
|
| 69 |
+
restore them without first checking that filename branch.
|
| 70 |
+
|
| 71 |
+
The ONNX Runtime files are intentionally newer than the version pinned by
|
| 72 |
+
Transformers.js 4.2.0. Stable 1.27.0 contains WebGPU buffer-pool and
|
| 73 |
+
Qwen3/QMoE correctness fixes needed by Ling while retaining the same public
|
| 74 |
+
JavaScript session API used by this Transformers.js release.
|
| 75 |
+
|
| 76 |
+
## Browser bundle patches
|
| 77 |
+
|
| 78 |
+
The upstream browser bundle contains two bare module specifiers that an
|
| 79 |
+
unbundled extension cannot resolve. After copying a new release, rewrite them:
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
sed -i 's|"onnxruntime-web/webgpu"|"./ort.webgpu.mjs"|' \
|
| 83 |
+
src/chrome/vendor/transformers/transformers.web.js
|
| 84 |
+
sed -i 's|"onnxruntime-common"|"./onnxruntime-common/index.js"|' \
|
| 85 |
+
src/chrome/vendor/transformers/transformers.web.js
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
Verify that no executable bare imports remain:
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
grep -E '(import|export)[^"]*from\s+"[a-zA-Z@]' \
|
| 92 |
+
src/chrome/vendor/transformers/transformers.web.js \
|
| 93 |
+
| grep -v '^\s*//' | grep -v '^\s*\*'
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
The LFM2.5-VL ONNX repositories need two compatibility hooks. The 1.6B export
|
| 97 |
+
predates the standard ImageTextToText component filenames, so keep the small
|
| 98 |
+
`session_file_names` alias hook in
|
| 99 |
+
`MODEL_SESSION_CONFIG[MODEL_TYPES.ImageTextToText]`; the worker supplies aliases
|
| 100 |
+
through `config["transformers.js_config"]`. Keep the corresponding `getSession`
|
| 101 |
+
logic resolving device and dtype by logical `session_name`, while using the
|
| 102 |
+
aliased filename only to fetch the physical ONNX graph. Both current VL exports
|
| 103 |
+
also use the Transformers v5 processor layout: image metadata is nested in
|
| 104 |
+
`processor_config.json`, and the chat template lives in `chat_template.jinja`.
|
| 105 |
+
Keep `loadImageProcessorConfig`, `image_processor_config_file`, and
|
| 106 |
+
`chat_template_file` support so the worker can opt into that layout without
|
| 107 |
+
changing older models. Reapply these patches after replacing
|
| 108 |
+
`transformers.web.js`, and mirror the resulting browser bundle into Firefox so
|
| 109 |
+
the packaged vendor files remain byte-identical.
|
| 110 |
+
|
| 111 |
+
## Updating
|
| 112 |
+
|
| 113 |
+
Use a temporary dependency install; WebBrain does not need a runtime npm
|
| 114 |
+
dependency because the reviewed browser assets are committed directly:
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
npm install --no-save @huggingface/transformers@latest
|
| 118 |
+
cp node_modules/@huggingface/transformers/dist/transformers.web.js \
|
| 119 |
+
src/chrome/vendor/transformers/
|
| 120 |
+
cp node_modules/onnxruntime-web/dist/ort.webgpu.mjs \
|
| 121 |
+
src/chrome/vendor/transformers/
|
| 122 |
+
cp node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.asyncify.{mjs,wasm} \
|
| 123 |
+
src/chrome/vendor/transformers/
|
| 124 |
+
rm -rf src/chrome/vendor/transformers/onnxruntime-common
|
| 125 |
+
mkdir src/chrome/vendor/transformers/onnxruntime-common
|
| 126 |
+
cp node_modules/onnxruntime-common/dist/esm/*.js \
|
| 127 |
+
src/chrome/vendor/transformers/onnxruntime-common/
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
Copy the Transformers.js license and the ONNX Runtime license plus
|
| 131 |
+
`ThirdPartyNotices.txt` into this directory whenever the runtime is updated.
|
| 132 |
+
Reapply the specifier and ImageTextToText session-alias patches, update the
|
| 133 |
+
version table above, then verify:
|
| 134 |
+
|
| 135 |
+
1. `node --check` passes for the provider, host, and worker.
|
| 136 |
+
2. **Use local fallback** enables the option without downloading weights.
|
| 137 |
+
3. **Test Connection** reads `WB7` from the packaged vision probe image.
|
| 138 |
+
4. The second test reuses browser-cached model files.
|
| 139 |
+
|
| 140 |
+
## Runtime architecture
|
| 141 |
+
|
| 142 |
+
```text
|
| 143 |
+
ProviderManager._createProvider('webgpu') / getVisionProvider()
|
| 144 |
+
-> WebGPUProvider.chat() / WebGPUVisionProvider.chat()
|
| 145 |
+
-> MV3 offscreen document
|
| 146 |
+
-> dedicated module Worker
|
| 147 |
+
-> text-generation pipeline / AutoProcessor + AutoModelForImageTextToText
|
| 148 |
+
-> selected LFM2.5 or Nanbeige ONNX repo / LFM2.5-VL-450M-ONNX over WebGPU
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
Keep inference in the Worker. The MV3 service worker has no WebGPU, while the
|
| 152 |
+
offscreen document's main thread has shown tighter WASM allocation limits for
|
| 153 |
+
large ONNX runs. Do not set `preferredOutputLocation: 'gpu-buffer'` on this
|
| 154 |
+
generation path: Transformers.js decodes the generated tensor on the CPU and
|
| 155 |
+
must be allowed to download that output normally.
|
| 156 |
+
|
| 157 |
+
LFM2.5-VL expects the image placeholder before the user's text in its chat
|
| 158 |
+
template. The Worker normalizes incoming OpenAI-style multimodal messages to
|
| 159 |
+
that order. For the connection test, it replaces the packaged generic OCR image
|
| 160 |
+
with three large, unlabeled color panels. This proves the local model received
|
| 161 |
+
pixels without relying on fine OCR, which is brittle for a 450M model. Normal
|
| 162 |
+
screenshots are never replaced by this probe-only path.
|
runtime/vendor/ThirdPartyNotices.onnxruntime.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
runtime/vendor/onnxruntime-common/backend-impl.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
const backends = new Map();
|
| 4 |
+
const backendsSortedByPriority = [];
|
| 5 |
+
/**
|
| 6 |
+
* Register a backend.
|
| 7 |
+
*
|
| 8 |
+
* @param name - the name as a key to lookup as an execution provider.
|
| 9 |
+
* @param backend - the backend object.
|
| 10 |
+
* @param priority - an integer indicating the priority of the backend. Higher number means higher priority. if priority
|
| 11 |
+
* < 0, it will be considered as a 'beta' version and will not be used as a fallback backend by default.
|
| 12 |
+
*
|
| 13 |
+
* @ignore
|
| 14 |
+
*/
|
| 15 |
+
export const registerBackend = (name, backend, priority) => {
|
| 16 |
+
if (backend && typeof backend.init === 'function' && typeof backend.createInferenceSessionHandler === 'function') {
|
| 17 |
+
const currentBackend = backends.get(name);
|
| 18 |
+
if (currentBackend === undefined) {
|
| 19 |
+
backends.set(name, { backend, priority });
|
| 20 |
+
}
|
| 21 |
+
else if (currentBackend.priority > priority) {
|
| 22 |
+
// same name is already registered with a higher priority. skip registeration.
|
| 23 |
+
return;
|
| 24 |
+
}
|
| 25 |
+
else if (currentBackend.priority === priority) {
|
| 26 |
+
if (currentBackend.backend !== backend) {
|
| 27 |
+
throw new Error(`cannot register backend "${name}" using priority ${priority}`);
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
if (priority >= 0) {
|
| 31 |
+
const i = backendsSortedByPriority.indexOf(name);
|
| 32 |
+
if (i !== -1) {
|
| 33 |
+
backendsSortedByPriority.splice(i, 1);
|
| 34 |
+
}
|
| 35 |
+
for (let i = 0; i < backendsSortedByPriority.length; i++) {
|
| 36 |
+
if (backends.get(backendsSortedByPriority[i]).priority <= priority) {
|
| 37 |
+
backendsSortedByPriority.splice(i, 0, name);
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
backendsSortedByPriority.push(name);
|
| 42 |
+
}
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
throw new TypeError('not a valid backend');
|
| 46 |
+
};
|
| 47 |
+
/**
|
| 48 |
+
* Try to resolve and initialize a backend.
|
| 49 |
+
*
|
| 50 |
+
* @param backendName - the name of the backend.
|
| 51 |
+
* @returns the backend instance if resolved and initialized successfully, or an error message if failed.
|
| 52 |
+
*/
|
| 53 |
+
const tryResolveAndInitializeBackend = async (backendName) => {
|
| 54 |
+
const backendInfo = backends.get(backendName);
|
| 55 |
+
if (!backendInfo) {
|
| 56 |
+
return 'backend not found.';
|
| 57 |
+
}
|
| 58 |
+
if (backendInfo.initialized) {
|
| 59 |
+
return backendInfo.backend;
|
| 60 |
+
}
|
| 61 |
+
else if (backendInfo.aborted) {
|
| 62 |
+
return backendInfo.error;
|
| 63 |
+
}
|
| 64 |
+
else {
|
| 65 |
+
const isInitializing = !!backendInfo.initPromise;
|
| 66 |
+
try {
|
| 67 |
+
if (!isInitializing) {
|
| 68 |
+
backendInfo.initPromise = backendInfo.backend.init(backendName);
|
| 69 |
+
}
|
| 70 |
+
await backendInfo.initPromise;
|
| 71 |
+
backendInfo.initialized = true;
|
| 72 |
+
return backendInfo.backend;
|
| 73 |
+
}
|
| 74 |
+
catch (e) {
|
| 75 |
+
if (!isInitializing) {
|
| 76 |
+
backendInfo.error = `${e}`;
|
| 77 |
+
backendInfo.aborted = true;
|
| 78 |
+
}
|
| 79 |
+
return backendInfo.error;
|
| 80 |
+
}
|
| 81 |
+
finally {
|
| 82 |
+
delete backendInfo.initPromise;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
};
|
| 86 |
+
/**
|
| 87 |
+
* Resolve execution providers from the specific session options.
|
| 88 |
+
*
|
| 89 |
+
* @param options - the session options object.
|
| 90 |
+
* @returns a promise that resolves to a tuple of an initialized backend instance and a session options object with
|
| 91 |
+
* filtered EP list.
|
| 92 |
+
*
|
| 93 |
+
* @ignore
|
| 94 |
+
*/
|
| 95 |
+
export const resolveBackendAndExecutionProviders = async (options) => {
|
| 96 |
+
// extract backend hints from session options
|
| 97 |
+
const eps = options.executionProviders || [];
|
| 98 |
+
const backendHints = eps.map((i) => (typeof i === 'string' ? i : i.name));
|
| 99 |
+
const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
|
| 100 |
+
// try to resolve and initialize all requested backends
|
| 101 |
+
let backend;
|
| 102 |
+
const errors = [];
|
| 103 |
+
const availableBackendNames = new Set();
|
| 104 |
+
for (const backendName of backendNames) {
|
| 105 |
+
const resolveResult = await tryResolveAndInitializeBackend(backendName);
|
| 106 |
+
if (typeof resolveResult === 'string') {
|
| 107 |
+
errors.push({ name: backendName, err: resolveResult });
|
| 108 |
+
}
|
| 109 |
+
else {
|
| 110 |
+
if (!backend) {
|
| 111 |
+
backend = resolveResult;
|
| 112 |
+
}
|
| 113 |
+
if (backend === resolveResult) {
|
| 114 |
+
availableBackendNames.add(backendName);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
// if no backend is available, throw error.
|
| 119 |
+
if (!backend) {
|
| 120 |
+
throw new Error(`no available backend found. ERR: ${errors.map((e) => `[${e.name}] ${e.err}`).join(', ')}`);
|
| 121 |
+
}
|
| 122 |
+
// for each explicitly requested backend, if it's not available, output warning message.
|
| 123 |
+
for (const { name, err } of errors) {
|
| 124 |
+
if (backendHints.includes(name)) {
|
| 125 |
+
// eslint-disable-next-line no-console
|
| 126 |
+
console.warn(`removing requested execution provider "${name}" from session options because it is not available: ${err}`);
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
const filteredEps = eps.filter((i) => availableBackendNames.has(typeof i === 'string' ? i : i.name));
|
| 130 |
+
return [
|
| 131 |
+
backend,
|
| 132 |
+
new Proxy(options, {
|
| 133 |
+
get: (target, prop) => {
|
| 134 |
+
if (prop === 'executionProviders') {
|
| 135 |
+
return filteredEps;
|
| 136 |
+
}
|
| 137 |
+
return Reflect.get(target, prop);
|
| 138 |
+
},
|
| 139 |
+
}),
|
| 140 |
+
];
|
| 141 |
+
};
|
| 142 |
+
//# sourceMappingURL=backend-impl.js.map
|
runtime/vendor/onnxruntime-common/backend.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
export { registerBackend } from './backend-impl.js';
|
| 4 |
+
//# sourceMappingURL=backend.js.map
|
runtime/vendor/onnxruntime-common/env-impl.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
import { version } from './version.js';
|
| 4 |
+
let logLevelValue = 'warning';
|
| 5 |
+
export const env = {
|
| 6 |
+
wasm: {},
|
| 7 |
+
webgl: {},
|
| 8 |
+
webgpu: {},
|
| 9 |
+
versions: { common: version },
|
| 10 |
+
set logLevel(value) {
|
| 11 |
+
if (value === undefined) {
|
| 12 |
+
return;
|
| 13 |
+
}
|
| 14 |
+
if (typeof value !== 'string' || ['verbose', 'info', 'warning', 'error', 'fatal'].indexOf(value) === -1) {
|
| 15 |
+
throw new Error(`Unsupported logging level: ${value}`);
|
| 16 |
+
}
|
| 17 |
+
logLevelValue = value;
|
| 18 |
+
},
|
| 19 |
+
get logLevel() {
|
| 20 |
+
return logLevelValue;
|
| 21 |
+
},
|
| 22 |
+
};
|
| 23 |
+
// set property 'logLevel' so that they can be correctly transferred to worker by `postMessage()`.
|
| 24 |
+
Object.defineProperty(env, 'logLevel', { enumerable: true });
|
| 25 |
+
//# sourceMappingURL=env-impl.js.map
|
runtime/vendor/onnxruntime-common/env.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
import { env as envImpl } from './env-impl.js';
|
| 4 |
+
/**
|
| 5 |
+
* Represent a set of flags as a global singleton.
|
| 6 |
+
*/
|
| 7 |
+
export const env = envImpl;
|
| 8 |
+
//# sourceMappingURL=env.js.map
|
runtime/vendor/onnxruntime-common/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
/**
|
| 4 |
+
* # ONNX Runtime JavaScript API
|
| 5 |
+
*
|
| 6 |
+
* ONNX Runtime JavaScript API is a unified API for all JavaScript usages, including the following NPM packages:
|
| 7 |
+
*
|
| 8 |
+
* - [onnxruntime-node](https://www.npmjs.com/package/onnxruntime-node)
|
| 9 |
+
* - [onnxruntime-web](https://www.npmjs.com/package/onnxruntime-web)
|
| 10 |
+
* - [onnxruntime-react-native](https://www.npmjs.com/package/onnxruntime-react-native)
|
| 11 |
+
*
|
| 12 |
+
* See also:
|
| 13 |
+
* - [Get Started](https://onnxruntime.ai/docs/get-started/with-javascript/)
|
| 14 |
+
* - [Inference examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js)
|
| 15 |
+
*
|
| 16 |
+
* @packageDocumentation
|
| 17 |
+
*/
|
| 18 |
+
export * from './backend.js';
|
| 19 |
+
export * from './env.js';
|
| 20 |
+
export * from './inference-session.js';
|
| 21 |
+
export * from './tensor.js';
|
| 22 |
+
export * from './tensor-conversion.js';
|
| 23 |
+
export * from './tensor-factory.js';
|
| 24 |
+
export * from './trace.js';
|
| 25 |
+
export * from './onnx-model.js';
|
| 26 |
+
export * from './onnx-value.js';
|
| 27 |
+
//# sourceMappingURL=index.js.map
|
runtime/vendor/onnxruntime-common/inference-session-impl.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
import { resolveBackendAndExecutionProviders } from './backend-impl.js';
|
| 4 |
+
import { Tensor } from './tensor.js';
|
| 5 |
+
import { TRACE_FUNC_BEGIN, TRACE_FUNC_END, TRACE_EVENT_BEGIN, TRACE_EVENT_END } from './trace.js';
|
| 6 |
+
export class InferenceSession {
|
| 7 |
+
constructor(handler) {
|
| 8 |
+
this.handler = handler;
|
| 9 |
+
}
|
| 10 |
+
async run(feeds, arg1, arg2) {
|
| 11 |
+
TRACE_FUNC_BEGIN();
|
| 12 |
+
TRACE_EVENT_BEGIN('InferenceSession.run');
|
| 13 |
+
const fetches = {};
|
| 14 |
+
let options = {};
|
| 15 |
+
// check inputs
|
| 16 |
+
if (typeof feeds !== 'object' || feeds === null || feeds instanceof Tensor || Array.isArray(feeds)) {
|
| 17 |
+
throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
|
| 18 |
+
}
|
| 19 |
+
let isFetchesEmpty = true;
|
| 20 |
+
// determine which override is being used
|
| 21 |
+
if (typeof arg1 === 'object') {
|
| 22 |
+
if (arg1 === null) {
|
| 23 |
+
throw new TypeError('Unexpected argument[1]: cannot be null.');
|
| 24 |
+
}
|
| 25 |
+
if (arg1 instanceof Tensor) {
|
| 26 |
+
throw new TypeError("'fetches' cannot be a Tensor");
|
| 27 |
+
}
|
| 28 |
+
if (Array.isArray(arg1)) {
|
| 29 |
+
if (arg1.length === 0) {
|
| 30 |
+
throw new TypeError("'fetches' cannot be an empty array.");
|
| 31 |
+
}
|
| 32 |
+
isFetchesEmpty = false;
|
| 33 |
+
// output names
|
| 34 |
+
for (const name of arg1) {
|
| 35 |
+
if (typeof name !== 'string') {
|
| 36 |
+
throw new TypeError("'fetches' must be a string array or an object.");
|
| 37 |
+
}
|
| 38 |
+
if (this.outputNames.indexOf(name) === -1) {
|
| 39 |
+
throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
|
| 40 |
+
}
|
| 41 |
+
fetches[name] = null;
|
| 42 |
+
}
|
| 43 |
+
if (typeof arg2 === 'object' && arg2 !== null) {
|
| 44 |
+
options = arg2;
|
| 45 |
+
}
|
| 46 |
+
else if (typeof arg2 !== 'undefined') {
|
| 47 |
+
throw new TypeError("'options' must be an object.");
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
else {
|
| 51 |
+
// decide whether arg1 is fetches or options
|
| 52 |
+
// if any output name is present and its value is valid OnnxValue, we consider it fetches
|
| 53 |
+
let isFetches = false;
|
| 54 |
+
const arg1Keys = Object.getOwnPropertyNames(arg1);
|
| 55 |
+
for (const name of this.outputNames) {
|
| 56 |
+
if (arg1Keys.indexOf(name) !== -1) {
|
| 57 |
+
const v = arg1[name];
|
| 58 |
+
if (v === null || v instanceof Tensor) {
|
| 59 |
+
isFetches = true;
|
| 60 |
+
isFetchesEmpty = false;
|
| 61 |
+
fetches[name] = v;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
if (isFetches) {
|
| 66 |
+
if (typeof arg2 === 'object' && arg2 !== null) {
|
| 67 |
+
options = arg2;
|
| 68 |
+
}
|
| 69 |
+
else if (typeof arg2 !== 'undefined') {
|
| 70 |
+
throw new TypeError("'options' must be an object.");
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
else {
|
| 74 |
+
options = arg1;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
else if (typeof arg1 !== 'undefined') {
|
| 79 |
+
throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
|
| 80 |
+
}
|
| 81 |
+
// check if all inputs are in feed
|
| 82 |
+
for (const name of this.inputNames) {
|
| 83 |
+
if (typeof feeds[name] === 'undefined') {
|
| 84 |
+
throw new Error(`input '${name}' is missing in 'feeds'.`);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
// if no fetches is specified, we use the full output names list
|
| 88 |
+
if (isFetchesEmpty) {
|
| 89 |
+
for (const name of this.outputNames) {
|
| 90 |
+
fetches[name] = null;
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
// feeds, fetches and options are prepared
|
| 94 |
+
const results = await this.handler.run(feeds, fetches, options);
|
| 95 |
+
const returnValue = {};
|
| 96 |
+
for (const key in results) {
|
| 97 |
+
if (Object.hasOwnProperty.call(results, key)) {
|
| 98 |
+
const result = results[key];
|
| 99 |
+
if (result instanceof Tensor) {
|
| 100 |
+
returnValue[key] = result;
|
| 101 |
+
}
|
| 102 |
+
else {
|
| 103 |
+
returnValue[key] = new Tensor(result.type, result.data, result.dims);
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
TRACE_EVENT_END('InferenceSession.run');
|
| 108 |
+
TRACE_FUNC_END();
|
| 109 |
+
return returnValue;
|
| 110 |
+
}
|
| 111 |
+
async release() {
|
| 112 |
+
return this.handler.dispose();
|
| 113 |
+
}
|
| 114 |
+
static async create(arg0, arg1, arg2, arg3) {
|
| 115 |
+
TRACE_FUNC_BEGIN();
|
| 116 |
+
TRACE_EVENT_BEGIN('InferenceSession.create');
|
| 117 |
+
// either load from a file or buffer
|
| 118 |
+
let filePathOrUint8Array;
|
| 119 |
+
let options = {};
|
| 120 |
+
if (typeof arg0 === 'string') {
|
| 121 |
+
filePathOrUint8Array = arg0;
|
| 122 |
+
if (typeof arg1 === 'object' && arg1 !== null) {
|
| 123 |
+
options = arg1;
|
| 124 |
+
}
|
| 125 |
+
else if (typeof arg1 !== 'undefined') {
|
| 126 |
+
throw new TypeError("'options' must be an object.");
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
else if (arg0 instanceof Uint8Array) {
|
| 130 |
+
filePathOrUint8Array = arg0;
|
| 131 |
+
if (typeof arg1 === 'object' && arg1 !== null) {
|
| 132 |
+
options = arg1;
|
| 133 |
+
}
|
| 134 |
+
else if (typeof arg1 !== 'undefined') {
|
| 135 |
+
throw new TypeError("'options' must be an object.");
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
else if (arg0 instanceof ArrayBuffer ||
|
| 139 |
+
(typeof SharedArrayBuffer !== 'undefined' && arg0 instanceof SharedArrayBuffer)) {
|
| 140 |
+
const buffer = arg0;
|
| 141 |
+
let byteOffset = 0;
|
| 142 |
+
let byteLength = arg0.byteLength;
|
| 143 |
+
if (typeof arg1 === 'object' && arg1 !== null) {
|
| 144 |
+
options = arg1;
|
| 145 |
+
}
|
| 146 |
+
else if (typeof arg1 === 'number') {
|
| 147 |
+
byteOffset = arg1;
|
| 148 |
+
if (!Number.isSafeInteger(byteOffset)) {
|
| 149 |
+
throw new RangeError("'byteOffset' must be an integer.");
|
| 150 |
+
}
|
| 151 |
+
if (byteOffset < 0 || byteOffset >= buffer.byteLength) {
|
| 152 |
+
throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`);
|
| 153 |
+
}
|
| 154 |
+
byteLength = arg0.byteLength - byteOffset;
|
| 155 |
+
if (typeof arg2 === 'number') {
|
| 156 |
+
byteLength = arg2;
|
| 157 |
+
if (!Number.isSafeInteger(byteLength)) {
|
| 158 |
+
throw new RangeError("'byteLength' must be an integer.");
|
| 159 |
+
}
|
| 160 |
+
if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) {
|
| 161 |
+
throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`);
|
| 162 |
+
}
|
| 163 |
+
if (typeof arg3 === 'object' && arg3 !== null) {
|
| 164 |
+
options = arg3;
|
| 165 |
+
}
|
| 166 |
+
else if (typeof arg3 !== 'undefined') {
|
| 167 |
+
throw new TypeError("'options' must be an object.");
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
else if (typeof arg2 !== 'undefined') {
|
| 171 |
+
throw new TypeError("'byteLength' must be a number.");
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
else if (typeof arg1 !== 'undefined') {
|
| 175 |
+
throw new TypeError("'options' must be an object.");
|
| 176 |
+
}
|
| 177 |
+
filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength);
|
| 178 |
+
}
|
| 179 |
+
else {
|
| 180 |
+
throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
|
| 181 |
+
}
|
| 182 |
+
// resolve backend, update session options with validated EPs, and create session handler
|
| 183 |
+
const [backend, optionsWithValidatedEPs] = await resolveBackendAndExecutionProviders(options);
|
| 184 |
+
const handler = await backend.createInferenceSessionHandler(filePathOrUint8Array, optionsWithValidatedEPs);
|
| 185 |
+
TRACE_EVENT_END('InferenceSession.create');
|
| 186 |
+
TRACE_FUNC_END();
|
| 187 |
+
return new InferenceSession(handler);
|
| 188 |
+
}
|
| 189 |
+
startProfiling() {
|
| 190 |
+
this.handler.startProfiling();
|
| 191 |
+
}
|
| 192 |
+
endProfiling() {
|
| 193 |
+
this.handler.endProfiling();
|
| 194 |
+
}
|
| 195 |
+
get inputNames() {
|
| 196 |
+
return this.handler.inputNames;
|
| 197 |
+
}
|
| 198 |
+
get outputNames() {
|
| 199 |
+
return this.handler.outputNames;
|
| 200 |
+
}
|
| 201 |
+
get inputMetadata() {
|
| 202 |
+
return this.handler.inputMetadata;
|
| 203 |
+
}
|
| 204 |
+
get outputMetadata() {
|
| 205 |
+
return this.handler.outputMetadata;
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
//# sourceMappingURL=inference-session-impl.js.map
|
runtime/vendor/onnxruntime-common/inference-session.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
import { InferenceSession as InferenceSessionImpl } from './inference-session-impl.js';
|
| 4 |
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
| 5 |
+
export const InferenceSession = InferenceSessionImpl;
|
| 6 |
+
//# sourceMappingURL=inference-session.js.map
|
runtime/vendor/onnxruntime-common/onnx-model.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
export {};
|
| 4 |
+
//# sourceMappingURL=onnx-model.js.map
|
runtime/vendor/onnxruntime-common/onnx-value.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
export {};
|
| 4 |
+
//# sourceMappingURL=onnx-value.js.map
|
runtime/vendor/onnxruntime-common/tensor-conversion-impl.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
/**
|
| 4 |
+
* implementation of Tensor.toDataURL()
|
| 5 |
+
*/
|
| 6 |
+
export const tensorToDataURL = (tensor, options) => {
|
| 7 |
+
const canvas = typeof document !== 'undefined' ? document.createElement('canvas') : new OffscreenCanvas(1, 1);
|
| 8 |
+
canvas.width = tensor.dims[3];
|
| 9 |
+
canvas.height = tensor.dims[2];
|
| 10 |
+
const pixels2DContext = canvas.getContext('2d');
|
| 11 |
+
if (pixels2DContext != null) {
|
| 12 |
+
// Default values for height and width & format
|
| 13 |
+
let width;
|
| 14 |
+
let height;
|
| 15 |
+
if (options?.tensorLayout !== undefined && options.tensorLayout === 'NHWC') {
|
| 16 |
+
width = tensor.dims[2];
|
| 17 |
+
height = tensor.dims[3];
|
| 18 |
+
}
|
| 19 |
+
else {
|
| 20 |
+
// Default layout is NCWH
|
| 21 |
+
width = tensor.dims[3];
|
| 22 |
+
height = tensor.dims[2];
|
| 23 |
+
}
|
| 24 |
+
const inputformat = options?.format !== undefined ? options.format : 'RGB';
|
| 25 |
+
const norm = options?.norm;
|
| 26 |
+
let normMean;
|
| 27 |
+
let normBias;
|
| 28 |
+
if (norm === undefined || norm.mean === undefined) {
|
| 29 |
+
normMean = [255, 255, 255, 255];
|
| 30 |
+
}
|
| 31 |
+
else {
|
| 32 |
+
if (typeof norm.mean === 'number') {
|
| 33 |
+
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
| 34 |
+
}
|
| 35 |
+
else {
|
| 36 |
+
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 0];
|
| 37 |
+
if (norm.mean[3] !== undefined) {
|
| 38 |
+
normMean[3] = norm.mean[3];
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
if (norm === undefined || norm.bias === undefined) {
|
| 43 |
+
normBias = [0, 0, 0, 0];
|
| 44 |
+
}
|
| 45 |
+
else {
|
| 46 |
+
if (typeof norm.bias === 'number') {
|
| 47 |
+
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
| 48 |
+
}
|
| 49 |
+
else {
|
| 50 |
+
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
|
| 51 |
+
if (norm.bias[3] !== undefined) {
|
| 52 |
+
normBias[3] = norm.bias[3];
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
const stride = height * width;
|
| 57 |
+
// Default pointer assignments
|
| 58 |
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
| 59 |
+
// Updating the pointer assignments based on the input image format
|
| 60 |
+
if (inputformat === 'RGBA') {
|
| 61 |
+
rTensorPointer = 0;
|
| 62 |
+
gTensorPointer = stride;
|
| 63 |
+
bTensorPointer = stride * 2;
|
| 64 |
+
aTensorPointer = stride * 3;
|
| 65 |
+
}
|
| 66 |
+
else if (inputformat === 'RGB') {
|
| 67 |
+
rTensorPointer = 0;
|
| 68 |
+
gTensorPointer = stride;
|
| 69 |
+
bTensorPointer = stride * 2;
|
| 70 |
+
}
|
| 71 |
+
else if (inputformat === 'RBG') {
|
| 72 |
+
rTensorPointer = 0;
|
| 73 |
+
bTensorPointer = stride;
|
| 74 |
+
gTensorPointer = stride * 2;
|
| 75 |
+
}
|
| 76 |
+
for (let i = 0; i < height; i++) {
|
| 77 |
+
for (let j = 0; j < width; j++) {
|
| 78 |
+
const R = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0]; // R value
|
| 79 |
+
const G = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1]; // G value
|
| 80 |
+
const B = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2]; // B value
|
| 81 |
+
const A = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3]; // A value
|
| 82 |
+
pixels2DContext.fillStyle = 'rgba(' + R + ',' + G + ',' + B + ',' + A + ')';
|
| 83 |
+
pixels2DContext.fillRect(j, i, 1, 1);
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
if ('toDataURL' in canvas) {
|
| 87 |
+
return canvas.toDataURL();
|
| 88 |
+
}
|
| 89 |
+
else {
|
| 90 |
+
throw new Error('toDataURL is not supported');
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
else {
|
| 94 |
+
throw new Error('Can not access image data');
|
| 95 |
+
}
|
| 96 |
+
};
|
| 97 |
+
/**
|
| 98 |
+
* implementation of Tensor.toImageData()
|
| 99 |
+
*/
|
| 100 |
+
export const tensorToImageData = (tensor, options) => {
|
| 101 |
+
const pixels2DContext = typeof document !== 'undefined'
|
| 102 |
+
? document.createElement('canvas').getContext('2d')
|
| 103 |
+
: new OffscreenCanvas(1, 1).getContext('2d');
|
| 104 |
+
let image;
|
| 105 |
+
if (pixels2DContext != null) {
|
| 106 |
+
// Default values for height and width & format
|
| 107 |
+
let width;
|
| 108 |
+
let height;
|
| 109 |
+
let channels;
|
| 110 |
+
if (options?.tensorLayout !== undefined && options.tensorLayout === 'NHWC') {
|
| 111 |
+
width = tensor.dims[2];
|
| 112 |
+
height = tensor.dims[1];
|
| 113 |
+
channels = tensor.dims[3];
|
| 114 |
+
}
|
| 115 |
+
else {
|
| 116 |
+
// Default layout is NCWH
|
| 117 |
+
width = tensor.dims[3];
|
| 118 |
+
height = tensor.dims[2];
|
| 119 |
+
channels = tensor.dims[1];
|
| 120 |
+
}
|
| 121 |
+
const inputformat = options !== undefined ? (options.format !== undefined ? options.format : 'RGB') : 'RGB';
|
| 122 |
+
const norm = options?.norm;
|
| 123 |
+
let normMean;
|
| 124 |
+
let normBias;
|
| 125 |
+
if (norm === undefined || norm.mean === undefined) {
|
| 126 |
+
normMean = [255, 255, 255, 255];
|
| 127 |
+
}
|
| 128 |
+
else {
|
| 129 |
+
if (typeof norm.mean === 'number') {
|
| 130 |
+
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
| 131 |
+
}
|
| 132 |
+
else {
|
| 133 |
+
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 255];
|
| 134 |
+
if (norm.mean[3] !== undefined) {
|
| 135 |
+
normMean[3] = norm.mean[3];
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
if (norm === undefined || norm.bias === undefined) {
|
| 140 |
+
normBias = [0, 0, 0, 0];
|
| 141 |
+
}
|
| 142 |
+
else {
|
| 143 |
+
if (typeof norm.bias === 'number') {
|
| 144 |
+
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
| 145 |
+
}
|
| 146 |
+
else {
|
| 147 |
+
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
|
| 148 |
+
if (norm.bias[3] !== undefined) {
|
| 149 |
+
normBias[3] = norm.bias[3];
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
const stride = height * width;
|
| 154 |
+
if (options !== undefined) {
|
| 155 |
+
if ((options.format !== undefined && channels === 4 && options.format !== 'RGBA') ||
|
| 156 |
+
(channels === 3 && options.format !== 'RGB' && options.format !== 'BGR')) {
|
| 157 |
+
throw new Error("Tensor format doesn't match input tensor dims");
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
// Default pointer assignments
|
| 161 |
+
const step = 4;
|
| 162 |
+
let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
| 163 |
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
| 164 |
+
// Updating the pointer assignments based on the input image format
|
| 165 |
+
if (inputformat === 'RGBA') {
|
| 166 |
+
rTensorPointer = 0;
|
| 167 |
+
gTensorPointer = stride;
|
| 168 |
+
bTensorPointer = stride * 2;
|
| 169 |
+
aTensorPointer = stride * 3;
|
| 170 |
+
}
|
| 171 |
+
else if (inputformat === 'RGB') {
|
| 172 |
+
rTensorPointer = 0;
|
| 173 |
+
gTensorPointer = stride;
|
| 174 |
+
bTensorPointer = stride * 2;
|
| 175 |
+
}
|
| 176 |
+
else if (inputformat === 'RBG') {
|
| 177 |
+
rTensorPointer = 0;
|
| 178 |
+
bTensorPointer = stride;
|
| 179 |
+
gTensorPointer = stride * 2;
|
| 180 |
+
}
|
| 181 |
+
image = pixels2DContext.createImageData(width, height);
|
| 182 |
+
for (let i = 0; i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) {
|
| 183 |
+
image.data[rImagePointer] = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0]; // R value
|
| 184 |
+
image.data[gImagePointer] = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1]; // G value
|
| 185 |
+
image.data[bImagePointer] = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2]; // B value
|
| 186 |
+
image.data[aImagePointer] =
|
| 187 |
+
aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3]; // A value
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
else {
|
| 191 |
+
throw new Error('Can not access image data');
|
| 192 |
+
}
|
| 193 |
+
return image;
|
| 194 |
+
};
|
| 195 |
+
//# sourceMappingURL=tensor-conversion-impl.js.map
|
runtime/vendor/onnxruntime-common/tensor-conversion.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
export {};
|
| 4 |
+
//# sourceMappingURL=tensor-conversion.js.map
|
runtime/vendor/onnxruntime-common/tensor-factory-impl.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
import { Tensor } from './tensor-impl.js';
|
| 4 |
+
/**
|
| 5 |
+
* Create a new tensor object from image object
|
| 6 |
+
*
|
| 7 |
+
* @param buffer - Extracted image buffer data - assuming RGBA format
|
| 8 |
+
* @param imageFormat - input image configuration - required configurations height, width, format
|
| 9 |
+
* @param tensorFormat - output tensor configuration - Default is RGB format
|
| 10 |
+
*/
|
| 11 |
+
export const bufferToTensor = (buffer, options) => {
|
| 12 |
+
if (buffer === undefined) {
|
| 13 |
+
throw new Error('Image buffer must be defined');
|
| 14 |
+
}
|
| 15 |
+
if (options.height === undefined || options.width === undefined) {
|
| 16 |
+
throw new Error('Image height and width must be defined');
|
| 17 |
+
}
|
| 18 |
+
if (options.tensorLayout === 'NHWC') {
|
| 19 |
+
throw new Error('NHWC Tensor layout is not supported yet');
|
| 20 |
+
}
|
| 21 |
+
const { height, width } = options;
|
| 22 |
+
const norm = options.norm ?? { mean: 255, bias: 0 };
|
| 23 |
+
let normMean;
|
| 24 |
+
let normBias;
|
| 25 |
+
if (typeof norm.mean === 'number') {
|
| 26 |
+
normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
|
| 27 |
+
}
|
| 28 |
+
else {
|
| 29 |
+
normMean = [norm.mean[0], norm.mean[1], norm.mean[2], norm.mean[3] ?? 255];
|
| 30 |
+
}
|
| 31 |
+
if (typeof norm.bias === 'number') {
|
| 32 |
+
normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
|
| 33 |
+
}
|
| 34 |
+
else {
|
| 35 |
+
normBias = [norm.bias[0], norm.bias[1], norm.bias[2], norm.bias[3] ?? 0];
|
| 36 |
+
}
|
| 37 |
+
const inputformat = options.format !== undefined ? options.format : 'RGBA';
|
| 38 |
+
// default value is RGBA since imagedata and HTMLImageElement uses it
|
| 39 |
+
const outputformat = options.tensorFormat !== undefined ? (options.tensorFormat !== undefined ? options.tensorFormat : 'RGB') : 'RGB';
|
| 40 |
+
const stride = height * width;
|
| 41 |
+
const float32Data = outputformat === 'RGBA' ? new Float32Array(stride * 4) : new Float32Array(stride * 3);
|
| 42 |
+
// Default pointer assignments
|
| 43 |
+
let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
| 44 |
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
| 45 |
+
// Updating the pointer assignments based on the input image format
|
| 46 |
+
if (inputformat === 'RGB') {
|
| 47 |
+
step = 3;
|
| 48 |
+
rImagePointer = 0;
|
| 49 |
+
gImagePointer = 1;
|
| 50 |
+
bImagePointer = 2;
|
| 51 |
+
aImagePointer = -1;
|
| 52 |
+
}
|
| 53 |
+
// Updating the pointer assignments based on the output tensor format
|
| 54 |
+
if (outputformat === 'RGBA') {
|
| 55 |
+
aTensorPointer = stride * 3;
|
| 56 |
+
}
|
| 57 |
+
else if (outputformat === 'RBG') {
|
| 58 |
+
rTensorPointer = 0;
|
| 59 |
+
bTensorPointer = stride;
|
| 60 |
+
gTensorPointer = stride * 2;
|
| 61 |
+
}
|
| 62 |
+
else if (outputformat === 'BGR') {
|
| 63 |
+
bTensorPointer = 0;
|
| 64 |
+
gTensorPointer = stride;
|
| 65 |
+
rTensorPointer = stride * 2;
|
| 66 |
+
}
|
| 67 |
+
for (let i = 0; i < stride; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) {
|
| 68 |
+
float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias[0]) / normMean[0];
|
| 69 |
+
float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias[1]) / normMean[1];
|
| 70 |
+
float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias[2]) / normMean[2];
|
| 71 |
+
if (aTensorPointer !== -1 && aImagePointer !== -1) {
|
| 72 |
+
float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
// Float32Array -> ort.Tensor
|
| 76 |
+
const outputTensor = outputformat === 'RGBA'
|
| 77 |
+
? new Tensor('float32', float32Data, [1, 4, height, width])
|
| 78 |
+
: new Tensor('float32', float32Data, [1, 3, height, width]);
|
| 79 |
+
return outputTensor;
|
| 80 |
+
};
|
| 81 |
+
/**
|
| 82 |
+
* implementation of Tensor.fromImage().
|
| 83 |
+
*/
|
| 84 |
+
export const tensorFromImage = async (image, options) => {
|
| 85 |
+
// checking the type of image object
|
| 86 |
+
const isHTMLImageEle = typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement;
|
| 87 |
+
const isImageDataEle = typeof ImageData !== 'undefined' && image instanceof ImageData;
|
| 88 |
+
const isImageBitmap = typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap;
|
| 89 |
+
const isString = typeof image === 'string';
|
| 90 |
+
let data;
|
| 91 |
+
let bufferToTensorOptions = options ?? {};
|
| 92 |
+
const createCanvas = () => {
|
| 93 |
+
if (typeof document !== 'undefined') {
|
| 94 |
+
return document.createElement('canvas');
|
| 95 |
+
}
|
| 96 |
+
else if (typeof OffscreenCanvas !== 'undefined') {
|
| 97 |
+
return new OffscreenCanvas(1, 1);
|
| 98 |
+
}
|
| 99 |
+
else {
|
| 100 |
+
throw new Error('Canvas is not supported');
|
| 101 |
+
}
|
| 102 |
+
};
|
| 103 |
+
const createCanvasContext = (canvas) => {
|
| 104 |
+
if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {
|
| 105 |
+
return canvas.getContext('2d');
|
| 106 |
+
}
|
| 107 |
+
else if (canvas instanceof OffscreenCanvas) {
|
| 108 |
+
return canvas.getContext('2d');
|
| 109 |
+
}
|
| 110 |
+
else {
|
| 111 |
+
return null;
|
| 112 |
+
}
|
| 113 |
+
};
|
| 114 |
+
// filling and checking image configuration options
|
| 115 |
+
if (isHTMLImageEle) {
|
| 116 |
+
// HTMLImageElement - image object - format is RGBA by default
|
| 117 |
+
const canvas = createCanvas();
|
| 118 |
+
canvas.width = image.width;
|
| 119 |
+
canvas.height = image.height;
|
| 120 |
+
const pixels2DContext = createCanvasContext(canvas);
|
| 121 |
+
if (pixels2DContext != null) {
|
| 122 |
+
let height = image.height;
|
| 123 |
+
let width = image.width;
|
| 124 |
+
if (options !== undefined && options.resizedHeight !== undefined && options.resizedWidth !== undefined) {
|
| 125 |
+
height = options.resizedHeight;
|
| 126 |
+
width = options.resizedWidth;
|
| 127 |
+
}
|
| 128 |
+
if (options !== undefined) {
|
| 129 |
+
bufferToTensorOptions = options;
|
| 130 |
+
if (options.tensorFormat !== undefined) {
|
| 131 |
+
throw new Error('Image input config format must be RGBA for HTMLImageElement');
|
| 132 |
+
}
|
| 133 |
+
else {
|
| 134 |
+
bufferToTensorOptions.tensorFormat = 'RGBA';
|
| 135 |
+
}
|
| 136 |
+
bufferToTensorOptions.height = height;
|
| 137 |
+
bufferToTensorOptions.width = width;
|
| 138 |
+
}
|
| 139 |
+
else {
|
| 140 |
+
bufferToTensorOptions.tensorFormat = 'RGBA';
|
| 141 |
+
bufferToTensorOptions.height = height;
|
| 142 |
+
bufferToTensorOptions.width = width;
|
| 143 |
+
}
|
| 144 |
+
pixels2DContext.drawImage(image, 0, 0);
|
| 145 |
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
| 146 |
+
}
|
| 147 |
+
else {
|
| 148 |
+
throw new Error('Can not access image data');
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
else if (isImageDataEle) {
|
| 152 |
+
let height;
|
| 153 |
+
let width;
|
| 154 |
+
if (options !== undefined && options.resizedWidth !== undefined && options.resizedHeight !== undefined) {
|
| 155 |
+
height = options.resizedHeight;
|
| 156 |
+
width = options.resizedWidth;
|
| 157 |
+
}
|
| 158 |
+
else {
|
| 159 |
+
height = image.height;
|
| 160 |
+
width = image.width;
|
| 161 |
+
}
|
| 162 |
+
if (options !== undefined) {
|
| 163 |
+
bufferToTensorOptions = options;
|
| 164 |
+
}
|
| 165 |
+
bufferToTensorOptions.format = 'RGBA';
|
| 166 |
+
bufferToTensorOptions.height = height;
|
| 167 |
+
bufferToTensorOptions.width = width;
|
| 168 |
+
if (options !== undefined) {
|
| 169 |
+
const tempCanvas = createCanvas();
|
| 170 |
+
tempCanvas.width = width;
|
| 171 |
+
tempCanvas.height = height;
|
| 172 |
+
const pixels2DContext = createCanvasContext(tempCanvas);
|
| 173 |
+
if (pixels2DContext != null) {
|
| 174 |
+
pixels2DContext.putImageData(image, 0, 0);
|
| 175 |
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
| 176 |
+
}
|
| 177 |
+
else {
|
| 178 |
+
throw new Error('Can not access image data');
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
else {
|
| 182 |
+
data = image.data;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
else if (isImageBitmap) {
|
| 186 |
+
// ImageBitmap - image object - format must be provided by user
|
| 187 |
+
if (options === undefined) {
|
| 188 |
+
throw new Error('Please provide image config with format for Imagebitmap');
|
| 189 |
+
}
|
| 190 |
+
const canvas = createCanvas();
|
| 191 |
+
canvas.width = image.width;
|
| 192 |
+
canvas.height = image.height;
|
| 193 |
+
const pixels2DContext = createCanvasContext(canvas);
|
| 194 |
+
if (pixels2DContext != null) {
|
| 195 |
+
const height = image.height;
|
| 196 |
+
const width = image.width;
|
| 197 |
+
pixels2DContext.drawImage(image, 0, 0, width, height);
|
| 198 |
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
| 199 |
+
bufferToTensorOptions.height = height;
|
| 200 |
+
bufferToTensorOptions.width = width;
|
| 201 |
+
return bufferToTensor(data, bufferToTensorOptions);
|
| 202 |
+
}
|
| 203 |
+
else {
|
| 204 |
+
throw new Error('Can not access image data');
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
else if (isString) {
|
| 208 |
+
return new Promise((resolve, reject) => {
|
| 209 |
+
const canvas = createCanvas();
|
| 210 |
+
const context = createCanvasContext(canvas);
|
| 211 |
+
if (!image || !context) {
|
| 212 |
+
return reject();
|
| 213 |
+
}
|
| 214 |
+
const newImage = new Image();
|
| 215 |
+
newImage.crossOrigin = 'Anonymous';
|
| 216 |
+
newImage.src = image;
|
| 217 |
+
newImage.onload = () => {
|
| 218 |
+
canvas.width = newImage.width;
|
| 219 |
+
canvas.height = newImage.height;
|
| 220 |
+
context.drawImage(newImage, 0, 0, canvas.width, canvas.height);
|
| 221 |
+
const img = context.getImageData(0, 0, canvas.width, canvas.height);
|
| 222 |
+
bufferToTensorOptions.height = canvas.height;
|
| 223 |
+
bufferToTensorOptions.width = canvas.width;
|
| 224 |
+
resolve(bufferToTensor(img.data, bufferToTensorOptions));
|
| 225 |
+
};
|
| 226 |
+
});
|
| 227 |
+
}
|
| 228 |
+
else {
|
| 229 |
+
throw new Error('Input data provided is not supported - aborted tensor creation');
|
| 230 |
+
}
|
| 231 |
+
if (data !== undefined) {
|
| 232 |
+
return bufferToTensor(data, bufferToTensorOptions);
|
| 233 |
+
}
|
| 234 |
+
else {
|
| 235 |
+
throw new Error('Input data provided is not supported - aborted tensor creation');
|
| 236 |
+
}
|
| 237 |
+
};
|
| 238 |
+
/**
|
| 239 |
+
* implementation of Tensor.fromTexture().
|
| 240 |
+
*/
|
| 241 |
+
export const tensorFromTexture = (texture, options) => {
|
| 242 |
+
const { width, height, download, dispose } = options;
|
| 243 |
+
// Always assume RGBAF32. TODO: support different texture format
|
| 244 |
+
const dims = [1, height, width, 4];
|
| 245 |
+
return new Tensor({ location: 'texture', type: 'float32', texture, dims, download, dispose });
|
| 246 |
+
};
|
| 247 |
+
/**
|
| 248 |
+
* implementation of Tensor.fromGpuBuffer().
|
| 249 |
+
*/
|
| 250 |
+
export const tensorFromGpuBuffer = (gpuBuffer, options) => {
|
| 251 |
+
const { dataType, dims, download, dispose } = options;
|
| 252 |
+
return new Tensor({ location: 'gpu-buffer', type: dataType ?? 'float32', gpuBuffer, dims, download, dispose });
|
| 253 |
+
};
|
| 254 |
+
/**
|
| 255 |
+
* implementation of Tensor.fromMLTensor().
|
| 256 |
+
*/
|
| 257 |
+
export const tensorFromMLTensor = (mlTensor, options) => {
|
| 258 |
+
const { dataType, dims, download, dispose } = options;
|
| 259 |
+
return new Tensor({ location: 'ml-tensor', type: dataType ?? 'float32', mlTensor, dims, download, dispose });
|
| 260 |
+
};
|
| 261 |
+
/**
|
| 262 |
+
* implementation of Tensor.fromPinnedBuffer().
|
| 263 |
+
*/
|
| 264 |
+
export const tensorFromPinnedBuffer = (type, buffer, dims) => new Tensor({ location: 'cpu-pinned', type, data: buffer, dims: dims ?? [buffer.length] });
|
| 265 |
+
//# sourceMappingURL=tensor-factory-impl.js.map
|
runtime/vendor/onnxruntime-common/tensor-factory.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
export {};
|
| 4 |
+
//# sourceMappingURL=tensor-factory.js.map
|
runtime/vendor/onnxruntime-common/tensor-impl-type-mapping.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
// a runtime map that maps type string to TypedArray constructor. Should match Tensor.DataTypeMap.
|
| 4 |
+
export const NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = new Map([
|
| 5 |
+
['float32', Float32Array],
|
| 6 |
+
['uint8', Uint8Array],
|
| 7 |
+
['int8', Int8Array],
|
| 8 |
+
['uint16', Uint16Array],
|
| 9 |
+
['int16', Int16Array],
|
| 10 |
+
['int32', Int32Array],
|
| 11 |
+
['bool', Uint8Array],
|
| 12 |
+
['float64', Float64Array],
|
| 13 |
+
['uint32', Uint32Array],
|
| 14 |
+
['int4', Uint8Array],
|
| 15 |
+
['uint4', Uint8Array],
|
| 16 |
+
]);
|
| 17 |
+
// a runtime map that maps type string to TypedArray constructor. Should match Tensor.DataTypeMap.
|
| 18 |
+
export const NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = new Map([
|
| 19 |
+
[Float32Array, 'float32'],
|
| 20 |
+
[Uint8Array, 'uint8'],
|
| 21 |
+
[Int8Array, 'int8'],
|
| 22 |
+
[Uint16Array, 'uint16'],
|
| 23 |
+
[Int16Array, 'int16'],
|
| 24 |
+
[Int32Array, 'int32'],
|
| 25 |
+
[Float64Array, 'float64'],
|
| 26 |
+
[Uint32Array, 'uint32'],
|
| 27 |
+
]);
|
| 28 |
+
// the following code allows delaying execution of BigInt/Float16Array checking. This allows lazy initialization for
|
| 29 |
+
// NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP and NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP, which allows BigInt/Float16Array
|
| 30 |
+
// polyfill if available.
|
| 31 |
+
let isTypedArrayChecked = false;
|
| 32 |
+
export const checkTypedArray = () => {
|
| 33 |
+
if (!isTypedArrayChecked) {
|
| 34 |
+
isTypedArrayChecked = true;
|
| 35 |
+
const isBigInt64ArrayAvailable = typeof BigInt64Array !== 'undefined' && BigInt64Array.from;
|
| 36 |
+
const isBigUint64ArrayAvailable = typeof BigUint64Array !== 'undefined' && BigUint64Array.from;
|
| 37 |
+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any
|
| 38 |
+
const Float16Array = globalThis.Float16Array;
|
| 39 |
+
const isFloat16ArrayAvailable = typeof Float16Array !== 'undefined' && Float16Array.from;
|
| 40 |
+
if (isBigInt64ArrayAvailable) {
|
| 41 |
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set('int64', BigInt64Array);
|
| 42 |
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, 'int64');
|
| 43 |
+
}
|
| 44 |
+
if (isBigUint64ArrayAvailable) {
|
| 45 |
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set('uint64', BigUint64Array);
|
| 46 |
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, 'uint64');
|
| 47 |
+
}
|
| 48 |
+
if (isFloat16ArrayAvailable) {
|
| 49 |
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set('float16', Float16Array);
|
| 50 |
+
NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array, 'float16');
|
| 51 |
+
}
|
| 52 |
+
else {
|
| 53 |
+
// if Float16Array is not available, use 'Uint16Array' to store the data.
|
| 54 |
+
NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set('float16', Uint16Array);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
};
|
| 58 |
+
//# sourceMappingURL=tensor-impl-type-mapping.js.map
|
runtime/vendor/onnxruntime-common/tensor-impl.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
| 2 |
+
// Licensed under the MIT License.
|
| 3 |
+
import { tensorToDataURL, tensorToImageData } from './tensor-conversion-impl.js';
|
| 4 |
+
import { tensorFromGpuBuffer, tensorFromImage, tensorFromMLTensor, tensorFromPinnedBuffer, tensorFromTexture, } from './tensor-factory-impl.js';
|
| 5 |
+
import { checkTypedArray, NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP, NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP, } from './tensor-impl-type-mapping.js';
|
| 6 |
+
import { calculateSize, tensorReshape } from './tensor-utils-impl.js';
|
| 7 |
+
/**
|
| 8 |
+
* the implementation of Tensor interface.
|
| 9 |
+
*
|
| 10 |
+
* @ignore
|
| 11 |
+
*/
|
| 12 |
+
export class Tensor {
|
| 13 |
+
/**
|
| 14 |
+
* implementation.
|
| 15 |
+
*/
|
| 16 |
+
constructor(arg0, arg1, arg2) {
|
| 17 |
+
// perform one-time check for BigInt/Float16Array support
|
| 18 |
+
checkTypedArray();
|
| 19 |
+
let type;
|
| 20 |
+
let dims;
|
| 21 |
+
if (typeof arg0 === 'object' && 'location' in arg0) {
|
| 22 |
+
//
|
| 23 |
+
// constructing tensor from specific location
|
| 24 |
+
//
|
| 25 |
+
this.dataLocation = arg0.location;
|
| 26 |
+
type = arg0.type;
|
| 27 |
+
dims = arg0.dims;
|
| 28 |
+
switch (arg0.location) {
|
| 29 |
+
case 'cpu-pinned': {
|
| 30 |
+
const expectedTypedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
|
| 31 |
+
if (!expectedTypedArrayConstructor) {
|
| 32 |
+
throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
|
| 33 |
+
}
|
| 34 |
+
if (!(arg0.data instanceof expectedTypedArrayConstructor)) {
|
| 35 |
+
throw new TypeError(`buffer should be of type ${expectedTypedArrayConstructor.name}`);
|
| 36 |
+
}
|
| 37 |
+
this.cpuData = arg0.data;
|
| 38 |
+
break;
|
| 39 |
+
}
|
| 40 |
+
case 'texture': {
|
| 41 |
+
if (type !== 'float32') {
|
| 42 |
+
throw new TypeError(`unsupported type "${type}" to create tensor from texture`);
|
| 43 |
+
}
|
| 44 |
+
this.gpuTextureData = arg0.texture;
|
| 45 |
+
this.downloader = arg0.download;
|
| 46 |
+
this.disposer = arg0.dispose;
|
| 47 |
+
break;
|
| 48 |
+
}
|
| 49 |
+
case 'gpu-buffer': {
|
| 50 |
+
if (type !== 'float32' &&
|
| 51 |
+
type !== 'float16' &&
|
| 52 |
+
type !== 'int32' &&
|
| 53 |
+
type !== 'int64' &&
|
| 54 |
+
type !== 'uint32' &&
|
| 55 |
+
type !== 'uint8' &&
|
| 56 |
+
type !== 'bool' &&
|
| 57 |
+
type !== 'uint4' &&
|
| 58 |
+
type !== 'int4') {
|
| 59 |
+
throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
|
| 60 |
+
}
|
| 61 |
+
this.gpuBufferData = arg0.gpuBuffer;
|
| 62 |
+
this.downloader = arg0.download;
|
| 63 |
+
this.disposer = arg0.dispose;
|
| 64 |
+
break;
|
| 65 |
+
}
|
| 66 |
+
case 'ml-tensor': {
|
| 67 |
+
if (type !== 'float32' &&
|
| 68 |
+
type !== 'float16' &&
|
| 69 |
+
type !== 'int32' &&
|
| 70 |
+
type !== 'int64' &&
|
| 71 |
+
type !== 'uint32' &&
|
| 72 |
+
type !== 'uint64' &&
|
| 73 |
+
type !== 'int8' &&
|
| 74 |
+
type !== 'uint8' &&
|
| 75 |
+
type !== 'bool' &&
|
| 76 |
+
type !== 'uint4' &&
|
| 77 |
+
type !== 'int4') {
|
| 78 |
+
throw new TypeError(`unsupported type "${type}" to create tensor from MLTensor`);
|
| 79 |
+
}
|
| 80 |
+
this.mlTensorData = arg0.mlTensor;
|
| 81 |
+
this.downloader = arg0.download;
|
| 82 |
+
this.disposer = arg0.dispose;
|
| 83 |
+
break;
|
| 84 |
+
}
|
| 85 |
+
default:
|
| 86 |
+
throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
else {
|
| 90 |
+
//
|
| 91 |
+
// constructing tensor of location 'cpu'
|
| 92 |
+
//
|
| 93 |
+
let data;
|
| 94 |
+
let maybeDims;
|
| 95 |
+
// check whether arg0 is type or data
|
| 96 |
+
if (typeof arg0 === 'string') {
|
| 97 |
+
//
|
| 98 |
+
// Override: constructor(type, data, ...)
|
| 99 |
+
//
|
| 100 |
+
type = arg0;
|
| 101 |
+
maybeDims = arg2;
|
| 102 |
+
if (arg0 === 'string') {
|
| 103 |
+
// string tensor
|
| 104 |
+
if (!Array.isArray(arg1)) {
|
| 105 |
+
throw new TypeError("A string tensor's data must be a string array.");
|
| 106 |
+
}
|
| 107 |
+
// we don't check whether every element in the array is string; this is too slow. we assume it's correct and
|
| 108 |
+
// error will be populated at inference
|
| 109 |
+
data = arg1;
|
| 110 |
+
}
|
| 111 |
+
else {
|
| 112 |
+
// numeric tensor
|
| 113 |
+
const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
|
| 114 |
+
if (typedArrayConstructor === undefined) {
|
| 115 |
+
throw new TypeError(`Unsupported tensor type: ${arg0}.`);
|
| 116 |
+
}
|
| 117 |
+
if (Array.isArray(arg1)) {
|
| 118 |
+
if ((arg0 === 'float16' && typedArrayConstructor === Uint16Array) || arg0 === 'uint4' || arg0 === 'int4') {
|
| 119 |
+
// - 'float16':
|
| 120 |
+
// When no Float16Array polyfill is used, we cannot create 'float16' tensor from number array.
|
| 121 |
+
//
|
| 122 |
+
// Throw error here because when user try to use number array as data,
|
| 123 |
+
// e.g. new Tensor('float16', [1, 2, 3, 4], dims)), it will actually call
|
| 124 |
+
// Uint16Array.from(arg1) which generates wrong data.
|
| 125 |
+
//
|
| 126 |
+
// - 'uint4' and 'int4':
|
| 127 |
+
// Uint8Array.from(arg1) will generate wrong data for 'uint4' and 'int4' tensor.
|
| 128 |
+
//
|
| 129 |
+
throw new TypeError(`Creating a ${arg0} tensor from number array is not supported. Please use ${typedArrayConstructor.name} as data.`);
|
| 130 |
+
}
|
| 131 |
+
else if (arg0 === 'uint64' || arg0 === 'int64') {
|
| 132 |
+
// use 'as any' here because:
|
| 133 |
+
// 1. TypeScript's check on type of 'Array.isArray()' does not work with readonly arrays.
|
| 134 |
+
// see https://github.com/microsoft/TypeScript/issues/17002
|
| 135 |
+
// 2. TypeScript's check on union type of '(BigInt64ArrayConstructor|BigUint64ArrayConstructor).from()'
|
| 136 |
+
// does not accept parameter mapFn.
|
| 137 |
+
// 3. parameters of 'SupportedTypedArrayConstructors.from()' does not match the requirement of the union
|
| 138 |
+
// type.
|
| 139 |
+
// assume 'arg1' is of type "readonly number[]|readonly bigint[]" here.
|
| 140 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 141 |
+
data = typedArrayConstructor.from(arg1, BigInt);
|
| 142 |
+
}
|
| 143 |
+
else {
|
| 144 |
+
// assume 'arg1' is of type "readonly number[]" here.
|
| 145 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 146 |
+
data = typedArrayConstructor.from(arg1);
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
else if (arg1 instanceof typedArrayConstructor) {
|
| 150 |
+
data = arg1;
|
| 151 |
+
}
|
| 152 |
+
else if (arg1 instanceof Uint8ClampedArray) {
|
| 153 |
+
if (arg0 === 'uint8') {
|
| 154 |
+
data = Uint8Array.from(arg1);
|
| 155 |
+
}
|
| 156 |
+
else {
|
| 157 |
+
throw new TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
else if (arg0 === 'float16' && arg1 instanceof Uint16Array && typedArrayConstructor !== Uint16Array) {
|
| 161 |
+
// when Float16Array is available and data is of type Uint16Array.
|
| 162 |
+
// We allow Uint16Array to be passed in as data for 'float16' tensor until Float16Array is generally
|
| 163 |
+
// supported in JavaScript environment.
|
| 164 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 165 |
+
data = new globalThis.Float16Array(arg1.buffer, arg1.byteOffset, arg1.length);
|
| 166 |
+
}
|
| 167 |
+
else {
|
| 168 |
+
throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
else {
|
| 173 |
+
//
|
| 174 |
+
// Override: constructor(data, ...)
|
| 175 |
+
//
|
| 176 |
+
maybeDims = arg1;
|
| 177 |
+
if (Array.isArray(arg0)) {
|
| 178 |
+
// only boolean[] and string[] is supported
|
| 179 |
+
if (arg0.length === 0) {
|
| 180 |
+
throw new TypeError('Tensor type cannot be inferred from an empty array.');
|
| 181 |
+
}
|
| 182 |
+
const firstElementType = typeof arg0[0];
|
| 183 |
+
if (firstElementType === 'string') {
|
| 184 |
+
type = 'string';
|
| 185 |
+
data = arg0;
|
| 186 |
+
}
|
| 187 |
+
else if (firstElementType === 'boolean') {
|
| 188 |
+
type = 'bool';
|
| 189 |
+
// 'arg0' is of type 'boolean[]'. Uint8Array.from(boolean[]) actually works, but typescript thinks this is
|
| 190 |
+
// wrong type. We use 'as any' to make it happy.
|
| 191 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 192 |
+
data = Uint8Array.from(arg0);
|
| 193 |
+
}
|
| 194 |
+
else {
|
| 195 |
+
throw new TypeError(`Invalid element type of data array: ${firstElementType}.`);
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
else if (arg0 instanceof Uint8ClampedArray) {
|
| 199 |
+
type = 'uint8';
|
| 200 |
+
data = Uint8Array.from(arg0);
|
| 201 |
+
}
|
| 202 |
+
else {
|
| 203 |
+
// get tensor type from TypedArray
|
| 204 |
+
const mappedType = NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
|
| 205 |
+
if (mappedType === undefined) {
|
| 206 |
+
throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
|
| 207 |
+
}
|
| 208 |
+
type = mappedType;
|
| 209 |
+
data = arg0;
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
// type and data is processed, now processing dims
|
| 213 |
+
if (maybeDims === undefined) {
|
| 214 |
+
// assume 1-D tensor if dims omitted
|
| 215 |
+
maybeDims = [data.length];
|
| 216 |
+
}
|
| 217 |
+
else if (!Array.isArray(maybeDims)) {
|
| 218 |
+
throw new TypeError("A tensor's dims must be a number array");
|
| 219 |
+
}
|
| 220 |
+
dims = maybeDims;
|
| 221 |
+
this.cpuData = data;
|
| 222 |
+
this.dataLocation = 'cpu';
|
| 223 |
+
}
|
| 224 |
+
// perform check on dims
|
| 225 |
+
const size = calculateSize(dims);
|
| 226 |
+
// if data is on CPU, check whether data length matches tensor size
|
| 227 |
+
if (this.cpuData && size !== this.cpuData.length) {
|
| 228 |
+
if ((type === 'uint4' || type === 'int4') && Math.ceil(size / 2) === this.cpuData.length) {
|
| 229 |
+
// for (u)int4, the data length is half of the tensor size. So we check this special case when size is odd.
|
| 230 |
+
}
|
| 231 |
+
else {
|
| 232 |
+
throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
this.type = type;
|
| 236 |
+
this.dims = dims;
|
| 237 |
+
this.size = size;
|
| 238 |
+
}
|
| 239 |
+
// #endregion
|
| 240 |
+
// #region factory
|
| 241 |
+
static async fromImage(image, options) {
|
| 242 |
+
return tensorFromImage(image, options);
|
| 243 |
+
}
|
| 244 |
+
static fromTexture(texture, options) {
|
| 245 |
+
return tensorFromTexture(texture, options);
|
| 246 |
+
}
|
| 247 |
+
static fromGpuBuffer(gpuBuffer, options) {
|
| 248 |
+
return tensorFromGpuBuffer(gpuBuffer, options);
|
| 249 |
+
}
|
| 250 |
+
static fromMLTensor(mlTensor, options) {
|
| 251 |
+
return tensorFromMLTensor(mlTensor, options);
|
| 252 |
+
}
|
| 253 |
+
static fromPinnedBuffer(type, buffer, dims) {
|
| 254 |
+
return tensorFromPinnedBuffer(type, buffer, dims);
|
| 255 |
+
}
|
| 256 |
+
// #endregion
|
| 257 |
+
// #region conversions
|
| 258 |
+
toDataURL(options) {
|
| 259 |
+
return tensorToDataURL(this, options);
|
| 260 |
+
}
|
| 261 |
+
toImageData(options) {
|
| 262 |
+
return tensorToImageData(this, options);
|
| 263 |
+
}
|
| 264 |
+
// #endregion
|
| 265 |
+
// #region properties
|
| 266 |
+
get data() {
|
| 267 |
+
this.ensureValid();
|
| 268 |
+
if (!this.cpuData) {
|
| 269 |
+
throw new Error('The data is not on CPU. Use `getData()` to download GPU data to CPU, ' +
|
| 270 |
+
'or use `texture` or `gpuBuffer` property to access the GPU data directly.');
|
| 271 |
+
}
|
| 272 |
+
return this.cpuData;
|
| 273 |
+
}
|
| 274 |
+
get location() {
|
| 275 |
+
return this.dataLocation;
|
| 276 |
+
}
|
| 277 |
+
get texture() {
|
| 278 |
+
this.ensureValid();
|
| 279 |
+
if (!this.gpuTextureData) {
|
| 280 |
+
throw new Error('The data is not stored as a WebGL texture.');
|
| 281 |
+
}
|
| 282 |
+
return this.gpuTextureData;
|
| 283 |
+
}
|
| 284 |
+
get gpuBuffer() {
|
| 285 |
+
this.ensureValid();
|
| 286 |
+
if (!this.gpuBufferData) {
|
| 287 |
+
throw new Error('The data is not stored as a WebGPU buffer.');
|
| 288 |
+
}
|
| 289 |
+
return this.gpuBufferData;
|
| 290 |
+
}
|
| 291 |
+
get mlTensor() {
|
| 292 |
+
this.ensureValid();
|
| 293 |
+
if (!this.mlTensorData) {
|
| 294 |
+
throw new Error('The data is not stored as a WebNN MLTensor.');
|
| 295 |
+
}
|
| 296 |
+
return this.mlTensorData;
|
| 297 |
+
}
|
| 298 |
+
// #endregion
|
| 299 |
+
// #region methods
|
| 300 |
+
async getData(releaseData) {
|
| 301 |
+
this.ensureValid();
|
| 302 |
+
switch (this.dataLocation) {
|
| 303 |
+
case 'cpu':
|
| 304 |
+
case 'cpu-pinned':
|
| 305 |
+
return this.data;
|
| 306 |
+
case 'texture':
|
| 307 |
+
case 'gpu-buffer':
|
| 308 |
+
case 'ml-tensor': {
|
| 309 |
+
if (!this.downloader) {
|
| 310 |
+
throw new Error('The current tensor is not created with a specified data downloader.');
|
| 311 |
+
}
|
| 312 |
+
if (this.isDownloading) {
|
| 313 |
+
throw new Error('The current tensor is being downloaded.');
|
| 314 |
+
}
|
| 315 |
+
try {
|
| 316 |
+
this.isDownloading = true;
|
| 317 |
+
const data = await this.downloader();
|
| 318 |
+
this.downloader = undefined;
|
| 319 |
+
this.dataLocation = 'cpu';
|
| 320 |
+
this.cpuData = data;
|
| 321 |
+
if (releaseData && this.disposer) {
|
| 322 |
+
this.disposer();
|
| 323 |
+
this.disposer = undefined;
|
| 324 |
+
}
|
| 325 |
+
return data;
|
| 326 |
+
}
|
| 327 |
+
finally {
|
| 328 |
+
this.isDownloading = false;
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
default:
|
| 332 |
+
throw new Error(`cannot get data from location: ${this.dataLocation}`);
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
dispose() {
|
| 336 |
+
if (this.isDownloading) {
|
| 337 |
+
throw new Error('The current tensor is being downloaded.');
|
| 338 |
+
}
|
| 339 |
+
if (this.disposer) {
|
| 340 |
+
this.disposer();
|
| 341 |
+
this.disposer = undefined;
|
| 342 |
+
}
|
| 343 |
+
this.cpuData = undefined;
|
| 344 |
+
this.gpuTextureData = undefined;
|
| 345 |
+
this.gpuBufferData = undefined;
|
| 346 |
+
this.mlTensorData = undefined;
|
| 347 |
+
this.downloader = undefined;
|
| 348 |
+
this.isDownloading = undefined;
|
| 349 |
+
this.dataLocation = 'none';
|
| 350 |
+
}
|
| 351 |
+
// #endregion
|
| 352 |
+
// #region tensor utilities
|
| 353 |
+
ensureValid() {
|
| 354 |
+
if (this.dataLocation === 'none') {
|
| 355 |
+
throw new Error('The tensor is disposed.');
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
reshape(dims) {
|
| 359 |
+
this.ensureValid();
|
| 360 |
+
if (this.downloader || this.disposer) {
|
| 361 |
+
throw new Error('Cannot reshape a tensor that owns GPU resource.');
|
| 362 |
+
}
|
| 363 |
+
return tensorReshape(this, dims);
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
//# sourceMappingURL=tensor-impl.js.map
|