Skip to content

feat(hslm): [C] Ternary Positional Encoding — multi-scale trit positions #332

Description

@gHashTag

Parent: #329 — Fully Ternary Transformer

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

Description

Replace sinusoidal/RoPE float PE with ternary positional encoding using 4 trit levels × 243 entries, multi-scale frequencies (1, 1/3, 1/9, 1/27).

Implementation

  • TernaryPE struct: 4 frequency scales, each 243 entries
  • positionToTrits4(pos: u32) → [4][dim]i2 — 4 trit vectors at different frequencies
  • Multi-scale composition: bind(scale1, scale2, scale3, scale4)
  • Precomputed tables for fast lookup

tri CLI

tri hslm trit-pe

Tests

  • 81 unique position encodings (3⁴)
  • Frequency scales correctly: scale_k has period 3^k
  • Gradient flows through PE lookup

Blocks

  • 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