Skip to content

Feat: 모델 분할 및 Docker 업로드 시간 측정 코드 추가 - #2

Merged
rinarina0429 merged 9 commits into
mainfrom
feat/#1
Jun 7, 2025
Merged

Feat: 모델 분할 및 Docker 업로드 시간 측정 코드 추가#2
rinarina0429 merged 9 commits into
mainfrom
feat/#1

Conversation

@rinarina0429

@rinarina0429 rinarina0429 commented Jun 5, 2025

Copy link
Copy Markdown
Member

📍 Issue

📝 Description

  • 모델을 분할하고 Docker 업로드 시간을 측정하는 코드를 추가하였습니다.
  • 아직 GPU를 사용할 수 없는 환경이기에, 경량화된 모델을 받아와 가볍게 테스트해보도록 코드를 짰습니다.
    • 현재 distilgpt를 사용하고 있습니다.
  • 모델 자체를 쪼개는 방식을 찾지 못해 모델의 weight 파일을 num_parts 만큼 나누어 디스크에 저장하는 방식을 사용해보았습니다.
    MegatronLM의 경우에도 간단한 수식을 추가하여 병렬화를 진행하기 때문에 cpu만으로 모델자체를 나누는 것은 쉽지 않을 것으로 예상됩니다.
  • 각 인스턴스(혹은 컨테이너)에서는 자신에게 할당된 파트만 로드하여 초기화 시간을 단축합니다.

📁 File

  • load_model.py:
    • Hugging Face distilgpt2 모델과 토크나이저를 다운로드
    • 모델의 가중치(pytorch_model.bin)만 별도 저장
    • 설정 파일(config.json)과 토크나이저 vocab 파일도 함께 저장
  • divide_model.py:
    • 전체 pytorch_model.bin을 CPU로 로드
    • key 리스트를 num_parts 비율에 따라 분할 경계 계산
    • 각 파트별로 weight 딕셔너리를 분리해 pytorch_model_partX.bin 파일로 저장
  • main.py:
    • 전체 모델(pytorch_model.bin) vs. 분할 모델(pytorch_model_part1.bin 등) 로딩 시간 비교 측정
    • CPU 환경에서 시간 차이를 직접 출력
    • 같은 설정(Config)이지만 로드해야 할 파라미터 수가 다르므로, “부분 로딩(partial)” 시 초기화 시간이 크게 단축됨
  • Dockerfile:
    • base: 공통 의존성 설치 및 스크립트 복사
    • full: 전체 모델만 남겨두고 파트 파일 삭제 → 전체 로드 이미지
    • part1: 1번 파트만 남기고 나머지 가중치 삭제 → 파셜 로드 이미지
    • 컨테이너 이미지 별로 불필요한 가중치 파일을 제거해 용량 최적화
    • 여러 파트 인스턴스를 동시에 배포 가능

▶️ Execution Flow

(맥북 기준)

  1. 모델 저장 준비
    python3 load_model.py
  2. 모델 분할
    python3 divide_model.py --num_parts 10
  3. 컨테이너 빌드 & 실행
    • 전체 모델
    docker build --target full -t gpt2-full .
    docker run --rm gpt2-full
    • 파트1 모델
    docker build --target part1 -t gpt2-part1 .
    docker run --rm gpt2-part1
  4. 로드 시간 비교
  • 전체 vs. 파셜 로딩 시 출력되는 초 단위 시간이 실험 결과

※ References

@rinarina0429 rinarina0429 self-assigned this Jun 5, 2025
@rinarina0429
rinarina0429 requested review from 2Ju1 and parknadam June 7, 2025 09:29
@rinarina0429
rinarina0429 merged commit ad24e21 into main Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

모델 분할 및 Docker 업로드 시간 측정

1 participant