Before loading a weight file

A downloaded model file contains a description of its tensors as well as the numbers themselves. Safetensors keeps that description in a JSON header: names, shapes, numeric types and byte ranges. A truncated file or overlapping ranges can be noticed before allocating memory to load the weights.

I built Tensor Header Desk to make those declarations inspectable in a browser. Choose a local file, check its declared layout and download the complete report. The browser reads only the length prefix and a bounded header; it uses the file size without reading tensor values. The file is not uploaded. A report can still reveal private tensor names and metadata if you choose to share it.

The most useful example is the one this tool cannot distinguish. I serialized the existing Character Router weights, then flipped one bit at the end of the tensor payload. Both files pass the layout checks and have the same header digest. Their full contents differ. A passing result means these implemented layout checks passed; it does not certify the weights, authenticity or safety of loading the file.

The examples also show truncation, overlapping ranges, an unknown numeric type and malformed JSON. An unknown type or a file beyond the tool's limits is labelled outside-profile, rather than evidence of corruption. The frozen 320-file corpus and pinned safetensors 0.8.0 comparison retain all three pass/reject differences. The original technical record follows, including its historical local-candidate status; hosted checks are recorded separately after deployment. This release uses the already accepted November 5 package, with no new training.

加载权重前,先看文件怎样描述自己

下载一个模型后,文件里既有权重数值,也有描述这些数值的信息。Safetensors 把张量名称、形状、数值类型和字节位置放在 JSON 头部里。文件被截断、两段数据的位置互相重叠,有些问题可以在真正加载权重前发现。

我做 Tensor Header Desk,是想把这些声明摊开来看。选一个本地文件,浏览器会读取长度前缀和限制范围内的头部,再对照整个文件的大小检查布局。它不读取权重数值,也不上传文件。筛选表格只改变显示,下载报告仍保留完整的支持范围内记录;报告里的张量名称和元数据可能有隐私,分享前需要自己检查。

其中一个例子很直接:我把已有 Character Router 的权重存成文件,再翻转数据区最后一位。两个文件都通过布局检查,头部摘要也相同,但完整文件内容已经不同。这个反例说明,通过头部检查只能确认这里实现的布局检查通过,不能证明权重内容正确、来源可信或加载安全。原模型的域外拒答失败也没有因此改变。

另外几个例子展示截断、重叠、未知数值类型和损坏的 JSON。超过检查上限或类型尚不支持时,工具会写明 outside-profile,不会把能力边界说成文件损坏。原有 320 个文件的完整检查和固定 safetensors 0.8.0 对照保留了全部三处通过/拒绝差异。下面保留原技术说明;其中本地候选的措辞是当时记录,正式托管验收另行登记。本次发布的是 11 月 5 日已经验收的库存,没有新增训练。

Tensor Header Desk

A local browser tool for inspecting a Safetensors file before loading tensors. It reads the eight-byte length prefix and a supported-size JSON header, then compares declared shapes and byte ranges with the complete file size. Tensor values are never read by the inspector.

Open the page, choose a file, and read the findings. The report includes exact decimal byte positions, every supported descriptor, the original UTF-8 header, metadata, diagnostics and a SHA-256 of the prefix and header. Filtering or paging the table does not remove records from the downloaded report. Selected files stay in the browser: no upload, remote inference, account, storage or analytics is used.

What it checks

The table retains malformed descriptors when JSON parsing succeeds and the tensor-count limit permits inspection. Exact original spelling, value types, key order and whitespace are retained in header_json_utf8. Descriptor summaries encode JSON number lexemes as strings to preserve precision. Reports deliberately use decimal strings for sizes and offsets.

Four outcomes

Outcome Meaning
layout-ok The implemented header, size and coverage checks passed.
invalid A concrete UTF-8, schema, arithmetic, size or coverage check failed.
policy-rejected Duplicate decoded keys or noncanonical unsigned integer spellings were rejected by this tool.
outside-profile Header above 1,048,576 bytes, more than 10,000 tensors, nesting above 32, or an unknown dtype. No corruption claim follows from a tool limit.

An invalid finding takes precedence over policy or unsupported findings. JSON parsing failures can prevent descriptor enumeration; a report then says the declared count is unknown. At the tensor-count limit the report retains the complete supported-size header and the declared count, but does not construct descriptor summaries.

A useful failure example

The default file contains my existing CPU Character Router’s weights and bias, serialized as F64. All 12,291 scalars were independently reloaded and checked exactly against the copied original JSON model. This is the earlier work:char-router-abstention-study:v1, not a new fit. Its original failed OOD abstention result is unchanged and this tool does not run it. Provenance, original source model, original manifest and original notice are included.

The altered-data example flips the final payload bit. It has different complete file bytes but the same header, header digest and passing layout result. This is an intentional blind spot. A header-only digest cannot validate complete file integrity, authenticity, correct weights, licensing, model quality or downstream code. Use a trusted independently obtained whole-file digest when comparing complete bytes; even that does not establish those other properties. NaN and infinity tensor values can also pass these checks.

Metadata and tensor names may contain private information. They are rendered as plain text and included in an explicitly downloaded report. Clear removes the file selection and visible report; it is not a secure memory-erasure guarantee.

Run locally

No build step or runtime dependency is needed beyond a modern browser. Serve this directory over localhost so browser Web Crypto is available:

python3 -m http.server 8000 --bind 127.0.0.1

Open http://127.0.0.1:8000/. The six included examples cover original weights, one payload bit flip, truncation, overlap, an unknown dtype and malformed JSON. File extension is a chooser hint, not validation. The application has no full-file hashing or tensor-loading action.

