PyTorch Profiler로 Baseline 측정하기
마지막 수정:
최적화 전에 먼저 baseline을 측정한다.
측정할 항목은 최소 세 가지다.
step time
GPU memory
top operators by CUDA time
PyTorch profiler는 operator 단위의 시간을 볼 수 있게 해준다.
with torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.CUDA,
],
record_shapes=True,
profile_memory=True,
) as prof:
train_step()
이 카드의 목표는 “느린 것 같다”가 아니라 “어느 op가 얼마나 먹는다”로 말하는 것이다.
확인
- 최적화 전에 baseline이 필요한 이유는 무엇인가?
record_shapes=True는 어떤 판단에 도움이 되는가?- profiler 결과에서 top operator만 보고 바로 결론내리면 위험한 이유는 무엇인가?