Skip to content

support storage-only FP16 tensors - #1398

Open
zhangzhenghao wants to merge 9 commits into
gorse-io:masterfrom
zhangzhenghao:feat/tensor-fp16-storage
Open

zhangzhenghao wants to merge 9 commits into
gorse-io:masterfrom
zhangzhenghao:feat/tensor-fp16-storage

Conversation

@zhangzhenghao

@zhangzhenghao zhangzhenghao commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add storage-only IEEE binary16 tensors with explicit DType, generic NewTensor[T float32 | uint16], raw Uint16s() / Floats() backing-storage accessors, and independent graph-free ToFloat16 / ToFloat32 conversions.
  • Preserve dtype and raw bits through slicing, indexed slicing, cloning, reads, and formatting.
  • Serialize both dtypes through shared protobuf bytes data = 3, with element width selected by dtype. Tensor/protobuf payloads share backing storage through unsafe byte views; no dual writes or fallback decoder.
  • Keep FP32 operator dispatch, automatic differentiation, optimizers, and initialization unchanged. FP16 tensors must be explicitly converted to FP32 for computation in this PR. No new dtype preflight guards are introduced.
  • FP16 operator/autodiff support, SGD/Adam updates, and NormalInit are split into dependent computation PR support FP16 tensor computation through FP32 kernels #1423. That PR targets pr-1398-fp16-storage, a mirror of this PR's head, so its diff contains only computation changes. Retarget it to master after this PR merges.

Verification

Passed locally with system Go 1.27.3 (no scratch modfile or dependency changes):

  • go test ./common/nn ./protocol -count=1
  • go test -race ./common/nn ./protocol -count=1
  • go test -tags=noasm ./common/nn ./protocol -count=1
  • go test -gcflags=all=-d=checkptr=2 ./common/nn ./protocol -count=1
  • go vet -composites=false ./common/nn ./protocol
  • git diff --check

The split retains the original storage commits and subsequent accessor/conversion/serialization changes, while removing the computation commit entirely from this branch's history. The dependent computation tree is byte-for-byte identical to the previous combined PR head. Independent review found no split-induced omissions or blocking issues. GitHub Actions run 40984389040 passed all unit, integration, compatibility, playground, and lint jobs on this head. The separate Codecov project check failed: project coverage 78.17% (-0.93% versus base), patch coverage 91.38% with 5 missing/partial changed lines in tensor.go. This is a coverage check failure, not a test failure; no unrelated coverage changes were bundled into the split.

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.37931% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.17%. Comparing base (9424736) to head (a36f4b3).
⚠️ Report is 18 commits behind head on master.

Files with missing lines Patch % Lines
common/nn/tensor.go 91.07% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1398      +/-   ##
==========================================
- Coverage   79.09%   78.17%   -0.93%     
==========================================
  Files          92       90       -2     
  Lines       16459    16468       +9     
==========================================
- Hits        13019    12874     -145     
- Misses       3440     3593     +153     
- Partials        0        1       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zhenghaoz zhenghaoz changed the title feat(nn): support storage-only FP16 tensors feat(nn): support FP16 tensors Oct 5, 2026
@zhenghaoz zhenghaoz changed the title feat(nn): support FP16 tensors support FP16 tensors Oct 5, 2026
@zhangzhenghao
zhangzhenghao force-pushed the feat/tensor-fp16-storage branch from 5e39e1a to a36f4b3 Compare October 30, 2026 01:11
@zhangzhenghao zhangzhenghao changed the title support FP16 tensors support storage-only FP16 tensors Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants