Base Llama 3.1-8B-Instruct와 PQC-tuned Llama (LoRA fine-tuned)를 기존 벤치마킹 시스템으로 비교합니다.
- 테스트 대상: Assembly/Binary 파일만
- 비교 모델:
- Base:
meta-llama/Meta-Llama-3.1-8B-Instruct(일반 모델) - Tuned:
sangwoohahn/PQCllama(PQC 특화 파인튜닝)
- Base:
# HuggingFace CLI 로그인
huggingface-cli login
# 토큰 입력: hf_xxxxx...
# Llama 3.1 접근 권한 요청
# https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct
# "Request Access" 클릭pip install peft acceleratepython benchmark_base_vs_tuned_binary.py- 위치:
data/test_files/assembly_binary/ - 파일 형식: Assembly 코드 (
.s파일) - 예시:
aes_key_expansion_module.srsa_signature_verification.saria_encryption_engine.s
-
Precision (정밀도)
- 탐지한 알고리즘 중 맞춘 비율
TP / (TP + FP)
-
Recall (재현율)
- 실제 알고리즘 중 찾은 비율
TP / (TP + FN)
-
F1-Score (조화 평균)
- Precision과 Recall의 균형
2 * (Precision * Recall) / (Precision + Recall)
-
Response Time (응답 시간)
- 모델이 답변을 생성하는 데 걸린 시간
Precision: 20-30%
Recall: 20-30%
F1-Score: ~25%
Response Time: ~15-20초
Precision: 60-80% (예상)
Recall: 60-80% (예상)
F1-Score: ~70% (예상)
Response Time: ~15-20초
예상 개선: +180% (약 2.8배)
# benchmark_base_vs_tuned_binary.py 수정
# 전체 테스트
TEST_LIMIT = None
# 10개만 테스트 (빠른 테스트)
TEST_LIMIT = 10
# 50개 테스트
TEST_LIMIT = 50Apple M2 24GB에서는 기본 설정으로 충분하지만, 메모리 부족 시:
# benchmark_base_vs_tuned_binary.py에서
torch_dtype=torch.float16 # 이미 설정됨
# 또는 INT8 양자화 (메모리 절약)
load_in_8bit=True결과는 results/ 디렉토리에 저장됩니다:
results/base_vs_tuned_binary_20250106_123456.json
{
"benchmark_info": {
"timestamp": "2025-01-06T12:34:56",
"base_model": "meta-llama/Meta-Llama-3.1-8B-Instruct",
"tuned_model": "sangwoohahn/PQCllama",
"test_type": "assembly_binary",
"total_tests": 152
},
"base_results": [
{
"test_id": "aes_key_expansion",
"true_positives": 1,
"false_positives": 2,
"false_negatives": 1,
"response_time": 15.3,
"detected_algorithms": ["AES", "RSA", "DES"]
}
],
"tuned_results": [...]
}결과를 시각화하려면:
python visualize_base_vs_tuned.py results/base_vs_tuned_binary_*.json생성되는 그래프:
- F1-Score 비교 (막대 그래프)
- Precision/Recall 비교 (산점도)
- 응답 시간 비교 (박스 플롯)
- 알고리즘별 성능 (히트맵)
| 테스트 수 | 예상 시간 | 권장 |
|---|---|---|
| 10개 | ~6분 | 빠른 테스트 ✅ |
| 50개 | ~30분 | 샘플 테스트 ✅ |
| 전체 (~150개) | ~1.5시간 | 전체 벤치마크 |
참고: 각 모델이 순차적으로 실행됩니다.
- Base model: 각 테스트 ~15-20초
- Tuned model: 각 테스트 ~15-20초
- 총: ~30-40초 per test
# 결과 파일 로드
import json
with open('results/base_vs_tuned_binary_xxx.json') as f:
data = json.load(f)
# Base model 분석
base_tp = sum(r['true_positives'] for r in data['base_results'])
base_fp = sum(r['false_positives'] for r in data['base_results'])
base_fn = sum(r['false_negatives'] for r in data['base_results'])
print(f"Base - TP: {base_tp}, FP: {base_fp}, FN: {base_fn}")
# Tuned model 분석
tuned_tp = sum(r['true_positives'] for r in data['tuned_results'])
tuned_fp = sum(r['false_positives'] for r in data['tuned_results'])
tuned_fn = sum(r['false_negatives'] for r in data['tuned_results'])
print(f"Tuned - TP: {tuned_tp}, FP: {tuned_fp}, FN: {tuned_fn}")from collections import defaultdict
# 알고리즘별 성공률
base_alg_success = defaultdict(lambda: {'correct': 0, 'total': 0})
for result in data['base_results']:
expected = set(result['expected_algorithms'])
detected = set(result['detected_algorithms'])
for alg in expected:
base_alg_success[alg]['total'] += 1
if alg in detected:
base_alg_success[alg]['correct'] += 1
# 출력
for alg, stats in sorted(base_alg_success.items()):
acc = stats['correct'] / stats['total'] * 100
print(f"{alg}: {acc:.1f}% ({stats['correct']}/{stats['total']})")# HuggingFace 로그인 확인
huggingface-cli whoami
# 재로그인
huggingface-cli login
# Llama 3.1 접근 권한 확인
# https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct# TEST_LIMIT 줄이기
TEST_LIMIT = 10
# 또는 모델을 순차적으로 실행
# (이미 순차 실행이지만, 한 번에 하나씩만)pip install peft# 프롬프트 길이 줄이기 (이미 3000자로 제한됨)
# 또는 max_new_tokens 줄이기
max_new_tokens=1000 # 기본 2000실행 전 확인:
- HuggingFace 로그인 완료
- Llama 3.1 접근 권한 승인됨
-
peft,accelerate설치됨 - 디스크 여유 공간 20GB 이상
- RAM 24GB 이상 (또는 양자화 설정)
-
data/test_files/assembly_binary/존재
- RSA, DSA, DH 같은 일반 알고리즘은 탐지
- PQC 특화 알고리즘 (CRYSTALS, NTRU 등) 탐지 실패
- 한국 표준 (SEED, ARIA, HIGHT) 탐지 낮음
- 양자 위협에 대한 이해 부족
- PQC 취약 알고리즘 정확히 식별
- 양자 컴퓨팅 위협을 정확히 설명
- CRYSTALS-Kyber, Dilithium 같은 대안 제시
- 한국 표준 알고리즘도 더 잘 인식
벤치마크 완료 후:
-
결과 분석
python analyze_results.py results/base_vs_tuned_binary_*.json -
시각화
python visualize_base_vs_tuned.py results/base_vs_tuned_binary_*.json -
보고서 생성
python generate_report.py results/base_vs_tuned_binary_*.json
- 스크립트:
benchmark_base_vs_tuned_binary.py - 데이터:
data/test_files/assembly_binary/ - 결과:
results/base_vs_tuned_binary_*.json - 로그인 가이드:
HUGGINGFACE_LOGIN_GUIDE.md