llama.cpp에서의 OSCAR2 - 나의 최신 프로젝트
요약
llama.cpp 환경에서 OSCAR2 KV Cache 기술의 성능을 벤치마크한 결과입니다. NVIDIA RTX 5090 하드웨어를 사용하여 Qwen3 모델 시리즈의 생성 속도를 테스트했습니다.
핵심 포인트
- OSCAR2 캐시는 q2_0 대비 생성 속도가 약 35% 더 빠름
- f16 베이스라인 성능의 30% 이내 오차 범위로 효율적인 성능 구현
- Blackwell 아키텍처 환경에서 MMA_F16 경로를 통한 최적화 확인
- Qwen3-8B 및 27B 모델에 대한 양자화 캐시 성능 검증
OSCAR2 KV Cache 벤치마크
날짜 : 2026-07-18
하드웨어 : NVIDIA RTX 5090 (32 GB VRAM, Blackwell sm_120, CUDA 13.3)
CPU : Intel Core Ultra 9 285K
빌드 : b10009-4b053b884 (oscar 브랜치, 최신 feature/turboquant-kv-cache로 리베이스됨)
적용된 수정 사항 : Blackwell VEC FA 커널 비활성화 — 작동 가능한 MMA_F16 경로로 라우팅됨
테스트된 모델
| 모델 | 양자화 크기 | 회전 (Rotation) |
|---|---|---|
| Qwen3-8B | Q8_0 | 8 GB Calibrated (RHP) |
| Qwen3.6-27B | Q5_K_XL | 19 GB Hadamard (data-free) |
생성 속도 (4K 컨텍스트, Qwen3.6-27B)
| 캐시 유형 | 프롬프트 t/s | 생성 t/s | 출력 f16/f16 |
|---|---|---|---|
| f16 | 207 | 60 | "Here's a thinking process:" |
| oscar2/oscar2 | 198 | 42 | "Here's a thinking process:" |
| q2_0/q2_0 | 180 | 31 | "Here's a thinking process:" |
명령어:
f16 baseline
CUDA_VISIBLE_DEVICES=0 ./build/bin/llama-cli \
-m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \
-ngl 99 -fa on -c 4096 \
--cache-type-k f16 --cache-type-v f16 \
--temp 0 -p "The capital of France is Paris. The capital of Germany is Berlin. The capital of Italy is Rome. The capital of Spain is" \
-n 50 --single-turn
oscar2
CUDA_VISIBLE_DEVICES=0 ./build/bin/llama-cli \
-m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \
-ngl 99 -fa on -c 4096 \
--cache-type-k oscar2 --cache-type-v oscar2 \
--temp 0 -p "The capital of France is Paris. The capital of Germany is Berlin. The capital of Italy is Rome. The capital of Spain is" \
-n 50 --single-turn
q2_0
CUDA_VISIBLE_DEVICES=0 ./build/bin/llama-cli \
-m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \
-ngl 99 -fa on -c 4096 \
--cache-type-k q2_0 --cache-type-v q2_0 \
--temp 0 -p "The capital of France is Paris. The capital of Germany is Berlin. The capital of Italy is Rome. The capital of Spain is" \
-n 50 --single-turn
oscar2는 생성 시 q2_0보다 35% 더 빠르며, f16의 30% 이내 성능을 보여줍니다.
Qwen3-8B 속도 (4K 컨텍스트) 캐시 프롬프트 t/s 생성 t/s f16/f16 2008 134 oscar2/oscar2 1496 60 q2_0/q2_0 699 32 명령어: bash CUDA_VISIBLE_DEVICES=0 ./build/bin/llama-cli \ -m /mnt/storage/models/qwen3-8b-q8_0-rot-kv.gguf \ -ngl 99 -fa on -c 4096 \ --cache-type-k oscar2 --cache-type-v oscar2 \ --temp 0 -p "The capital of France is Paris. The capital of Germany is Berlin. The capital of Italy is Rome. The capital of Spain is" \ -n 50 --single-turn 컨텍스트 스케일링 (Qwen3.6-27B, oscar2/oscar2) 컨텍스트 프롬프트 t/s 생성 t/s 적합? 4K 97 42 예 128K 95 43 예 256K 103 46 예 512K — — 예 (YaRN 사용 시) 1M 96 43 예 생성 속도는 모든 컨텍스트 길이에서 일정합니다. 즉, 4K에서 1M까지 성능 저하가 없습니다. 명령어: bash 128K ./build/bin/llama-cli \ -m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \ -ngl 99 -fa on -c 131072 \ --cache-type-k oscar2 --cache-type-v oscar2 \ --temp 0 -p "What is the capital of France?" -n 20 --single-turn 256K ./build/bin/llama-cli \ -m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \ -ngl 99 -fa on -c 262144 \ --cache-type-k oscar2 --cache-type-v oscar2 \ --temp 0 -p "What is the capital of France?" -n 20 --single-turn 1M ./build/bin/llama-cli \ -m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \ -ngl 99 -fa on -c 1048576 \ --cache-type-k oscar2 --cache-type-v oscar2 \ --temp 0 -p "What is the capital of France?" -n 20 --single-turn 컨텍스트 제한: f16 대 oscar2 (Qwen3.6-27B) 컨텍스트 f16/f16 oscar2/oscar2 128K ✓ 61 t/s ✓ 43 t/s 170K OOM ✓ 256K OOM ✓ 46 t/s 512K OOM ✓ (YaRN 사용 시) 1M OOM ✓ 43 t/s 최대 f16 컨텍스트: 32 GB 카드에서 ~170K 최대 oscar2 컨텍스트: >1M (테스트됨, 더 높을 수 있음) bash f16의 OOM 경계 테스트 CUDA_VISIBLE_DEVICES=0 ./build/bin/llama-cli \ -m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \ -ngl 99 -fa on -c 196608 \ --cache-type-k f16 --cache-type-v f16 \ --temp 0 -n 1 --prompt "x" --single-turn oscar2 대 turbo2 (256K 컨텍스트에서) 지표 oscar2/oscar2 turbo2 (K=q8_0, V=turbo2) K 정밀도 INT2
(2.25 bit) Q8_0 (8.5 bit) V 정밀도 INT2 (2.25 bit) Turbo2 (2.12 bit) KV 캐시 (KV cache) VRAM 9.0 GB 21.2 GB 모델 (Model) VRAM 19.0 GB 19.0 GB 총 VRAM (Total VRAM) 28.0 GB ✓ 40.2 GB ✗ 생성 속도 (Generation speed) 46 t/s 59 t/s (+28%) 32 GB에 적합한가? (Fits in 32 GB?) 예 (Yes) 아니오 (No) turbo2는 비대칭 모드 (asymmetric mode)를 강제하며 (정책상 K=q8_0), 이는 더 빠르지만 VRAM을 2.4배 더 사용합니다. oscar2는 생성 속도를 21% 희생하는 대신 2.4배 더 큰 컨텍스트 용량 (context capacity)을 제공합니다.
oscar2 ./build/bin/llama-cli \
-m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \
-ngl 99 -fa on -c 262144 \
--cache-type-k oscar2 --cache-type-v oscar2 \
--temp 0 -p "What is the capital of France?" -n 20 --single-turn
turbo2 비대칭 (asymmetric) (K=q8_0, V=turbo2) ./build/bin/llama-cli \
-m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \
-ngl 99 -fa on -c 262144 \
--cache-type-k q8_0 --cache-type-v turbo2 \
--temp 0 -p "What is the capital of France?" -n 20 --single-turn
서버 테스트 (Server Test) (llama-server + oscar2 + YaRN 512K)
서버는 YaRN RoPE 스케일링 (scaling)을 사용하여 512K 컨텍스트에서 oscar2로 로드되며 일관된 응답을 생성합니다.
bash Start server CUDA_VISIBLE_DEVICES=0 ./build/bin/llama-server \ -m /mnt/storage/models/qwen3.6-27b-q5kxl-hadamard.gguf \ -ngl 99 -fa on -c 524288 \ --cache-type-k oscar2 --cache-type-v oscar2 \ --rope-scaling yarn --yarn-orig-ctx 262144 --rope-scale 2 \ --host 127.0.0.1 --port 18080 Request curl -s -X POST http://127.0.0.1:18080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"What is the capital of France?","n_predict":20,"temperature":0}' Parallel requests curl -s -X POST http://127.0.0.1:18080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Explain quantum computing","n_predict":30,"temperature":0}' & curl -s -X POST http://127.0.0.1:18080/completion \ -H "Content-Type: application/json" \ -d '{"prompt":"Write a haiku about programming","n_predict":30,"temperature":0}' & 512K에서 서버 지표 (단일 요청): | Metric | Value | |--------|-------| | Prompt eval | 42 t/s | | Generation | 48 t/s | | Output | Coherent: "The capital of France is Paris ." | | KV size | 524,288 | | Context checkpoint | 150 MB per checkpoint | Compression Ratios Type Bytes/128-elem bits/elem vs f16 f16 256 16.00 1.0× q8_0 136 8.50 1.9× turbo2 34 2.12 7.5× oscar2 36 2.25 7.1× q2_0 40 2.50 6.4× OSCAR2는 fp16 zero-point 메타데이터 덕분에 turbo2보다 약간 덜 공격적으로 압축되지만 (2.25 vs 2.12 bits/elem), K와 V 모두에 대칭적인 INT2 압축을 가능하게 합니다. 이는 K를 q8_0으로 강제하는 turbo2의 비대칭 정책과는 다릅니다. Rotation Model Conversion 모든 GGUF 모델에 대해 Hadamard 회전을 생성하고 내장하려면: bash One-step: generate + bake python3 oscar-rotation/generate_and_bake_rot.py \ --base model.gguf --out model-rot-kv.gguf \ --method hadamard Standalone Hadamard generator python3 oscar-rotation/generate_hadamard_rot.py \ --head-dim 256 --num-layers 48 --output-dir . Bake existing .pt rotation files python3 oscar-rotation/export_rot_kv_gguf.py \ --base model.gguf --out model-rot-kv.gguf
레이어별 헤드 차원 (Per-layer head dimensions) 지원 (Gemma-4 SWA: 256 차원 40개 레이어, 512 차원 8개 레이어).
해결된 알려진 문제들 (Known Issues Fixed):
- Blackwell에서의 VEC FA 커널: sm_120에서 쓰레기 값 (garbage) 생성 문제. MMA_F16으로 라우팅하여 해결함.
- oscar2 커널의 융합된 리덕션 (Fused reduction) 버그: 전체 KQ 점수 대신 부분 합 (partial sums)에서 최댓값이 계산되던 문제. 해결됨.
- 레이어별 헤드 차원 감지: 이제 스크립트가 균일한 헤드 차원을 가정하는 대신 attn_q 텐서 형상 (tensor shapes)을 읽어옴.
submitted by /u/giveen [link] [comments]
AI 자동 생성 콘텐츠
본 콘텐츠는 r/LocalLLaMA의 원문을 AI가 자동으로 요약·번역·분석한 것입니다. 원 저작권은 원저작자에게 있으며, 정확한 내용은 반드시 원문을 확인해 주세요.
원문 바로가기