Skip to content

daisybum/CPP_QAT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cerebras-GPT-1.3B INT4 QAT 프로젝트

C++/LibTorch 기반 INT4 양자화 인지 학습(Quantization-Aware Training) 구현 프로젝트

📁 프로젝트 구조

CPP_QAT/
├── README.md                          # 프로젝트 개요
├── ROADMAP_REVIEW.md                  # 로드맵 검토 문서
├── CMakeLists.txt                     # C++ 빌드 설정
├── requirements.txt                   # Python 의존성
├── config/                            # 설정 파일
│   ├── phase0_fp32.yaml              # Phase 0: FP32 학습 설정
│   ├── phase1_int8_qat.yaml          # Phase 1: INT8 QAT 설정
│   └── phase3_int4_qat.yaml          # Phase 3: INT4 QAT 설정
├── python/                            # Python 구현 (Phase 0-1)
│   ├── phase0_baseline.py            # FP32 baseline 학습
│   ├── phase1_int8_qat.py            # INT8 QAT (PyTorch 공식 API)
│   ├── data/
│   │   ├── dataset.py                # 데이터셋 로더
│   │   └── tokenizer.py              # 토크나이저 래퍼
│   ├── models/
│   │   ├── cerebras_gpt.py           # Cerebras-GPT 모델 정의
│   │   └── qat_model.py              # QAT 모델 래퍼
│   ├── utils/
│   │   ├── metrics.py                # 평가 메트릭 (Perplexity 등)
│   │   ├── logger.py                 # 로깅 유틸리티
│   │   └── checkpoint.py             # 체크포인트 관리
│   └── tests/
│       ├── test_dataset.py
│       └── test_model.py
├── cpp/                               # C++ 구현 (Phase 2-5)
│   ├── include/
│   │   ├── quantization/
│   │   │   ├── observer.h            # Observer 클래스
│   │   │   ├── fake_quantize.h       # FakeQuantize 모듈
│   │   │   ├── qconfig.h             # 양자화 설정
│   │   │   └── packing.h             # INT4/INT8 패킹 유틸
│   │   ├── modules/
│   │   │   ├── quant_linear.h        # QuantLinear 레이어
│   │   │   └── quant_conv.h          # QuantConv 레이어
│   │   ├── models/
│   │   │   └── cerebras_gpt.h        # Cerebras-GPT C++ 구현
│   │   └── utils/
│   │       ├── monitor.h             # 양자화 품질 모니터
│   │       └── checkpoint.h          # 체크포인트 로드/저장
│   ├── src/
│   │   ├── quantization/
│   │   │   ├── observer.cpp
│   │   │   ├── fake_quantize.cpp
│   │   │   └── packing.cpp
│   │   ├── modules/
│   │   │   └── quant_linear.cpp
│   │   ├── models/
│   │   │   └── cerebras_gpt.cpp
│   │   └── utils/
│   │       └── monitor.cpp
│   ├── tests/
│   │   ├── test_observer.cpp
│   │   ├── test_fake_quantize.cpp
│   │   ├── test_packing.cpp
│   │   └── test_integration.cpp
│   └── main.cpp                       # C++ 학습 메인 진입점
├── scripts/
│   ├── download_model.sh             # Cerebras-GPT 다운로드
│   ├── prepare_data.sh               # 데이터 전처리
│   └── run_training.sh               # 학습 실행 스크립트
├── checkpoints/                       # 체크포인트 저장 디렉토리
├── logs/                              # 로그 디렉토리
└── data/                              # 데이터 디렉토리
    ├── raw/                          # 원본 데이터
    └── processed/                    # 전처리된 데이터

🚀 빠른 시작

1. 환경 설정

Python 환경

# Python 3.10+ 권장
pip install -r requirements.txt

LibTorch 설치

# CUDA 11.8 버전 (Windows)
# https://pytorch.org/get-started/locally/ 에서 다운로드
# 예: libtorch-win-shared-with-deps-2.1.0+cu118.zip

# 압축 해제 후 환경 변수 설정
set LIBTORCH_PATH=C:\path\to\libtorch

C++ 빌드

mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=%LIBTORCH_PATH% ..
cmake --build . --config Release

2. Phase 0: FP32 Baseline 학습

# 데이터 준비
python python/data/dataset.py --prepare

# FP32 학습 실행
python python/phase0_baseline.py --config config/phase0_fp32.yaml

3. Phase 1: INT8 QAT (Python)

python python/phase1_int8_qat.py --config config/phase1_int8_qat.yaml --pretrained checkpoints/fp32_baseline.pt

4. Phase 2-5: C++ 구현

# C++ 학습 실행
.\build\Release\cpp_qat_train.exe --config config/phase3_int4_qat.yaml

📊 Phase별 목표

Phase 0: 사전 검증 (1주)

  • 프로젝트 구조 생성
  • FP32 baseline 학습
  • 데이터셋 검증
  • 목표 Perplexity: < 15.0

Phase 1: INT8 QAT Python (2주)

  • PyTorch 공식 QAT API 활용
  • 목표 Perplexity: < 16.0
  • 학습 안정성 검증

Phase 2: LibTorch 포팅 (2주)

  • C++ Observer/FakeQuant 구현
  • DDP/AMP 통합

Phase 3: INT4 구현 (3주)

  • INT4 커스텀 모듈
  • 패킹/언패킹 로직

Phase 4-5: 통합 및 최적화 (4주)

  • 전체 학습 파이프라인
  • 목표 Perplexity: < 18.0
  • 모델 크기: 650MB

🛠️ 개발 가이드

코드 스타일

  • Python: PEP 8, Black formatter
  • C++: Google C++ Style Guide
  • 주석: 한글/영어 혼용 가능

테스트

# Python 테스트
pytest python/tests/

# C++ 테스트
cd build
ctest --output-on-failure

디버깅

# 양자화 품질 모니터링
python python/utils/metrics.py --checkpoint checkpoints/qat_model.pt --analyze

# 텐서보드
tensorboard --logdir logs/

📚 참고 자료

📝 라이선스

MIT License

👥 기여자

  • Phase 0 개발 시작: 2025-10-02

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors