Skip to content

feat(hslm): [B] Trit Token Encoding — 729 tokens → 6 balanced trits #331

Description

@gHashTag

Parent: #329 — Fully Ternary Transformer

Level 0 (no dependencies) | ~100 LOC | New: src/hslm/trit_encoding.zig

Description

Encode tokens as balanced trits instead of dense embeddings. 729 = 3⁶ tokens → 6 balanced trits per token. TritEmbedding: 6×243 = 1,458 params vs 177K = 121x compression.

Implementation

  • tokenToTrits(token: u32) → [6]i2 — base-3 decomposition into balanced {-1, 0, +1}
  • tritsToToken(trits: [6]i2) → u32 — inverse
  • TritEmbedding struct: 6 sub-embeddings of size 243 (3⁵), compose via bind
  • Forward: token → 6 trits → lookup 6 sub-tables → bind together → output vector

tri CLI

tri hslm trit-encode

Tests

  • Roundtrip all 729 tokens: tritsToToken(tokenToTrits(t)) == t
  • Unique vectors: all 729 embeddings distinct
  • Gradient flows through embedding lookup

Blocks

  • Issue D (Ternary Activations)
  • Issue J (Full Ternary Inference)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions