caiovicentino1/Qwen3.5-9B-PolarEngine-v4

Model

0

stars

16

commits

3

linked in READMEs

Apr 13, 2026

updated

conversational
custom-kernel
endpoints_compatible
hlwq
llm-compression
polar-engine
quantization
qwen3.5
qwen3_5_text
research
safetensors
text-generation
transformers
triton

README

[!IMPORTANT] Naming notice (2026-04-10). The "HLWQ" technique used in this model is being rebranded to HLWQ (Hadamard-Lloyd Weight Quantization). The change is only the name; the algorithm and the weights in this repository are unchanged.

The rebrand resolves a name collision with an unrelated, earlier KV cache quantization method also named HLWQ (Han et al., arXiv:2502.02617, 2025). HLWQ addresses weight quantization with a deterministic Walsh-Hadamard rotation and Lloyd-Max scalar codebook; Han et al.'s HLWQ addresses KV cache quantization with a random polar rotation. The two methods are technically distinct.

Existing loaders that load this repository by ID continue to work without changes. Future model uploads will use the HLWQ name.

Reference paper for this technique: arXiv:2603.29078 (v2 in preparation; v1 still uses the old name).

⚑ HLWQ-Engine v4 -- Qwen3.5-9B

Custom Triton kernel inference for HLWQ -- 34 tok/s with direct quantized computation (no dequantization).

Note: For production use, we recommend HLWQ Q5 + torchao instead (43 tok/s vs 34 tok/s). HLWQ-Engine v4 is a research artifact demonstrating direct quantized inference without dequantization.


🎯 Key Results

MetricValue
MethodHLWQ-Engine v4 (Triton GEMV)
Perplexity (WikiText-2)6.89
Throughput34.0 tok/s
VRAM12.2 GB
PlatformRTX PRO 6000 (Blackwell)
vs v32.9x speedup (11.8 -> 34.0 tok/s)
vs FP1674% speed, 68% VRAM

πŸ“Š Performance Evolution

Speed vs VRAM

Versiontok/sSpeedupKey Optimization
v1~31xNaive Python dequant
v2~72.3xGPU dequant
v311.83.9xTriton GEMV kernel
v434.011.3xMatmul FWHT + cache
Methodtok/sVRAMPPLApproach
HLWQ Q5 + torchao43.16.5 GB6.56Dequant + cuBLAS
HLWQ-Engine v434.012.2 GB6.89Direct Triton GEMV
FP16 baseline45.717.9 GB6.37cuBLAS

πŸ”¬ Architecture

HLWQ-Engine v4 performs inference directly on quantized weights without dequantization, using custom Triton kernels:

Input Activations
       |
       v
  [FWHT Cache] --> Hadamard Transform (cached per forward pass)
       |
       v
  [Triton GEMV] --> Centroid lookup + accumulate (fused kernel)
       |
       v
  [Scale by Norms] --> Output Activations

Key Optimizations (v3 -> v4)

OptimizationBeforeAfterSpeedup
Matmul FWHT0.208 ms/call0.008 ms/call25x
FWHT cache3x redundant calls1x (Q/K/V reuse)3x
Pre-scaled centroidsRuntime multiplyBaked into table~1.1x

Matmul FWHT: Replaced butterfly-algorithm FWHT with torch.matmul(x, H128) -- cuBLAS is faster than custom code for 128-dim transforms.

FWHT Cache: Q, K, V projections in attention share the same input activation. Cache by data_ptr to avoid redundant transforms. Auto-cleared between model.forward() calls via pre-hook.


πŸš€ Usage

# HLWQ-Engine v4 requires the polarengine-vllm package
pip install polarengine-vllm

