Skip to content

feat(hslm): [J] Full Ternary Inference Pipeline — 0 float ops #339

Description

@gHashTag

Parent: #329 — Fully Ternary Transformer

Level 2 (needs B, C, D, E) | ~150 LOC | New: src/hslm/ternary_inference.zig

Description

Complete inference pipeline with zero floating-point operations: trit embed → trit PE → quantize → 3 blocks (ternary attn + integer FFN + quantize) → argmax.

Implementation

  • TernaryInferencePipeline struct: holds all ternary components
  • forward(token: u32, pos: u32) → u32 — full pipeline, returns next token
  • quantizeI32ToTernary(accum: []i32) → []i2 — inter-layer requantization
  • Pipeline: trit_embed(token) → add trit_pe(pos) → for each block: ternary_attn → integer_ffn → requantize → argmax on final output

tri CLI

tri hslm inference --ternary

Tests

  • Output is valid token (0..728)
  • Zero float operations (compile-time check: no f32/f64 in pipeline)
  • Benchmark: ternary inference vs float inference throughput

Dependencies

  • B (Trit Encoding) — trit embedding
  • C (Ternary PE) — positional encoding
  • D (Ternary Activations) — quantizer + integer matmul
  • E (Ternary Attention) — ternary scoring

Blocks

  • Issue K (FPGA Verilog Export)

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