Skip to content

dasLLAMA: half-float rows on the CPU hot paths cost time where the target has no hardware convert (wasm, x86-base) #4657

Done

Description

@borisbat

The CPU engine keeps some weights and caches as half floats (binary16). That is a win where the CPU converts halves in hardware - every aarch64, and x86 with F16C - because the convert is free and the rows are half the size. On a target with no hardware convert it costs time on every read: wasm, and the x86-base class.

Where the CPU paths hold halves

  • RNNT decoder (parakeet, GigaAM rnnt), dasllama/dasllama_rnnt.das: the LSTM gate weights, joint.pred and the joint net's columns. The engine narrows the file's f32 rows to halves at session build (repack_lstm_gates_f16, cvt_f32_to_f16_sat), or reads them baked from the image (wh, jw). Every decode step reads them through dot_f16 / axpy_f16.
  • LLM K/V cache, f16 codec, dasllama/dasllama_kv_codec.das: dot_f16 / axpy_f16 on read, cvt_f32_to_f16 on store.
  • q8 weight scales in halves (wscale over uint16, one convert per 32 elements) and K-quant superblock scales (two per 256 elements). These are too sparse to matter.

Measured (zen4b, 8 threads, wasm64 under node)

Decode step, ms a pass, parakeet-tdt-0.6b-v3 Q4_K_M on an 11 s clip:

build decode step
native, AVX2 class (hardware convert) 6.5
wasm, before 62.9
wasm, loop hints on and a branch-free half-to-float lowering 21.1

So after the lowering the stage is still about 3x the native one, and it is the largest gap left in the ASR path besides the f32 attention GEMM (#4653).

Kernel level, in wasm, the same tuner run: dot over f32 rows gains 5.3x from loop hints; dot_f16 gains 3.2x and starts from a slower body.

Proposal

A policy keyed on "the target converts halves in hardware" (what target_has_half_converts answers in the JIT):

  1. The RNNT session keeps f32 rows on a target without the convert, and reads them through dot / axpy.
  2. The K/V cache's default codec on such a target is f32 or q8_0, not f16.
  3. The image lane follows: a wasm or x86-base image carries f32 rows where today's carries halves (wh, jw), so its identity differs from the hardware-convert lane's.

Notes

  • The half-to-float lowering for targets without the convert (intrinsic_f16_to_f32_bits, the wasm tune branch) stays useful for whatever keeps halves; this issue is about not keeping them on the hot paths there.
  • f32_to_f16 still compiles its daslang body on those targets. It matters only for a K/V store that stays f16.
  • Not measured: the K/V f16 codec on wasm (no LLM has been timed there yet), and the tower code's f16_to_f32 uses in dasllama/dasllama_tower.das.

Activity

  1. borisbat commented on Dec 2, 2026

    @borisbat
    CollaboratorAuthor

    The three parts landed in #4790: the RNNT session keeps f32 rows where the target has no hardware half convert, the K/V cache's automatic codec picks q8_0 there, and an image records its row form. The wasm suite at #4879's tip passes with them (19 files, 0 failed, test_rnnt_f32_rows among them). The wasm decode-step timing this issue quotes was not re-measured.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions