feat: Ternary-everywhere refactor + STE shadow weight infrastructure#59
Merged
feat: Ternary-everywhere refactor + STE shadow weight infrastructure#59
Conversation
CpuLinear now quantizes to ternary on creation via from_weight(). CpuMoELayer stores TernaryExpert for all expert weights. TernaryLinear::from_cpu_linear() uses raw ternary (no FP32 round-trip). TernaryMoELayer::from_cpu_moe() copies ternary values directly. Backward pass dequantizes via to_fp32() where needed. Memory: 2-expert MoE ~2.1 GB ternary vs ~17 GB FP32. [3da81652]
ShadowPrecision trait: switchable BF16/FP32 for shadow weights. BitLinear<P>: ternary base + optional shadow, STE forward path, stochastic rounding, boundary noise injection, running average α. BitMoELayer: per-block synchronized α across experts + PLE projections, ScaleSync enum for PerBlock vs PerExpert modes. Added half crate with num-traits/serde/bytemuck features. 20 new tests (13 shadow_weights + 7 bit_moe), all passing. [3da81652]
3 research papers + renderdoc added to flake for GPU kernel debugging. STE viability: shadow weight memory constraint (BF16 saves 50%). Quality ceiling: rank sweep needed to determine if LoRA can close gap. Expert count: 4 big vs 128 small experts with same param budget. [3da81652]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ternary-Everywhere Refactor + STE Infrastructure
Summary
Two major changes in this PR:
1. Ternary-everywhere refactor (all base weights as {-1, 0, +1})
CpuLinear::from_weight()immediately quantizes FP32 → ternaryCpuMoELayerstoresTernaryExpertfor all expert gate/up/down projectionsTernaryLinear::from_cpu_linear()uses raw ternary values (no FP32 round-trip)TernaryMoELayer::from_cpu_moe()copies ternary directly.to_fp32()where needed2. STE shadow weight infrastructure (BF16-ready)
ShadowPrecisiontrait: switchable BF16/FP32 for shadow weightsBitLinear<P>: ternary base + optional shadow, STE forward, stochastic rounding, boundary noise injection, running average αBitMoELayer: per-block synchronized α across experts + PLE projections,ScaleSyncenum (PerBlock vs PerExpert)halfcrate with num-traits/serde/bytemuck featuresshadow_weights+ 7bit_moe)3. Research papers
ste_ternary_training.md— STE viability analysis, shadow weight memory constraintsternary_quality_ceiling.md— rank sweep experiment design, LoRA vs STE ceilingexpert_count_tradeoff.md— 4 big vs 128 small experts tradeoff analysisTest Results
--features vulkanhalfcrate)Architecture Decisions
Memory Impact
Next Steps (post-merge)
[3da81652]