Qwen36 routed-expert TWLA W1.58A16, group size 256
Qwen36 35B-A3B 계열 모델의 routed expert를 E2M-ATQ/TWLA로 ternary 양자화한 public 연구 체크포인트다. TWLA scale과 offset을 output row 전체가 아니라 연속된 256개 input column 단위로 공유한다.
무엇이 양자화됐나
- 40개 layer x 256 routed expert 전체
- 대상 tensor:
routed_experts.gate_up_proj,routed_experts.down_proj - Weight alphabet:
{-1, 0, +1}(log2(3)=1.584963theoretical bits/weight) - Activation: BF16
- Router, attention, embedding, shared expert 등 비대상 파라미터: BF16
각 output row에서 256 input columns마다 독립적인 (mu, alpha)를 둔다. Stage I Euclidean warm start 뒤, Stage II에서 group-local S=X^T X block을 사용해 manifold-aware scale과 offset을 closed form으로 계산했다.
최종 reconstruction은 BF16 tensor로 materialize했다. 따라서 모델 값에는 ternary 양자화가 적용되어 있지만 파일 자체는 packed 1.58-bit checkpoint가 아니다.
Calibration 데이터와 loss
추가 gradient 학습은 없다. Calibration pool은 C4 160, code 32, math 32, science 32, long-context 8개 문서로 구성한 264문서 혼합 corpus이며, 실행에는 128개의 2,048-token chunk를 사용했다.
실제 router가 선택한 expert input으로 S=X^T X를 누적하고, ternary code를 고정한 채 다음 activation-domain reconstruction error를 group별로 최소화했다.
min_(mu, alpha) ||(W - mu - alpha*T) X||_F^2
세부 통계는 twla_quant_stats.json에 포함되어 있다.
추론
pip install -r requirements.txt
python inference.py --model minjaechoi/qwen36-twla-group256-w1p58a16 \
--prompt "Explain why the sky is blue." --max-new-tokens 512
양자화 코드
code/에는 실제 groupwise TWLA 파이프라인을 함께 제공한다.
python code/quantize_qwen36_experts_groupwise.py \
--group_size 256 \
--model_dir /path/to/base-model \
--calibset /path/to/robust_mixed_c4.jsonl \
--nsamples 128 --seqlen 2048 \
--out_dir /path/to/output
코드 안의 로컬 기본 경로는 실행 환경에 맞는 CLI 값으로 교체해야 한다.