Haruka-Tagger-12L W4A8 (AWQ-QAT)

A 111.26 MB W4A8 (4-bit weights, dynamic 8-bit activations) quantized & distilled version of Haruka-Tagger (12-layer EVA02-Base-448, 98,782 Danbooru tags), trained via Activation-Aware Weight & Activation Quantization-Aware Training (AWQ-QAT) using Haruka-Tagger-Large (24L) as the distillation teacher.

  • 7.3x smaller than the FP32 Base model (809 MB $\to$ 111.26 MB) and 1.68x smaller than alpindale/haruka-compressed (187 MB).
  • 2.5x–3.4x faster on WebGPU (dot4I8Packed DP4A) than 8-bit W8A8 / W8A16 formats, and 2.07x faster on CPU (AVX-512 VNNI) than PyTorch FP32.
  • Surpasses both 12L alpindale/haruka-compressed (+3.02% Micro-F1) and 24L FP32 Teacher (+1.15% Micro-F1) on ALL_CONTENT Micro-F1 on Shio-Koube/new-dan ($N=5000$).

Accuracy (Shio-Koube/new-dan, $N = 5,000$)

Evaluated at the standard Haruka-Tagger thresholds (general: 0.35, character: 0.35, copyright: 0.35, artist: 0.25, rating: 0.50, ALL_CONTENT: 0.35) against:

  • FP32 Teacher: KaraKaraWitch/haruka-tagger-large (24L EVA02-Large-448, 1.69 GB)
  • Alpin: alpindale/haruka-compressed (12L EVA02-Base-448, ~7.4-bit GPTQ, 187 MB)
  • W4A8 (Ours): 12L EVA02-Base-448, 4-bit weights + 8-bit activations (AWQ-QAT, 111.26 MB)
Category FP32 (24L) AUPRC Alpin (~7.4-bit) AUPRC W4A8 (Ours) AUPRC W4A8 - Alpin FP32 (24L) F1 Alpin (~7.4-bit) F1 W4A8 (Ours) F1
general 46.45% 42.50% 41.37% -1.13% 59.37% 57.69% 60.79%
character 92.75% 90.23% 89.83% -0.39% 80.36% 76.48% 78.17%
copyright 76.97% 72.72% 71.93% -0.79% 74.39% 69.22% 65.48%
artist 87.82% 84.83% 85.07% +0.24% 53.21% 49.33% 64.51%
rating 89.14% 88.80% 88.16% -0.64% 84.65% 84.32% 83.48%
ALL_CONTENT 61.65% 58.07% 57.23% -0.84% 60.54% 58.67% 61.69%

Speed & Size Benchmarks

Measured on AMD Ryzen 7 8845H / Radeon 780M (rdna-3) for a single 448Γ—448 image (M = 1024 patch tokens + 98,782-tag classifier head):

WebGPU (Radeon 780M rdna-3, Hardware timestamp-query)

All 12 transformer block linears + 98.8k classifier head:

Model / Precision Checkpoint Size 12L Linears + Head Throughput Speedup vs. FP16
Standard FP16 (W16A16) 386 MB ~797 ms 1.25 img/s 1.00x
alpindale/haruka-compressed (W8A16 f16 FMA) 187 MB 142.36 ms 7.0 img/s 5.60x
alpindale/haruka-compressed (W8A8 dot4I8Packed) 187 MB 105.96 ms 9.4 img/s 7.52x
W4A8 AWQ-QAT (dot4I8Packed, g=64) 111.26 MB 41.84 – 46.59 ms 21.5 – 23.9 img/s ~17–19x faster

CPU (Ryzen 7 8845H, 8 Cores / 16 Threads)

Runtime / Precision Model Size End-to-End (1 image 448Γ—448) Throughput
PyTorch FP32 (MKL) 809 MB 896.1 ms 1.12 img/s
AVX-512 VNNI W4A8 (vpdpbusd, g=64) 111.26 MB 432.4 ms 2.31 img/s (2.07x faster)

