Determined 체크포인트 관리 — 체크포인트 조회·다운로드·모델 로딩

Determined 체크포인트 관리 — 체크포인트 조회·다운로드·모델 로딩

체크포인트는 학습 중 모델 상태를 저장한 것으로, 재현·복원의 핵심이에요. Determined는 체크포인트를 파이썬 프로세스에 다운로드해 메모리로 로딩하는 API를 제공해요. 파일 목록만 가져오는 것도 가능하고, 사용자 정의 메타데이터를 저장할 수도 있어요. Determined CLI로 체크포인트를 디스크에 받을 수도 있어요.

출처: https://docs.determined.ai/latest/model-dev-guide/model-management/checkpoints.html

체크포인트 조회

experiment나 trial로부터 체크포인트를 조회할 수 있어요.

from determined.experimental import client

checkpoint = client.get_experiment(id).list_checkpoints()[0]

메트릭으로 정렬하고 싶다면 sort_byorder_by를 써요.

checkpoints = (
    client.get_experiment(id)
    .list_checkpoints(sort_by="accuracy", order_by=client.OrderBy.DESC)
)

체크포인트 다운로드와 모델 로딩

체크포인트를 다운로드한 뒤, PyTorch는 load_trial_from_checkpoint_path로, Keras(TensorFlow)는 load_model_from_checkpoint_path로 로딩할 수 있어요.

from determined.experimental import client
from determined import pytorch

checkpoint = client.get_experiment(id).list_checkpoints()[0]
path = checkpoint.download()
trial = pytorch.load_trial_from_checkpoint_path(path)
model = trial.model
predictions = model(samples)
from determined.experimental import client
from determined import keras

checkpoint = client.get_experiment(id).list_checkpoints()[0]
path = checkpoint.download()
model = keras.load_model_from_checkpoint_path(path)
predictions = model(samples)

PyTorch 체크포인트는 pickle로 저장되고 PyTorch API 객체로 로딩돼요. build_model() 메서드는 experiment config의 entrypoint 필드로 지정한 trial 클래스에 정의돼 있어요.

체크포인트에 포함되는 것

체크포인트에는 모델 정의(파이썬 소스), experiment 설정 파일, 네트워크 아키텍처, 모델 파라미터(가중치)·하이퍼파라미터 값이 들어 있어요. stateful optimizer를 쓸 때는 optimizer 상태(학습률 포함)도 포함돼요. Python SDK로 임의 메타데이터를 체크포인트에 담을 수도 있어요.

더 알아보기

체크포인트 API와 모델 레지스트리 활용은 공식 Model Management 문서에서 이어서 볼 수 있어요.