from polarengine_vllm import HLWQizer
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load the quantized model
model = AutoModelForCausalLM.from_pretrained(
    "caiovicentino1/Qwen3.5-9B-HLWQ-Engine-v4",
    dtype="bfloat16", device_map="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("caiovicentino1/Qwen3.5-9B-HLWQ-Engine-v4")

output = model.generate(
    **tokenizer("What is machine learning?", return_tensors="pt").to("cuda"),
    max_new_tokens=200
)
print(tokenizer.decode(output[0], skip_special_tokens=True))

πŸ”§ Technical Details

ComponentDetails
KernelTriton GEMV (polar_gemv_kernel)
FWHTMatmul-based, cached per forward pass
CentroidsPre-scaled by 1/sqrt(block_size)
QuantizationHLWQ Q5 (5-bit, block_size=128)
Storageint8 codes + fp16 norms + fp32 centroids
Remaining gap2048x8192 layers 4.5x slower than cuBLAS (SplitK would fix)

Known Limitations

  • Slower than torchao: cuBLAS INT4 matmul is highly optimized; custom Triton GEMV cannot yet match it
  • Higher VRAM: Stores quantized weights + lookup tables (12.2 GB vs 6.5 GB)
  • No SplitK: Large matrices (2048x8192) are bottlenecked without split-K parallel reduction
  • Research code: Not recommended for production deployment


πŸ“– Citation

@article{vicentino2026polarquant,
  title={HLWQ: Optimal Gaussian Weight Quantization via Hadamard Rotation for LLM Compression},
  author={Vicentino, Caio},
  journal={arXiv preprint arXiv:2603.7424577},
  year={2026}
}

πŸ™ Acknowledgements

Built with PyTorch, Triton, and the Qwen team's open-weight models.

Contributors

caiovicentino1

16 commits

caiovicentino1/Qwen3.5-9B-PolarEngine-v4

Model

0

stars

16

commits

3

linked in READMEs

Apr 13, 2026

updated

conversational
custom-kernel
endpoints_compatible
hlwq
llm-compression
polar-engine
quantization
qwen3.5
qwen3_5_text
research
safetensors
text-generation
transformers
triton

README

[!IMPORTANT] Naming notice (2026-04-10). The "HLWQ" technique used in this model is being rebranded to HLWQ (Hadamard-Lloyd Weight Quantization). The change is only the name; the algorithm and the weights in this repository are unchanged.

The rebrand resolves a name collision with an unrelated, earlier KV cache quantization method also named HLWQ (Han et al., arXiv:2502.02617, 2025). HLWQ addresses weight quantization with a deterministic Walsh-Hadamard rotation and Lloyd-Max scalar codebook; Han et al.'s HLWQ addresses KV cache quantization with a random polar rotation. The two methods are technically distinct.

Existing loaders that load this repository by ID continue to work without changes. Future model uploads will use the HLWQ name.

Reference paper for this technique: arXiv:2603.29078 (v2 in preparation; v1 still uses the old name).

⚑ HLWQ-Engine v4 -- Qwen3.5-9B

Custom Triton kernel inference for HLWQ -- 34 tok/s with direct quantized computation (no dequantization).

Note: For production use, we recommend HLWQ Q5 + torchao instead (43 tok/s vs 34 tok/s). HLWQ-Engine v4 is a research artifact demonstrating direct quantized inference without dequantization.


🎯 Key Results

MetricValue
MethodHLWQ-Engine v4 (Triton GEMV)
Perplexity (WikiText-2)6.89
Throughput34.0 tok/s
VRAM12.2 GB
PlatformRTX PRO 6000 (Blackwell)
vs v32.9x speedup (11.8 -> 34.0 tok/s)
vs FP1674% speed, 68% VRAM

πŸ“Š Performance Evolution

Speed vs VRAM

Versiontok/sSpeedupKey Optimization
v1~31xNaive Python dequant
v2~72.3xGPU dequant
v311.83.9xTriton GEMV kernel
v434.011.3xMatmul FWHT + cache
Methodtok/sVRAMPPLApproach
HLWQ Q5 + torchao43.16.5 GB6.56Dequant + cuBLAS
HLWQ-Engine v434.012.2 GB6.89Direct Triton GEMV
FP16 baseline45.717.9 GB6.37cuBLAS

πŸ”¬ Architecture

HLWQ-Engine v4 performs inference directly on quantized weights without dequantization, using custom Triton kernels:

Input Activations
       |
       v
  [FWHT Cache] --> Hadamard Transform (cached per forward pass)
       |
       v
  [Triton GEMV] --> Centroid lookup + accumulate (fused kernel)
       |
       v
  [Scale by Norms] --> Output Activations

Key Optimizations (v3 -> v4)

OptimizationBeforeAfterSpeedup
Matmul FWHT0.208 ms/call0.008 ms/call25x
FWHT cache3x redundant calls1x (Q/K/V reuse)3x
Pre-scaled centroidsRuntime multiplyBaked into table~1.1x

Matmul FWHT: Replaced butterfly-algorithm FWHT with torch.matmul(x, H128) -- cuBLAS is faster than custom code for 128-dim transforms.

FWHT Cache: Q, K, V projections in attention share the same input activation. Cache by data_ptr to avoid redundant transforms. Auto-cleared between model.forward() calls via pre-hook.


πŸš€ Usage

# HLWQ-Engine v4 requires the polarengine-vllm package
pip install polarengine-vllm

from polarengine_vllm import HLWQizer
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load the quantized model
model = AutoModelForCausalLM.from_pretrained(
    "caiovicentino1/Qwen3.5-9B-HLWQ-Engine-v4",
    dtype="bfloat16", device_map="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("caiovicentino1/Qwen3.5-9B-HLWQ-Engine-v4")

output = model.generate(
    **tokenizer("What is machine learning?", return_tensors="pt").to("cuda"),
    max_new_tokens=200
)
print(tokenizer.decode(output[0], skip_special_tokens=True))

πŸ”§ Technical Details

ComponentDetails
KernelTriton GEMV (polar_gemv_kernel)
FWHTMatmul-based, cached per forward pass
CentroidsPre-scaled by 1/sqrt(block_size)
QuantizationHLWQ Q5 (5-bit, block_size=128)
Storageint8 codes + fp16 norms + fp32 centroids
Remaining gap2048x8192 layers 4.5x slower than cuBLAS (SplitK would fix)

Known Limitations

  • Slower than torchao: cuBLAS INT4 matmul is highly optimized; custom Triton GEMV cannot yet match it
  • Higher VRAM: Stores quantized weights + lookup tables (12.2 GB vs 6.5 GB)
  • No SplitK: Large matrices (2048x8192) are bottlenecked without split-K parallel reduction
  • Research code: Not recommended for production deployment


πŸ“– Citation

@article{vicentino2026polarquant,
  title={HLWQ: Optimal Gaussian Weight Quantization via Hadamard Rotation for LLM Compression},
  author={Vicentino, Caio},
  journal={arXiv preprint arXiv:2603.7424577},
  year={2026}
}

πŸ™ Acknowledgements

Built with PyTorch, Triton, and the Qwen team's open-weight models.

Contributors

caiovicentino1

16 commits