Skip to content

feat(hslm): [H] φ-Scaled Dimensions — golden ratio architecture #337

Description

@gHashTag

Parent: #329 — Fully Ternary Transformer

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

Description

Scale model dimensions using the golden ratio φ = (1+√5)/2. Per-depth scaling φ^(-depth), FFN expansion φ× instead of 4×, residual scaling 1/√3, Xavier init for E[w²]=0.667.

Implementation

  • layerScale(depth: u32) → f32 — φ^(-depth): {1.0, 0.618, 0.382, ...}
  • ternaryInit(fan_in: u32) → []i2 — Xavier for ternary: E[w²] = 2/(fan_in+fan_out) ≈ 0.667
  • ffnExpansion(model_dim: u32) → u32 — φ× expansion (round to nearest multiple of 3)
  • residualScale() → f32 — 1/√3 ≈ 0.577

tri CLI

tri hslm phi-scale

Tests

  • Trinity identity: φ² + 1/φ² = 3
  • Layer scales decrease monotonically
  • FFN dimensions divisible by 3
  • Init variance ≈ 0.667

Blocks

  • Issue L (Integration — model.zig uses φ scaling)

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