Method

  1. AWQ Channel Migration & Zero-Cost LayerNorm Fusion:
    • Profiles per-channel activation scales (capturing EVA02's $>5\sigma$ denominator-sink channels) and runs a grid search over $\alpha \in [0, 1]$ for $s = s_X^\alpha / s_W^{1-\alpha}$ to minimize joint W4A8 output reconstruction error.
    • Fuses $s^{-1}$ directly into preceding LayerNorm weights/biases (norm1, norm2, mlp.norm, head_pool.norm) for zero runtime division overhead, while keeping learnable awq_scale vectors on remaining layers (attn.proj, head).
  2. Differentiable W4A8 AWQ-QAT with Learnable Weight Clipping:
    • Weights (W4): Group-wise symmetric signed INT4 [-8, 7] (group_size = 64) with Straight-Through Estimator (_STERound) and learnable per-group clipping (clip_logit $\in (0.5, 1.0)$).
    • Activations (A8): Dynamic per-group symmetric INT8 [-127, 127] (act_group_size = 128).
  3. Cross-Architecture 24L Large -> 12L Base Logit Distillation:
    • Distilled using full-vocabulary dual-probability weighted MSE, ListNet softmax ranking KL, and focal multi-label Binary KL across all 98,782 tags.

Quick Inference Usage

Run inference directly with the included haruka_w4a8_infer.py script:

pip install torch torchvision timm safetensors pillow huggingface_hub
python haruka_w4a8_infer.py path/to/image.jpg \
  --weights ./haruka-tagger-12L-w4a8-awq-qat-packed.safetensors \
  --sim-a8

Checkpoint Format (haruka-tagger-12L-w4a8-awq-qat-packed.safetensors)

All 86 quantized linear layers (12 blocks Γ— 7 linears + head_pool.kv + head) are stored as:

  • <layer>.qweight_packed: uint8 [N, K // 2] β€” two 4-bit unsigned offset-8 codes (w_int4 + 8 $\in [0, 15]$) per byte (low nibble = even k, high nibble = odd k).
  • <layer>.scales: float16 [N, K // 64] β€” per-group weight scale.
  • <layer>.awq_scale: float16 [K] β€” input channel smoothing scale (1.0 where fused into LayerNorm).
  • <layer>.bias: float16 [N] (where present).

All remaining non-quantized weights (patch_embed, pos_embed, LayerNorm, head_pool) are stored in float16.

Unpacking in PyTorch

import torch
from safetensors.torch import load_file

sd = load_file("haruka-tagger-12L-w4a8-awq-qat-packed.safetensors")

def unpack_w4_layer(sd, prefix, group_size=64):
    qpack = sd[f"{prefix}.qweight_packed"]
    scales = sd[f"{prefix}.scales"].float()
    awq_s = sd[f"{prefix}.awq_scale"].float()
    N, K_half = qpack.shape
    K = K_half * 2

    w_even = (qpack & 0x0F).to(torch.int32) - 8
    w_odd = ((qpack >> 4) & 0x0F).to(torch.int32) - 8
    w_int = torch.empty((N, K), dtype=torch.float32)
    w_int[:, 0::2] = w_even.float()
    w_int[:, 1::2] = w_odd.float()

    return (w_int.reshape(N, K // group_size, group_size) * scales.unsqueeze(-1)).reshape(N, K) / awq_s.unsqueeze(0)

WebGPU dot4I8Packed Unpacking Snippet

// Load 8 x 4-bit weights in a single u32 (pre-XOR'd by 0x88888888u to convert offset-8 -> 2's complement)
let wp: u32 = w_buf[idx];
let w_lo4: u32 = (wp & 0x0F0F0F0Fu) << 4u; // 4 signed int8 weights (* 16)
let w_hi4: u32 =  wp & 0xF0F0F0F0u;        // 4 signed int8 weights (* 16)
acc_i32 += dot4I8Packed(x_i8.x, w_lo4) + dot4I8Packed(x_i8.y, w_hi4);
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Shio-Koube/Haruka-W4A8