The README includes Static Space configuration according to HF’s current static SDK documentation. This is a locally verified candidate. Public HF deployment, hosted asset loading and anonymous hosted usability require separate verification after publication; there is no published URL or cloud-execution claim in this package.

Hosted included-example transport

The first hosted revision loaded the application, but its binary included-example requests redirected to a CDN that the observed Edge browser blocked (ERR_BLOCKED_BY_CLIENT). The original files remain unchanged. The six included examples now have same-origin JSON/base64 carriers under fixtures-web/. The loader reconstructs their exact original bytes before calling the unchanged inspector; this is transport adaptation, not a new model or a change to layout rules.

The loader allows only the six named examples, refuses redirects, limits each decoded response body to 140,000 bytes and each request to 15 seconds, and checks schema, original filename, encoding, exact byte length and a fixed SHA-256. Carrier hashes check consistency against this saved package, not independent authenticity or loading safety. Invalid carriers or network errors remove the old report and show an error. No CDN fallback, browser permission change or protection disablement is used.

Included examples are intentionally loaded in full from public carrier files, then inspected with the same bounded prefix/header reader. A user-selected local file still follows the original File/Blob path: only its prefix and supported-size header are read, and it is never uploaded. The unchanged payload-bitflip example still passes layout checks with the same header digest as the original. The original binary fixtures and all original scientific results are retained for reproduction.

The hosting adaptation has local Node HTTP and controlled-DOM tests. These do not establish hosted browser success or completed native downloads; the original HF operator must independently verify the exact updated package and actual hosted behavior before calling the release complete.

Reproduce the checks

Run tests on a writable copy of the package, preserving the frozen original:

python3 -m venv .venv
.venv/bin/python -m pip install -r requirements-test.txt
node test_core.mjs
node test_example_loader.mjs
.venv/bin/python verify_reference.py
node test_ui_races.mjs
.venv/bin/python verify_native.py

Python 3.14.7, NumPy 2.5.4, safetensors 0.8.0 and Node 24.19.0 were used for author verification. Python and safetensors are test dependencies, not part of the browser app. verify_native.py validates the supplied 20 actual browser downloads; reviewers should additionally generate fresh native uploads/downloads rather than treating a replay as new UI evidence. The five controlled async race scenarios are Node tests and are explicitly not native browser evidence.

Core results retain all 320 synthetic/serialization fixtures: 283 layout-ok, 27 invalid, six policy rejections and four outside-profile outcomes. The corpus includes 240 deterministic randomized small layouts and one aligned fixture for each dtype. The official 0.8.0 reader accepts 286 fixtures. Three pass/reject differences are retained:

  1. It accepts the duplicate-tensor-name fixture by overwriting a repeated name; this tool rejects decoded duplicate keys according to policy. Other duplicate cases are retained even when both readers reject them.
  2. It accepts a valid header just over this tool’s 1 MiB cap.
  3. It accepts 10,001 empty tensors, beyond this tool’s descriptor cap.

The last two are explicitly outside-profile results here. Unknown dtype and excessive nesting have separate unsupported labels even when both readers decline the fixture. Current Rust and the installed 0.8.0 reader accept leading JSON whitespace, although the README format section says the header starts with {; the tool accepts it with a compatibility warning. Metadata null is accepted by the pinned reference and by this tool. Agreement on a finite corpus is not proof of complete format equivalence or adversarial robustness.

verify_reference.py does not import the inspector or fixture generator. It replays the official metadata reader, checks every fixture’s bytes/hash and source model scalars, and verifies the payload-bitflip counterexample. test_core.mjs instruments every Blob slice: at most the prefix and declared supported-size header are read. Unsafe integers, prototype-named tensors, escaped duplicate keys, surrogate failures, zero/scalar cases and sequential overflow are retained.

To regenerate fixture source material into a new directory, use the bundled original model:

.venv/bin/python make_fixtures.py demo fresh-fixtures

This does no training. Official serializer metadata-map ordering can change the three router-derived file headers and their complete hashes. The frozen corpus is never overwritten by that command. Fresh regeneration results record all 320 expected labels and official-reader outcomes matching, with only those three serialization hashes changing. Compare reloaded values and classified outcomes, not accidental metadata order.

Product evidence and limits

The validation record separates native UI operations from Node simulations. Twenty actual native reports contain 293 descriptor rows, including the complete 137-row inventory after a seven-row filter. Native pagination shows 50/50/37 rows. Header-size and tensor-count limits, malformed replacement, Clear, metadata-as-text, unsafe integer preservation and mobile keyboard scrolling were exercised. Desktop preview and mobile preview are actual local browser captures.

This is a bounded educational/developer inspector. It does not inspect shard-index JSON, find missing shards, repair files, validate checkpoint architecture/config/tokenizers, decode quantization, compare tensor contents, detect every malicious input or certify a loader’s safety. Runtime/format changes may introduce unsupported types. Large valid files can be declined by the profile. Public deployment and adoption are not inferred from local tests.

Sources and license

Original code, synthetic fixtures, model serialization and reports © 2026 Renchao Wu, Apache-2.0. The copied original Char Router model/notice/manifest have the same author and license. No employer, private or third-party training data was used.

The Safetensors format and reference implementation belong to their original authors. The official repository README and Rust reader were read through the native browser on 2026-11-05. main is moving evidence; the differential reference is pinned to installed safetensors 0.8.0. No upstream implementation or prose is copied into this tool. Dependency terms remain their own; see dependencies and implementation contract.